mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-28 09:15:12 +03:00
Minor date format code cleanup
This commit is contained in:
parent
aeacdad484
commit
c707d4bfd8
6 changed files with 31 additions and 22 deletions
|
@ -22,17 +22,17 @@ fun Preference<Boolean>.invert(): Boolean = getOrDefault().let { set(!it); !it }
|
|||
|
||||
private class DateFormatConverter : Preference.Adapter<DateFormat> {
|
||||
override fun get(key: String, preferences: SharedPreferences): DateFormat {
|
||||
var dateFormat = preferences.getString(Keys.dateFormat, "")
|
||||
val dateFormat = preferences.getString(Keys.dateFormat, "")!!
|
||||
|
||||
if (dateFormat != "") {
|
||||
return SimpleDateFormat(dateFormat)
|
||||
return SimpleDateFormat(dateFormat, Locale.getDefault())
|
||||
}
|
||||
|
||||
return DateFormat.getDateInstance(DateFormat.SHORT)
|
||||
}
|
||||
|
||||
override fun set(key: String, value: DateFormat, editor: SharedPreferences.Editor) {
|
||||
TODO("not implemented")
|
||||
// No-op
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,9 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
|||
*/
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
val dateFormat: DateFormat = preferences.dateFormat().getOrDefault()
|
||||
private val dateFormat: DateFormat by lazy {
|
||||
preferences.dateFormat().getOrDefault()
|
||||
}
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
|
|
|
@ -6,8 +6,8 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.util.toTimestampString
|
||||
import kotlinx.android.synthetic.main.recently_read_item.*
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
|
@ -55,10 +55,8 @@ class RecentlyReadHolder(
|
|||
manga_source.text = itemView.context.getString(R.string.recent_manga_source)
|
||||
.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
|
||||
last_read.text = "$date $time"
|
||||
last_read.text = Date(history.last_read).toTimestampString(adapter.dateFormat)
|
||||
|
||||
// Set cover
|
||||
GlideApp.with(itemView.context).clear(cover)
|
||||
|
|
|
@ -4,8 +4,8 @@ import android.app.Dialog
|
|||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceScreen
|
||||
import android.view.View
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
|||
import eu.kanade.tachiyomi.data.updater.UpdaterService
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.ui.main.ChangelogDialogController
|
||||
import eu.kanade.tachiyomi.util.toTimestampString
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
|
@ -26,7 +27,8 @@ import uy.kohesive.injekt.injectLazy
|
|||
import java.text.DateFormat
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
|
||||
class SettingsAboutController : SettingsController() {
|
||||
|
@ -36,10 +38,9 @@ class SettingsAboutController : SettingsController() {
|
|||
*/
|
||||
private val updateChecker by lazy { UpdateChecker.getUpdateChecker() }
|
||||
|
||||
|
||||
private val userPreferences: PreferencesHelper by injectLazy()
|
||||
|
||||
val dateFormat: DateFormat = userPreferences.dateFormat().getOrDefault()
|
||||
private val dateFormat: DateFormat = userPreferences.dateFormat().getOrDefault()
|
||||
|
||||
/**
|
||||
* The subscribtion service of the obtained release object
|
||||
|
@ -192,9 +193,7 @@ class SettingsAboutController : SettingsController() {
|
|||
DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
||||
outputDf.timeZone = TimeZone.getDefault()
|
||||
|
||||
val date = dateFormat.format(buildTime)
|
||||
val time = DateFormat.getTimeInstance(DateFormat.SHORT).format(buildTime)
|
||||
return "$date $time"
|
||||
return buildTime.toTimestampString(dateFormat)
|
||||
} catch (e: ParseException) {
|
||||
return BuildConfig.BUILD_TIME
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ class SettingsGeneralController : SettingsController() {
|
|||
key = Keys.lang
|
||||
titleRes = R.string.pref_language
|
||||
entryValues = arrayOf("", "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB",
|
||||
"es", "fr", "hi", "hu", "in", "it", "ja", "ko", "lv", "ms", "nb-rNO", "nl", "pl", "pt",
|
||||
"pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN")
|
||||
"es", "fr", "hi", "hu", "in", "it", "ja", "ko", "lv", "ms", "nb-rNO", "nl", "pl", "pt",
|
||||
"pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN")
|
||||
entries = entryValues.map { value ->
|
||||
val locale = LocaleHelper.getLocaleFromString(value.toString())
|
||||
locale?.getDisplayName(locale)?.capitalize() ?:
|
||||
context.getString(R.string.system_default)
|
||||
locale?.getDisplayName(locale)?.capitalize()
|
||||
?: context.getString(R.string.system_default)
|
||||
}.toTypedArray()
|
||||
defaultValue = ""
|
||||
summary = "%s"
|
||||
|
@ -34,9 +34,9 @@ class SettingsGeneralController : SettingsController() {
|
|||
}
|
||||
}
|
||||
listPreference {
|
||||
key= Keys.dateFormat
|
||||
key = Keys.dateFormat
|
||||
titleRes = R.string.pref_date_format
|
||||
entryValues= arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd")
|
||||
entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd")
|
||||
entries = entryValues.map { value ->
|
||||
if (value == "") {
|
||||
context.getString(R.string.system_default)
|
||||
|
@ -45,7 +45,7 @@ class SettingsGeneralController : SettingsController() {
|
|||
}
|
||||
}.toTypedArray()
|
||||
defaultValue = ""
|
||||
summary= "%s"
|
||||
summary = "%s"
|
||||
}
|
||||
intListPreference {
|
||||
key = Keys.theme
|
||||
|
|
10
app/src/main/java/eu/kanade/tachiyomi/util/DateExtensions.kt
Normal file
10
app/src/main/java/eu/kanade/tachiyomi/util/DateExtensions.kt
Normal file
|
@ -0,0 +1,10 @@
|
|||
package eu.kanade.tachiyomi.util
|
||||
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
fun Date.toTimestampString(dateFormatter: DateFormat): String {
|
||||
val date = dateFormatter.format(this)
|
||||
val time = DateFormat.getTimeInstance(DateFormat.SHORT).format(this)
|
||||
return "$date $time"
|
||||
}
|
Loading…
Reference in a new issue