mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-29 05:17:56 +01:00
Show date format examples, migrate to FlowPreferences
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user