diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 99033f497..dc1bb2da8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.data.preference import android.content.Context -import android.content.SharedPreferences import android.net.Uri import android.os.Environment import androidx.preference.PreferenceManager @@ -31,22 +30,6 @@ fun Preference.asImmediateFlow(block: (value: T) -> Unit): Flow { .onEach { block(it) } } -private class DateFormatConverter : RxPreference.Adapter { - override fun get(key: String, preferences: SharedPreferences): DateFormat { - val dateFormat = preferences.getString(Keys.dateFormat, "")!! - - if (dateFormat != "") { - return SimpleDateFormat(dateFormat, Locale.getDefault()) - } - - return DateFormat.getDateInstance(DateFormat.SHORT) - } - - override fun set(key: String, value: DateFormat, editor: SharedPreferences.Editor) { - // No-op - } -} - @OptIn(ExperimentalCoroutinesApi::class) class PreferencesHelper(val context: Context) { @@ -177,7 +160,10 @@ class PreferencesHelper(val context: Context) { fun backupsDirectory() = flowPrefs.getString(Keys.backupDirectory, defaultBackupDir.toString()) - fun dateFormat() = rxPrefs.getObject(Keys.dateFormat, DateFormat.getDateInstance(DateFormat.SHORT), DateFormatConverter()) + fun dateFormat(format: String = flowPrefs.getString(Keys.dateFormat, "").get()): DateFormat = when (format) { + "" -> DateFormat.getDateInstance(DateFormat.SHORT) + else -> SimpleDateFormat(format, Locale.getDefault()) + } fun downloadsDirectory() = flowPrefs.getString(Keys.downloadsDirectory, defaultDownloadsDir.toString()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt index 9e696fc4f..5de867417 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt @@ -4,7 +4,6 @@ import android.content.Context import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.system.getResourceColor import java.text.DateFormat import java.text.DecimalFormat @@ -31,7 +30,7 @@ class ChaptersAdapter( .apply { decimalSeparator = '.' } ) - val dateFormat: DateFormat = preferences.dateFormat().getOrDefault() + val dateFormat: DateFormat = preferences.dateFormat() override fun updateDataSet(items: List?) { this.items = items ?: emptyList() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index 32e56c87d..bcaf203bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.databinding.MangaInfoControllerBinding import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager @@ -62,7 +61,7 @@ class MangaInfoController(private val fromSource: Boolean = false) : private val preferences: PreferencesHelper by injectLazy() private val dateFormat: DateFormat by lazy { - preferences.dateFormat().getOrDefault() + preferences.dateFormat() } private var initialLoad: Boolean = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt index 7f76b7af5..920724929 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.manga.track import android.annotation.SuppressLint import android.view.View import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visibleIf @@ -27,7 +26,7 @@ class TrackHolder(view: View, adapter: TrackAdapter) : BaseViewHolder(view) { private val preferences: PreferencesHelper by injectLazy() private val dateFormat: DateFormat by lazy { - preferences.dateFormat().getOrDefault() + preferences.dateFormat() } init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 6c766a931..20b149baa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -10,8 +10,6 @@ import com.afollestad.materialdialogs.MaterialDialog import com.google.android.gms.oss.licenses.OssLicensesMenuActivity import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.updater.UpdateChecker import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdaterService @@ -32,7 +30,6 @@ import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone import timber.log.Timber -import uy.kohesive.injekt.injectLazy class AboutController : SettingsController() { @@ -41,9 +38,7 @@ class AboutController : SettingsController() { */ private val updateChecker by lazy { UpdateChecker.getUpdateChecker() } - private val userPreferences: PreferencesHelper by injectLazy() - - private val dateFormat: DateFormat = userPreferences.dateFormat().getOrDefault() + private val dateFormat: DateFormat = preferences.dateFormat() private val isUpdaterEnabled = BuildConfig.INCLUDE_UPDATER diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index acdc9e085..d5696821a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -19,6 +19,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.LocaleHelper +import java.util.Calendar import kotlinx.coroutines.flow.launchIn class SettingsGeneralController : SettingsController() { @@ -92,13 +93,17 @@ class SettingsGeneralController : SettingsController() { key = Keys.dateFormat titleRes = R.string.pref_date_format entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd") + + val currentDate = Calendar.getInstance().time entries = entryValues.map { value -> + val formattedDate = preferences.dateFormat(value.toString()).format(currentDate) if (value == "") { - context.getString(R.string.system_default) + "${context.getString(R.string.system_default)} ($formattedDate)" } else { - value + "$value ($formattedDate)" } }.toTypedArray() + defaultValue = "" summary = "%s" } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 565057b51..80dad839f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -61,7 +61,7 @@ Edit categories Rename category Set categories - Edit the cover picture + Edit cover Sort up Sort down Downloaded