diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-02-26 14:58:25 +0100 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-02-26 14:58:25 +0100 |
| commit | 5ba686d1ac45509cba636d717bb6729865105cf3 (patch) | |
| tree | e21ad8d6ca30a8ca6a02313c9b4cc786370dc91e /android/lib | |
| parent | 5025db74b34cfb3536c43f89f3407ffc0d97ae73 (diff) | |
| parent | 38c4791b414538962f6a8ab958aecd09414f33f6 (diff) | |
| download | mullvadvpn-5ba686d1ac45509cba636d717bb6729865105cf3.tar.xz mullvadvpn-5ba686d1ac45509cba636d717bb6729865105cf3.zip | |
Merge branch 'remove-jodatime-droid-898'
Diffstat (limited to 'android/lib')
12 files changed, 36 insertions, 31 deletions
diff --git a/android/lib/common/build.gradle.kts b/android/lib/common/build.gradle.kts index c8554b52c7..24468d9815 100644 --- a/android/lib/common/build.gradle.kts +++ b/android/lib/common/build.gradle.kts @@ -34,7 +34,6 @@ dependencies { implementation(libs.arrow) implementation(libs.androidx.appcompat) - implementation(libs.jodatime) implementation(libs.kotlin.stdlib) implementation(libs.kotlinx.coroutines.android) implementation(libs.kermit) diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt index 536fea3d24..e34bfa582e 100644 --- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt @@ -1,22 +1,8 @@ package net.mullvad.mullvadvpn.lib.common.util -import org.joda.time.DateTime -import org.joda.time.format.DateTimeFormat - -private const val EXPIRY_FORMAT = "YYYY-MM-dd HH:mm:ss z" private const val BIG_DOT_CHAR = "●" private const val SPACE_CHAR = ' ' -fun String.parseAsDateTime(): DateTime? { - return try { - DateTime.parse(this, DateTimeFormat.forPattern(EXPIRY_FORMAT)) - } catch (ex: IllegalArgumentException) { - null - } catch (ex: UnsupportedOperationException) { - null - } -} - fun String.groupWithSpaces(groupCharSize: Int = 4): String { return fold(StringBuilder()) { formattedText, nextDigit -> if ((formattedText.length % (groupCharSize + 1)) == groupCharSize) { diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt new file mode 100644 index 0000000000..74fe9d6ba0 --- /dev/null +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt @@ -0,0 +1,20 @@ +package net.mullvad.mullvadvpn.lib.common.util + +import java.time.Duration +import java.time.Instant +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle + +fun ZonedDateTime.formatDate(): String = DateTimeFormatter.ISO_LOCAL_DATE.format(this) + +fun ZonedDateTime.toExpiryDateString(): String = + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(this) + +fun ZonedDateTime.millisFromNow(): Long = Duration.between(ZonedDateTime.now(), this).toMillis() + +fun ZonedDateTime.daysFromNow(): Long = Duration.between(ZonedDateTime.now(), this).toDays() + +fun ZonedDateTime.isBeforeNowInstant(): Boolean = toInstant().isBefore(Instant.now()) + +fun ZonedDateTime.isAfterNowInstant(): Boolean = toInstant().isAfter(Instant.now()) diff --git a/android/lib/daemon-grpc/build.gradle.kts b/android/lib/daemon-grpc/build.gradle.kts index 60e2073843..f3b8799f95 100644 --- a/android/lib/daemon-grpc/build.gradle.kts +++ b/android/lib/daemon-grpc/build.gradle.kts @@ -63,7 +63,6 @@ dependencies { implementation(projects.lib.model) implementation(projects.lib.talpid) - implementation(libs.jodatime) implementation(libs.kermit) implementation(libs.kotlin.stdlib) implementation(libs.kotlinx.coroutines) diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt index fe4cf11881..717bf401f4 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt @@ -5,6 +5,8 @@ package net.mullvad.mullvadvpn.lib.daemon.grpc.mapper import io.grpc.ConnectivityState import java.net.InetAddress import java.net.InetSocketAddress +import java.time.Instant +import java.time.ZoneId import java.util.UUID import mullvad_daemon.management_interface.ManagementInterface import net.mullvad.mullvadvpn.lib.daemon.grpc.GrpcConnectivityState @@ -72,7 +74,6 @@ import net.mullvad.mullvadvpn.lib.model.WireguardConstraints import net.mullvad.mullvadvpn.lib.model.WireguardEndpointData import net.mullvad.mullvadvpn.lib.model.WireguardRelayEndpointData import net.mullvad.mullvadvpn.lib.model.WireguardTunnelOptions -import org.joda.time.Instant internal fun ManagementInterface.TunnelState.toDomain(): TunnelState = when (stateCase!!) { @@ -570,8 +571,10 @@ internal fun ManagementInterface.Relay.toDomain( } else false, ) +private fun Instant.atDefaultZone() = atZone(ZoneId.systemDefault()) + internal fun ManagementInterface.Device.toDomain(): Device = - Device(DeviceId.fromString(id), name, Instant.ofEpochSecond(created.seconds).toDateTime()) + Device(DeviceId.fromString(id), name, Instant.ofEpochSecond(created.seconds).atDefaultZone()) internal fun ManagementInterface.DeviceState.toDomain(): DeviceState = when (state) { @@ -587,13 +590,13 @@ internal fun ManagementInterface.DeviceState.toDomain(): DeviceState = internal fun ManagementInterface.AccountData.toDomain(): AccountData = AccountData( AccountId(UUID.fromString(id)), - expiryDate = Instant.ofEpochSecond(expiry.seconds).toDateTime(), + expiryDate = Instant.ofEpochSecond(expiry.seconds).atDefaultZone(), ) internal fun ManagementInterface.VoucherSubmission.toDomain(): RedeemVoucherSuccess = RedeemVoucherSuccess( timeAdded = secondsAdded, - newExpiryDate = Instant.ofEpochSecond(newExpiry.seconds).toDateTime(), + newExpiryDate = Instant.ofEpochSecond(newExpiry.seconds).atDefaultZone(), ) internal fun ManagementInterface.SplitTunnelSettings.toDomain(): SplitTunnelSettings = diff --git a/android/lib/model/build.gradle.kts b/android/lib/model/build.gradle.kts index c961dcc32f..f83ff3d5d4 100644 --- a/android/lib/model/build.gradle.kts +++ b/android/lib/model/build.gradle.kts @@ -35,7 +35,6 @@ android { } dependencies { - implementation(libs.jodatime) implementation(libs.kotlin.stdlib) implementation(libs.kotlinx.coroutines.android) implementation(libs.arrow) diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/AccountData.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/AccountData.kt index 8a4182b2e5..b1746e1bcc 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/AccountData.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/AccountData.kt @@ -1,5 +1,5 @@ package net.mullvad.mullvadvpn.lib.model -import org.joda.time.DateTime +import java.time.ZonedDateTime -data class AccountData(val id: AccountId, val expiryDate: DateTime) +data class AccountData(val id: AccountId, val expiryDate: ZonedDateTime) diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Device.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Device.kt index e8303f0eca..3eb92f2f8f 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Device.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Device.kt @@ -1,12 +1,12 @@ package net.mullvad.mullvadvpn.lib.model import android.os.Parcelable +import java.time.ZonedDateTime import kotlinx.parcelize.Parcelize import net.mullvad.mullvadvpn.lib.model.extensions.startCase -import org.joda.time.DateTime @Parcelize -data class Device(val id: DeviceId, private val name: String, val creationDate: DateTime) : +data class Device(val id: DeviceId, private val name: String, val creationDate: ZonedDateTime) : Parcelable { fun displayName(): String = name.startCase() } diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Notification.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Notification.kt index acb8d74907..6b073988a3 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Notification.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Notification.kt @@ -1,6 +1,6 @@ package net.mullvad.mullvadvpn.lib.model -import org.joda.time.Duration +import java.time.Duration sealed interface Notification { val actions: List<NotificationAction> diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RedeemVoucherSuccess.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RedeemVoucherSuccess.kt index 9c81042b8c..53fa414047 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RedeemVoucherSuccess.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/RedeemVoucherSuccess.kt @@ -1,5 +1,5 @@ package net.mullvad.mullvadvpn.lib.model -import org.joda.time.DateTime +import java.time.ZonedDateTime -data class RedeemVoucherSuccess(val timeAdded: Long, val newExpiryDate: DateTime) +data class RedeemVoucherSuccess(val timeAdded: Long, val newExpiryDate: ZonedDateTime) diff --git a/android/lib/shared/build.gradle.kts b/android/lib/shared/build.gradle.kts index 4be82a9eb2..7e2730a9e9 100644 --- a/android/lib/shared/build.gradle.kts +++ b/android/lib/shared/build.gradle.kts @@ -41,7 +41,6 @@ dependencies { implementation(libs.kermit) implementation(libs.kotlin.stdlib) implementation(libs.kotlinx.coroutines.android) - implementation(libs.jodatime) testImplementation(libs.kotlin.test) testImplementation(libs.kotlinx.coroutines.test) diff --git a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt index f6b146ecd3..a0edc2faa6 100644 --- a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt +++ b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.lib.shared import arrow.core.Either import arrow.core.raise.nullable +import java.time.ZonedDateTime import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -21,7 +22,6 @@ import net.mullvad.mullvadvpn.lib.model.CreateAccountError import net.mullvad.mullvadvpn.lib.model.DeviceState import net.mullvad.mullvadvpn.lib.model.LoginAccountError import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken -import org.joda.time.DateTime class AccountRepository( private val managementService: ManagementService, @@ -87,7 +87,7 @@ class AccountRepository( suspend fun getWebsiteAuthToken(): WebsiteAuthToken? = managementService.getWebsiteAuthToken().getOrNull() - internal suspend fun onVoucherRedeemed(newExpiry: DateTime) { + internal suspend fun onVoucherRedeemed(newExpiry: ZonedDateTime) { accountData.value?.copy(expiryDate = newExpiry)?.let { _mutableAccountDataCache.emit(it) } } } |
