From 6414606ee7014aa4710f610fb4579b525c2db963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Wed, 11 Oct 2023 11:47:29 +0200 Subject: [PATCH] Fix remarks --- .../mullvad/mullvadvpn/compose/component/TopBar.kt | 10 ++++++++-- .../kotlin/net/mullvad/mullvadvpn/di/UiModule.kt | 1 + .../net/mullvad/mullvadvpn/util/DateExtensions.kt | 5 +++++ .../mullvadvpn/viewmodel/ConnectViewModel.kt | 3 ++- .../net/mullvad/mullvadvpn/model/AccountExpiry.kt | 14 +------------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt index 93669fb829dc..5e8fc2c78bd1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.component import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.animateContentSize import androidx.compose.animation.core.Spring import androidx.compose.animation.core.spring import androidx.compose.foundation.background @@ -287,12 +288,17 @@ fun MullvadTopBarWithDeviceName( start = Dimens.mediumPadding, end = Dimens.mediumPadding ) - .fillMaxWidth(), + .fillMaxWidth() + .animateContentSize(), horizontalArrangement = Arrangement.spacedBy(Dimens.mediumPadding) ) { Text( modifier = Modifier.weight(1f, fill = false), - text = stringResource(id = R.string.top_bar_device_name, deviceName ?: ""), + text = + deviceName?.let { + stringResource(id = R.string.top_bar_device_name, deviceName) + } + ?: "", maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt index 8a60f19f3d20..7134f7b7d205 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt @@ -32,6 +32,7 @@ import net.mullvad.mullvadvpn.viewmodel.SelectLocationViewModel import net.mullvad.mullvadvpn.viewmodel.SettingsViewModel import net.mullvad.mullvadvpn.viewmodel.SplitTunnelingViewModel import net.mullvad.mullvadvpn.viewmodel.ViewLogsViewModel +import net.mullvad.mullvadvpn.viewmodel.VoucherDialogViewModel import net.mullvad.mullvadvpn.viewmodel.VpnSettingsViewModel import net.mullvad.mullvadvpn.viewmodel.WelcomeViewModel import org.apache.commons.validator.routines.InetAddressValidator diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/DateExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/DateExtensions.kt index d3be3e09aa6e..e11434257a22 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/DateExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/DateExtensions.kt @@ -1,6 +1,8 @@ package net.mullvad.mullvadvpn.util import java.text.DateFormat +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.DurationUnit import org.joda.time.DateTime import org.joda.time.format.ISODateTimeFormat @@ -8,3 +10,6 @@ fun DateTime.formatDate(): String = ISODateTimeFormat.date().print(this) fun DateTime.toExpiryDateString(): String = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(this.toDate()) + +fun DateTime.daysFromNow() = + (toInstant().millis - DateTime.now().toInstant().millis).milliseconds.toInt(DurationUnit.DAYS) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt index 85b69f3f2040..01ba71ff861a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt @@ -38,6 +38,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy import net.mullvad.mullvadvpn.util.appVersionCallbackFlow import net.mullvad.mullvadvpn.util.callbackFlowFromNotifier import net.mullvad.mullvadvpn.util.combine +import net.mullvad.mullvadvpn.util.daysFromNow import net.mullvad.mullvadvpn.util.toInAddress import net.mullvad.mullvadvpn.util.toOutAddress import net.mullvad.talpid.tunnel.ActionAfterDisconnect @@ -131,7 +132,7 @@ class ConnectViewModel( accountExpiry = accountExpiry ), deviceName = deviceName, - daysLeftUntilExpiry = accountExpiry.daysLeft() + daysLeftUntilExpiry = accountExpiry.date()?.daysFromNow() ) } } diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/AccountExpiry.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/AccountExpiry.kt index 8980d1bf22ef..f856ef8c8961 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/AccountExpiry.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/AccountExpiry.kt @@ -1,27 +1,15 @@ package net.mullvad.mullvadvpn.model import android.os.Parcelable -import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.DurationUnit import kotlinx.parcelize.Parcelize import org.joda.time.DateTime sealed class AccountExpiry : Parcelable { - @Parcelize - data class Available(val expiryDateTime: DateTime) : AccountExpiry() { - override fun daysLeft(): Int = - (expiryDateTime.toInstant().millis - DateTime.now().toInstant().millis) - .milliseconds - .toInt(DurationUnit.DAYS) - } + @Parcelize data class Available(val expiryDateTime: DateTime) : AccountExpiry() @Parcelize data object Missing : AccountExpiry() fun date(): DateTime? { return (this as? Available)?.expiryDateTime } - - open fun daysLeft(): Int? { - return (this as? Available)?.daysLeft() - } }