From 705b55c57a09c3b643a72aa918d5f83b205bcf33 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 17 Jun 2022 16:53:33 +0200 Subject: [PATCH] Use handy kotlin.time.Duration.Companion and remove default value. --- .../java/im/vector/app/core/utils/TemporaryStoreTest.kt | 3 ++- .../main/java/im/vector/app/core/utils/TemporaryStore.kt | 9 ++++----- .../home/room/detail/RoomDetailPendingActionStore.kt | 3 ++- .../java/im/vector/app/features/login/ReAuthHelper.kt | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vector/src/androidTest/java/im/vector/app/core/utils/TemporaryStoreTest.kt b/vector/src/androidTest/java/im/vector/app/core/utils/TemporaryStoreTest.kt index 71a83f2e9b..303c1673dd 100644 --- a/vector/src/androidTest/java/im/vector/app/core/utils/TemporaryStoreTest.kt +++ b/vector/src/androidTest/java/im/vector/app/core/utils/TemporaryStoreTest.kt @@ -19,13 +19,14 @@ package im.vector.app.core.utils import org.amshove.kluent.shouldBe import org.junit.Test import java.lang.Thread.sleep +import kotlin.time.Duration.Companion.milliseconds class TemporaryStoreTest { @Test fun testTemporaryStore() { // Keep the data 300 millis - val store = TemporaryStore(300) + val store = TemporaryStore(300.milliseconds) store.data = "test" store.data shouldBe "test" diff --git a/vector/src/main/java/im/vector/app/core/utils/TemporaryStore.kt b/vector/src/main/java/im/vector/app/core/utils/TemporaryStore.kt index bd1e396126..809ba1173a 100644 --- a/vector/src/main/java/im/vector/app/core/utils/TemporaryStore.kt +++ b/vector/src/main/java/im/vector/app/core/utils/TemporaryStore.kt @@ -18,15 +18,14 @@ package im.vector.app.core.utils import java.util.Timer import java.util.TimerTask - -const val THREE_MINUTES = 3 * 60_000L +import kotlin.time.Duration /** * Store an object T for a specific period of time. * @param T type of the data to store - * @property delay delay to keep the data, in millis + * @property delay delay to keep the data */ -open class TemporaryStore(private val delay: Long = THREE_MINUTES) { +open class TemporaryStore(private val delay: Duration) { private var timer: Timer? = null @@ -40,7 +39,7 @@ open class TemporaryStore(private val delay: Long = THREE_MINUTES) { override fun run() { field = null } - }, delay) + }, delay.inWholeMilliseconds) } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailPendingActionStore.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailPendingActionStore.kt index 9ffbb83a47..9dd6569cbd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailPendingActionStore.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailPendingActionStore.kt @@ -19,7 +19,8 @@ package im.vector.app.features.home.room.detail import im.vector.app.core.utils.TemporaryStore import javax.inject.Inject import javax.inject.Singleton +import kotlin.time.Duration.Companion.seconds // Store to keep a pending action from sub screen of a room detail @Singleton -class RoomDetailPendingActionStore @Inject constructor() : TemporaryStore(10_000) +class RoomDetailPendingActionStore @Inject constructor() : TemporaryStore(10.seconds) diff --git a/vector/src/main/java/im/vector/app/features/login/ReAuthHelper.kt b/vector/src/main/java/im/vector/app/features/login/ReAuthHelper.kt index b29c930234..95cb4cc879 100644 --- a/vector/src/main/java/im/vector/app/features/login/ReAuthHelper.kt +++ b/vector/src/main/java/im/vector/app/features/login/ReAuthHelper.kt @@ -19,9 +19,10 @@ package im.vector.app.features.login import im.vector.app.core.utils.TemporaryStore import javax.inject.Inject import javax.inject.Singleton +import kotlin.time.Duration.Companion.minutes /** * Will store the account password for 3 minutes. */ @Singleton -class ReAuthHelper @Inject constructor() : TemporaryStore() +class ReAuthHelper @Inject constructor() : TemporaryStore(3.minutes)