From 1b6073d0de818e20d9f64d9f27d63bf9079fbe78 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 28 Oct 2024 07:28:11 +0100 Subject: [PATCH] use kotlin.Duration Signed-off-by: alperozturk --- .../com/nextcloud/model/DurationOption.kt | 33 ------------------- .../ui/activity/InternalTwoWaySyncActivity.kt | 24 ++++++++++---- 2 files changed, 18 insertions(+), 39 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/model/DurationOption.kt diff --git a/app/src/main/java/com/nextcloud/model/DurationOption.kt b/app/src/main/java/com/nextcloud/model/DurationOption.kt deleted file mode 100644 index 98de6c9a27..0000000000 --- a/app/src/main/java/com/nextcloud/model/DurationOption.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2024 Alper Ozturk - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -package com.nextcloud.model - -import android.content.Context -import com.owncloud.android.R - -data class DurationOption( - val value: Long, - val displayText: String -) { - companion object { - - @Suppress("MagicNumber") - fun twoWaySyncIntervals(context: Context): List = listOf( - DurationOption(15L, context.getString(R.string.two_way_sync_interval_15_min)), - DurationOption(30L, context.getString(R.string.two_way_sync_interval_30_min)), - DurationOption(45L, context.getString(R.string.two_way_sync_interval_45_min)), - DurationOption(60L, context.getString(R.string.two_way_sync_interval_1_hour)), - DurationOption(120L, context.getString(R.string.two_way_sync_interval_2_hours)), - DurationOption(240L, context.getString(R.string.two_way_sync_interval_4_hours)), - DurationOption(360L, context.getString(R.string.two_way_sync_interval_6_hours)), - DurationOption(480L, context.getString(R.string.two_way_sync_interval_8_hours)), - DurationOption(720L, context.getString(R.string.two_way_sync_interval_12_hours)), - DurationOption(1440L, context.getString(R.string.two_way_sync_interval_24_hours)) - ) - } -} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/InternalTwoWaySyncActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/InternalTwoWaySyncActivity.kt index ab7111930e..257579d19f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/InternalTwoWaySyncActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/InternalTwoWaySyncActivity.kt @@ -12,12 +12,13 @@ import android.widget.ArrayAdapter import androidx.recyclerview.widget.LinearLayoutManager import com.nextcloud.client.di.Injectable import com.nextcloud.client.jobs.BackgroundJobManager -import com.nextcloud.model.DurationOption import com.nextcloud.utils.extensions.setVisibleIf import com.owncloud.android.R import com.owncloud.android.databinding.InternalTwoWaySyncLayoutBinding import com.owncloud.android.ui.adapter.InternalTwoWaySyncAdapter import javax.inject.Inject +import kotlin.time.Duration.Companion.hours +import kotlin.time.Duration.Companion.minutes class InternalTwoWaySyncActivity : BaseActivity(), Injectable { lateinit var binding: InternalTwoWaySyncLayoutBinding @@ -38,20 +39,31 @@ class InternalTwoWaySyncActivity : BaseActivity(), Injectable { } private fun setupTwoWaySyncInterval() { - val durations = DurationOption.twoWaySyncIntervals(this) - val selectedDuration = durations.find { it.value == preferences.twoWaySyncInterval } + val durations = listOf( + 15.minutes to getString(R.string.two_way_sync_interval_15_min), + 30.minutes to getString(R.string.two_way_sync_interval_30_min), + 45.minutes to getString(R.string.two_way_sync_interval_45_min), + 1.hours to getString(R.string.two_way_sync_interval_1_hour), + 2.hours to getString(R.string.two_way_sync_interval_2_hours), + 4.hours to getString(R.string.two_way_sync_interval_4_hours), + 6.hours to getString(R.string.two_way_sync_interval_6_hours), + 8.hours to getString(R.string.two_way_sync_interval_8_hours), + 12.hours to getString(R.string.two_way_sync_interval_12_hours), + 24.hours to getString(R.string.two_way_sync_interval_24_hours) + ) + val selectedDuration = durations.find { it.first.inWholeMinutes == preferences.twoWaySyncInterval } val adapter = ArrayAdapter( this, android.R.layout.simple_dropdown_item_1line, - durations.map { it.displayText } + durations.map { it.second } ) binding.twoWaySyncInterval.run { setAdapter(adapter) - setText(selectedDuration?.displayText ?: getString(R.string.two_way_sync_interval_15_min), false) + setText(selectedDuration?.second ?: getString(R.string.two_way_sync_interval_15_min), false) setOnItemClickListener { _, _, position, _ -> - handleDurationSelected(durations[position].value) + handleDurationSelected(durations[position].first.inWholeMinutes) } } }