Show date format examples, migrate to FlowPreferences

This commit is contained in:
arkon
2020-05-10 12:26:18 -04:00
parent d46a742a43
commit 04d44f19f5
7 changed files with 16 additions and 33 deletions

View File

@@ -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())