mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-27 17:49:16 +03:00
Show date format examples, migrate to FlowPreferences
This commit is contained in:
parent
d46a742a43
commit
04d44f19f5
7 changed files with 16 additions and 33 deletions
|
@ -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 <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
|||
.onEach { block(it) }
|
||||
}
|
||||
|
||||
private class DateFormatConverter : RxPreference.Adapter<DateFormat> {
|
||||
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())
|
||||
|
||||
|
|
|
@ -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<ChapterItem>?) {
|
||||
this.items = items ?: emptyList()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<string name="action_edit_categories">Edit categories</string>
|
||||
<string name="action_rename_category">Rename category</string>
|
||||
<string name="action_move_category">Set categories</string>
|
||||
<string name="action_edit_cover">Edit the cover picture</string>
|
||||
<string name="action_edit_cover">Edit cover</string>
|
||||
<string name="action_sort_up">Sort up</string>
|
||||
<string name="action_sort_down">Sort down</string>
|
||||
<string name="action_show_downloaded">Downloaded</string>
|
||||
|
|
Loading…
Reference in a new issue