mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 21:41:50 +01:00
Allow setting a preferred date format (#2175)
This commit is contained in:
parent
6d9bec3e0b
commit
aeacdad484
@ -109,6 +109,8 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val lang = "app_language"
|
const val lang = "app_language"
|
||||||
|
|
||||||
|
const val dateFormat = "app_date_format"
|
||||||
|
|
||||||
const val defaultCategory = "default_category"
|
const val defaultCategory = "default_category"
|
||||||
|
|
||||||
const val skipRead = "skip_read"
|
const val skipRead = "skip_read"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.data.preference
|
package eu.kanade.tachiyomi.data.preference
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
@ -11,12 +12,30 @@ import eu.kanade.tachiyomi.data.track.TrackService
|
|||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||||
|
|
||||||
fun <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
fun <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
||||||
|
|
||||||
fun Preference<Boolean>.invert(): Boolean = getOrDefault().let { set(!it); !it }
|
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, "")
|
||||||
|
|
||||||
|
if (dateFormat != "") {
|
||||||
|
return SimpleDateFormat(dateFormat)
|
||||||
|
}
|
||||||
|
|
||||||
|
return DateFormat.getDateInstance(DateFormat.SHORT)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun set(key: String, value: DateFormat, editor: SharedPreferences.Editor) {
|
||||||
|
TODO("not implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class PreferencesHelper(val context: Context) {
|
class PreferencesHelper(val context: Context) {
|
||||||
|
|
||||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
@ -126,6 +145,8 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun backupsDirectory() = rxPrefs.getString(Keys.backupDirectory, defaultBackupDir.toString())
|
fun backupsDirectory() = rxPrefs.getString(Keys.backupDirectory, defaultBackupDir.toString())
|
||||||
|
|
||||||
|
fun dateFormat() = rxPrefs.getObject(Keys.dateFormat, DateFormatConverter())
|
||||||
|
|
||||||
fun downloadsDirectory() = rxPrefs.getString(Keys.downloadsDirectory, defaultDownloadsDir.toString())
|
fun downloadsDirectory() = rxPrefs.getString(Keys.downloadsDirectory, defaultDownloadsDir.toString())
|
||||||
|
|
||||||
fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true)
|
fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true)
|
||||||
|
@ -8,12 +8,17 @@ import eu.kanade.tachiyomi.util.getResourceColor
|
|||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.text.DecimalFormatSymbols
|
import java.text.DecimalFormatSymbols
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class ChaptersAdapter(
|
class ChaptersAdapter(
|
||||||
controller: ChaptersController,
|
controller: ChaptersController,
|
||||||
context: Context
|
context: Context
|
||||||
) : FlexibleAdapter<ChapterItem>(null, controller, true) {
|
) : FlexibleAdapter<ChapterItem>(null, controller, true) {
|
||||||
|
|
||||||
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
var items: List<ChapterItem> = emptyList()
|
var items: List<ChapterItem> = emptyList()
|
||||||
|
|
||||||
val menuItemListener: OnMenuItemClickListener = controller
|
val menuItemListener: OnMenuItemClickListener = controller
|
||||||
@ -27,7 +32,7 @@ class ChaptersAdapter(
|
|||||||
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
||||||
.apply { decimalSeparator = '.' })
|
.apply { decimalSeparator = '.' })
|
||||||
|
|
||||||
val dateFormat: DateFormat = DateFormat.getDateInstance(DateFormat.SHORT)
|
val dateFormat: DateFormat = preferences.dateFormat().getOrDefault()
|
||||||
|
|
||||||
override fun updateDataSet(items: List<ChapterItem>?) {
|
override fun updateDataSet(items: List<ChapterItem>?) {
|
||||||
this.items = items ?: emptyList()
|
this.items = items ?: emptyList()
|
||||||
|
@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
|||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
@ -65,6 +66,8 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
|||||||
*/
|
*/
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
|
val dateFormat: DateFormat = preferences.dateFormat().getOrDefault()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
setOptionsMenuHidden(true)
|
setOptionsMenuHidden(true)
|
||||||
@ -253,7 +256,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
|||||||
|
|
||||||
fun setLastUpdateDate(date: Date) {
|
fun setLastUpdateDate(date: Date) {
|
||||||
if (date.time != 0L) {
|
if (date.time != 0L) {
|
||||||
manga_last_update?.text = DateFormat.getDateInstance(DateFormat.SHORT).format(date)
|
manga_last_update?.text = dateFormat.format(date)
|
||||||
} else {
|
} else {
|
||||||
manga_last_update?.text = resources?.getString(R.string.unknown)
|
manga_last_update?.text = resources?.getString(R.string.unknown)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recently_read
|
package eu.kanade.tachiyomi.ui.recently_read
|
||||||
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
@ -32,7 +34,9 @@ class RecentlyReadAdapter(controller: RecentlyReadController)
|
|||||||
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
||||||
.apply { decimalSeparator = '.' })
|
.apply { decimalSeparator = '.' })
|
||||||
|
|
||||||
val dateFormat: DateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
|
val dateFormat: DateFormat = preferences.dateFormat().getOrDefault()
|
||||||
|
|
||||||
interface OnResumeClickListener {
|
interface OnResumeClickListener {
|
||||||
fun onResumeClick(position: Int)
|
fun onResumeClick(position: Int)
|
||||||
|
@ -7,6 +7,7 @@ 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 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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,8 +55,10 @@ 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 = adapter.dateFormat.format(Date(history.last_read))
|
last_read.text = "$date $time"
|
||||||
|
|
||||||
// Set cover
|
// Set cover
|
||||||
GlideApp.with(itemView.context).clear(cover)
|
GlideApp.with(itemView.context).clear(cover)
|
||||||
|
@ -9,6 +9,8 @@ import android.view.View
|
|||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.R
|
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.UpdateChecker
|
||||||
import eu.kanade.tachiyomi.data.updater.UpdateResult
|
import eu.kanade.tachiyomi.data.updater.UpdateResult
|
||||||
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
||||||
@ -20,11 +22,11 @@ import rx.Subscription
|
|||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.schedulers.Schedulers
|
import rx.schedulers.Schedulers
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.*
|
||||||
import java.util.TimeZone
|
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||||
|
|
||||||
class SettingsAboutController : SettingsController() {
|
class SettingsAboutController : SettingsController() {
|
||||||
@ -34,6 +36,11 @@ class SettingsAboutController : SettingsController() {
|
|||||||
*/
|
*/
|
||||||
private val updateChecker by lazy { UpdateChecker.getUpdateChecker() }
|
private val updateChecker by lazy { UpdateChecker.getUpdateChecker() }
|
||||||
|
|
||||||
|
|
||||||
|
private val userPreferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
|
val dateFormat: DateFormat = userPreferences.dateFormat().getOrDefault()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The subscribtion service of the obtained release object
|
* The subscribtion service of the obtained release object
|
||||||
*/
|
*/
|
||||||
@ -179,13 +186,15 @@ class SettingsAboutController : SettingsController() {
|
|||||||
try {
|
try {
|
||||||
val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US)
|
val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US)
|
||||||
inputDf.timeZone = TimeZone.getTimeZone("UTC")
|
inputDf.timeZone = TimeZone.getTimeZone("UTC")
|
||||||
val date = inputDf.parse(BuildConfig.BUILD_TIME)
|
val buildTime = inputDf.parse(BuildConfig.BUILD_TIME)
|
||||||
|
|
||||||
val outputDf = DateFormat.getDateTimeInstance(
|
val outputDf = DateFormat.getDateTimeInstance(
|
||||||
DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
||||||
outputDf.timeZone = TimeZone.getDefault()
|
outputDf.timeZone = TimeZone.getDefault()
|
||||||
|
|
||||||
return outputDf.format(date)
|
val date = dateFormat.format(buildTime)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,20 @@ class SettingsGeneralController : SettingsController() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
listPreference {
|
||||||
|
key= Keys.dateFormat
|
||||||
|
titleRes = R.string.pref_date_format
|
||||||
|
entryValues= arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd")
|
||||||
|
entries = entryValues.map { value ->
|
||||||
|
if (value == "") {
|
||||||
|
context.getString(R.string.system_default)
|
||||||
|
} else {
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}.toTypedArray()
|
||||||
|
defaultValue = ""
|
||||||
|
summary= "%s"
|
||||||
|
}
|
||||||
intListPreference {
|
intListPreference {
|
||||||
key = Keys.theme
|
key = Keys.theme
|
||||||
titleRes = R.string.pref_theme
|
titleRes = R.string.pref_theme
|
||||||
|
@ -153,6 +153,7 @@
|
|||||||
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
||||||
<string name="pref_auto_update_manga_sync">Sync chapters after reading</string>
|
<string name="pref_auto_update_manga_sync">Sync chapters after reading</string>
|
||||||
<string name="pref_ask_update_manga_sync">Confirm before updating</string>
|
<string name="pref_ask_update_manga_sync">Confirm before updating</string>
|
||||||
|
<string name="pref_date_format">Date format</string>
|
||||||
<string name="default_category">Default category</string>
|
<string name="default_category">Default category</string>
|
||||||
<string name="default_category_summary">Always ask</string>
|
<string name="default_category_summary">Always ask</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user