Minor date format code cleanup

This commit is contained in:
arkon 2020-01-28 22:32:56 -05:00 committed by Jay
parent f06d61a137
commit dbc634c8e4
5 changed files with 11 additions and 13 deletions

View File

@ -23,17 +23,17 @@ fun Preference<Boolean>.invert(): Boolean = getOrDefault().let { set(!it); !it }
private class DateFormatConverter : Preference.Adapter<DateFormat> { private class DateFormatConverter : Preference.Adapter<DateFormat> {
override fun get(key: String, preferences: SharedPreferences): DateFormat { override fun get(key: String, preferences: SharedPreferences): DateFormat {
var dateFormat = preferences.getString(Keys.dateFormat, "") val dateFormat = preferences.getString(Keys.dateFormat, "")!!
if (dateFormat != "") { if (dateFormat != "") {
return SimpleDateFormat(dateFormat) return SimpleDateFormat(dateFormat, Locale.getDefault())
} }
return DateFormat.getDateInstance(DateFormat.SHORT) return DateFormat.getDateInstance(DateFormat.SHORT)
} }
override fun set(key: String, value: DateFormat, editor: SharedPreferences.Editor) { override fun set(key: String, value: DateFormat, editor: SharedPreferences.Editor) {
TODO("not implemented") // No-op
} }
} }

View File

@ -114,7 +114,9 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
var fullRes:Drawable? = null var fullRes:Drawable? = null
private val dateFormat: DateFormat = preferences.dateFormat().getOrDefault() private val dateFormat: DateFormat by lazy {
preferences.dateFormat().getOrDefault()
}
init { init {
setHasOptionsMenu(true) setHasOptionsMenu(true)

View File

@ -8,8 +8,8 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.toTimestampString
import kotlinx.android.synthetic.main.recently_read_item.* import kotlinx.android.synthetic.main.recently_read_item.*
import java.text.DateFormat
import java.util.Date import java.util.Date
import kotlin.math.max import kotlin.math.max
@ -69,10 +69,8 @@ class RecentlyReadHolder(
manga_source.text = itemView.context.getString(R.string.recent_manga_source) manga_source.text = itemView.context.getString(R.string.recent_manga_source)
.format(adapter.sourceManager.getOrStub(manga.source).toString(), formattedNumber) .format(adapter.sourceManager.getOrStub(manga.source).toString(), formattedNumber)
val date = adapter.dateFormat.format(Date(history.last_read))
val time = DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(history.last_read))
// Set last read timestamp title // Set last read timestamp title
last_read.text = "$date $time" last_read.text = Date(history.last_read).toTimestampString(adapter.dateFormat)
// Set cover // Set cover
GlideApp.with(itemView.context).clear(cover) GlideApp.with(itemView.context).clear(cover)

View File

@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.data.updater.UpdaterService
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.main.ChangelogDialogController import eu.kanade.tachiyomi.ui.main.ChangelogDialogController
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.lang.toTimestampString
import rx.Subscription import rx.Subscription
import rx.android.schedulers.AndroidSchedulers import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers import rx.schedulers.Schedulers
@ -35,7 +36,6 @@ class SettingsAboutController : SettingsController() {
*/ */
private val updateChecker by lazy { UpdateChecker.getUpdateChecker() } private val updateChecker by lazy { UpdateChecker.getUpdateChecker() }
private val userPreferences: PreferencesHelper by injectLazy() private val userPreferences: PreferencesHelper by injectLazy()
private val dateFormat: DateFormat = userPreferences.dateFormat().getOrDefault() private val dateFormat: DateFormat = userPreferences.dateFormat().getOrDefault()
@ -165,9 +165,7 @@ class SettingsAboutController : SettingsController() {
inputDf.timeZone = TimeZone.getTimeZone("UTC") inputDf.timeZone = TimeZone.getTimeZone("UTC")
val buildTime = inputDf.parse(BuildConfig.BUILD_TIME) ?: return BuildConfig.BUILD_TIME val buildTime = inputDf.parse(BuildConfig.BUILD_TIME) ?: return BuildConfig.BUILD_TIME
val date = dateFormat.format(buildTime) return buildTime.toTimestampString(dateFormat)
val time = DateFormat.getTimeInstance(DateFormat.SHORT).format(buildTime)
return "$date $time"
} catch (e: ParseException) { } catch (e: ParseException) {
return BuildConfig.BUILD_TIME return BuildConfig.BUILD_TIME
} }

View File

@ -67,7 +67,7 @@ class SettingsGeneralController : SettingsController() {
} }
} }
defaultValue = "" defaultValue = ""
summary= "%s" summary = "%s"
} }
intListPreference(activity) { intListPreference(activity) {
key = Keys.startScreen key = Keys.startScreen