Remove preferences keys from resources

This commit is contained in:
Koitharu
2020-11-03 16:51:31 +02:00
parent 95a4bf41d2
commit 2772f0b3dd
33 changed files with 165 additions and 197 deletions

View File

@@ -20,5 +20,5 @@ abstract class RemoteMangaRepository(protected val loaderContext: MangaLoaderCon
override suspend fun getTags(): Set<MangaTag> = emptySet() override suspend fun getTags(): Set<MangaTag> = emptySet()
abstract fun onCreatePreferences(): Set<Int> abstract fun onCreatePreferences(): Set<String>
} }

View File

@@ -1,10 +1,10 @@
package org.koitharu.kotatsu.core.parser.site package org.koitharu.kotatsu.core.parser.site
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
@@ -133,7 +133,7 @@ abstract class ChanRepository(loaderContext: MangaLoaderContext) : RemoteMangaRe
} }
} }
override fun onCreatePreferences() = arraySetOf(R.string.key_parser_domain) override fun onCreatePreferences() = arraySetOf(SourceSettings.KEY_DOMAIN)
private fun getSortKey(sortOrder: SortOrder?) = private fun getSortKey(sortOrder: SortOrder?) =
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) { when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {

View File

@@ -1,10 +1,10 @@
package org.koitharu.kotatsu.core.parser.site package org.koitharu.kotatsu.core.parser.site
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
@@ -120,7 +120,7 @@ class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
} }
} }
override fun onCreatePreferences() = arraySetOf(R.string.key_parser_domain) override fun onCreatePreferences() = arraySetOf(SourceSettings.KEY_DOMAIN)
private fun getSortKey(sortOrder: SortOrder?) = private fun getSortKey(sortOrder: SortOrder?) =
when (sortOrder) { when (sortOrder) {

View File

@@ -1,10 +1,10 @@
package org.koitharu.kotatsu.core.parser.site package org.koitharu.kotatsu.core.parser.site
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
@@ -167,7 +167,7 @@ abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
} }
} }
override fun onCreatePreferences() = arraySetOf(R.string.key_parser_domain) override fun onCreatePreferences() = arraySetOf(SourceSettings.KEY_DOMAIN)
private fun getSortKey(sortOrder: SortOrder?) = private fun getSortKey(sortOrder: SortOrder?) =
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) { when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {

View File

@@ -8,6 +8,7 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
@@ -70,7 +71,7 @@ open class MangaLibRepository(loaderContext: MangaLoaderContext) :
} }
} }
override fun onCreatePreferences() = arraySetOf(R.string.key_parser_domain) override fun onCreatePreferences() = arraySetOf(SourceSettings.KEY_DOMAIN)
override suspend fun getDetails(manga: Manga): Manga { override suspend fun getDetails(manga: Manga): Manga {
val doc = loaderContext.httpGet(manga.url + "?section=info").parseHtml() val doc = loaderContext.httpGet(manga.url + "?section=info").parseHtml()

View File

@@ -2,10 +2,10 @@ package org.koitharu.kotatsu.core.parser.site
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import org.intellij.lang.annotations.Language import org.intellij.lang.annotations.Language
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
import java.util.* import java.util.*
@@ -168,8 +168,10 @@ class MangaTownRepository(loaderContext: MangaLoaderContext) :
} }
override fun onCreatePreferences() = override fun onCreatePreferences() = arraySetOf(
arraySetOf(R.string.key_parser_domain, R.string.key_parser_ssl) SourceSettings.KEY_DOMAIN,
SourceSettings.KEY_USE_SSL
)
private fun String.parseTagKey() = split('/').findLast { TAG_REGEX matches it } private fun String.parseTagKey() = split('/').findLast { TAG_REGEX matches it }

View File

@@ -1,10 +1,10 @@
package org.koitharu.kotatsu.core.parser.site package org.koitharu.kotatsu.core.parser.site
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
@@ -147,7 +147,7 @@ class MangareadRepository(
} }
} }
override fun onCreatePreferences() = arraySetOf(R.string.key_parser_domain) override fun onCreatePreferences() = arraySetOf(SourceSettings.KEY_DOMAIN)
private companion object { private companion object {

View File

@@ -1,10 +1,10 @@
package org.koitharu.kotatsu.core.parser.site package org.koitharu.kotatsu.core.parser.site
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.ParseException import org.koitharu.kotatsu.core.exceptions.ParseException
import org.koitharu.kotatsu.core.model.* import org.koitharu.kotatsu.core.model.*
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.ext.* import org.koitharu.kotatsu.utils.ext.*
import java.util.regex.Pattern import java.util.regex.Pattern
@@ -134,7 +134,7 @@ class NudeMoonRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposit
} }
} }
override fun onCreatePreferences() = arraySetOf(R.string.key_parser_domain) override fun onCreatePreferences() = arraySetOf(SourceSettings.KEY_DOMAIN)
private fun getSortKey(sortOrder: SortOrder?) = private fun getSortKey(sortOrder: SortOrder?) =
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) { when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {

View File

@@ -2,109 +2,78 @@ package org.koitharu.kotatsu.core.prefs
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.res.Resources
import android.provider.Settings import android.provider.Settings
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.collection.arraySetOf import androidx.collection.arraySetOf
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.parser.LocalMangaRepository import org.koitharu.kotatsu.core.parser.LocalMangaRepository
import org.koitharu.kotatsu.utils.delegates.prefs.* import org.koitharu.kotatsu.utils.delegates.prefs.*
import java.io.File import java.io.File
class AppSettings private constructor(resources: Resources, private val prefs: SharedPreferences) : class AppSettings private constructor(private val prefs: SharedPreferences) :
SharedPreferences by prefs { SharedPreferences by prefs {
constructor(context: Context) : this( constructor(context: Context) : this(
context.resources,
PreferenceManager.getDefaultSharedPreferences(context) PreferenceManager.getDefaultSharedPreferences(context)
) )
var listMode by EnumPreferenceDelegate( var listMode by EnumPreferenceDelegate(
ListMode::class.java, ListMode::class.java,
resources.getString(R.string.key_list_mode), KEY_LIST_MODE,
ListMode.DETAILED_LIST ListMode.DETAILED_LIST
) )
var defaultSection by EnumPreferenceDelegate( var defaultSection by EnumPreferenceDelegate(
AppSection::class.java, AppSection::class.java,
resources.getString(R.string.key_app_section), KEY_APP_SECTION,
AppSection.HISTORY AppSection.HISTORY
) )
val theme by StringIntPreferenceDelegate( val theme by StringIntPreferenceDelegate(
resources.getString(R.string.key_theme), KEY_THEME,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
) )
val gridSize by IntPreferenceDelegate( val gridSize by IntPreferenceDelegate(KEY_GRID_SIZE, defaultValue = 100)
resources.getString(R.string.key_grid_size),
100
)
val readerPageSwitch by StringSetPreferenceDelegate( val readerPageSwitch by StringSetPreferenceDelegate(
resources.getString(R.string.key_reader_switchers), KEY_READER_SWITCHERS,
arraySetOf(PAGE_SWITCH_TAPS) arraySetOf(PAGE_SWITCH_TAPS)
) )
var isTrafficWarningEnabled by BoolPreferenceDelegate( var isTrafficWarningEnabled by BoolPreferenceDelegate(KEY_TRAFFIC_WARNING, defaultValue = true)
resources.getString(R.string.key_traffic_warning),
true
)
val appUpdateAuto by BoolPreferenceDelegate( val appUpdateAuto by BoolPreferenceDelegate(KEY_APP_UPDATE_AUTO, defaultValue = true)
resources.getString(R.string.key_app_update_auto),
true
)
var appUpdate by LongPreferenceDelegate( var appUpdate by LongPreferenceDelegate(KEY_APP_UPDATE, defaultValue = 0L)
resources.getString(R.string.key_app_update),
0L
)
val trackerNotifications by BoolPreferenceDelegate( val trackerNotifications by BoolPreferenceDelegate(
resources.getString(R.string.key_tracker_notifications), KEY_TRACKER_NOTIFICATIONS,
true defaultValue = true
) )
var notificationSound by StringPreferenceDelegate( var notificationSound by StringPreferenceDelegate(
resources.getString(R.string.key_notifications_sound), KEY_NOTIFICATIONS_SOUND,
Settings.System.DEFAULT_NOTIFICATION_URI.toString() Settings.System.DEFAULT_NOTIFICATION_URI.toString()
) )
val notificationVibrate by BoolPreferenceDelegate( val notificationVibrate by BoolPreferenceDelegate(KEY_NOTIFICATIONS_VIBRATE, false)
resources.getString(R.string.key_notifications_vibrate),
false
)
val notificationLight by BoolPreferenceDelegate( val notificationLight by BoolPreferenceDelegate(KEY_NOTIFICATIONS_LIGHT, true)
resources.getString(R.string.key_notifications_light),
true
)
val readerAnimation by BoolPreferenceDelegate( val readerAnimation by BoolPreferenceDelegate(KEY_READER_ANIMATION, false)
resources.getString(R.string.key_reader_animation),
false
)
val isPreferRtlReader by BoolPreferenceDelegate( val isPreferRtlReader by BoolPreferenceDelegate(KEY_READER_PREFER_RTL, false)
resources.getString(R.string.key_reader_prefer_rtl),
false
)
val trackSources by StringSetPreferenceDelegate( val trackSources by StringSetPreferenceDelegate(
resources.getString(R.string.key_track_sources), KEY_TRACK_SOURCES,
arraySetOf(TRACK_FAVOURITES, TRACK_HISTORY) arraySetOf(TRACK_FAVOURITES, TRACK_HISTORY)
) )
var appPassword by NullableStringPreferenceDelegate( var appPassword by NullableStringPreferenceDelegate(KEY_APP_PASSWORD)
resources.getString(R.string.key_app_password)
)
private var sourcesOrderStr by NullableStringPreferenceDelegate( private var sourcesOrderStr by NullableStringPreferenceDelegate(KEY_SOURCES_ORDER)
resources.getString(R.string.key_sources_order)
)
var sourcesOrder: List<Int> var sourcesOrder: List<Int>
get() = sourcesOrderStr?.split('|')?.mapNotNull(String::toIntOrNull).orEmpty() get() = sourcesOrderStr?.split('|')?.mapNotNull(String::toIntOrNull).orEmpty()
@@ -112,22 +81,21 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
sourcesOrderStr = value.joinToString("|") sourcesOrderStr = value.joinToString("|")
} }
var hiddenSources by StringSetPreferenceDelegate(resources.getString(R.string.key_sources_hidden)) var hiddenSources by StringSetPreferenceDelegate(KEY_SOURCES_HIDDEN)
fun getStorageDir(context: Context): File? { fun getStorageDir(context: Context): File? {
val value = prefs.getString(context.getString(R.string.key_local_storage), null)?.let { val value = prefs.getString(KEY_LOCAL_STORAGE, null)?.let {
File(it) File(it)
}?.takeIf { it.exists() && it.canWrite() } }?.takeIf { it.exists() && it.canWrite() }
return value ?: LocalMangaRepository.getFallbackStorageDir(context) return value ?: LocalMangaRepository.getFallbackStorageDir(context)
} }
fun setStorageDir(context: Context, file: File?) { fun setStorageDir(context: Context, file: File?) {
val key = context.getString(R.string.key_local_storage)
prefs.edit { prefs.edit {
if (file == null) { if (file == null) {
remove(key) remove(KEY_LOCAL_STORAGE)
} else { } else {
putString(key, file.path) putString(KEY_LOCAL_STORAGE, file.path)
} }
} }
} }
@@ -147,5 +115,33 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
const val TRACK_HISTORY = "history" const val TRACK_HISTORY = "history"
const val TRACK_FAVOURITES = "favourites" const val TRACK_FAVOURITES = "favourites"
const val KEY_LIST_MODE = "list_mode"
const val KEY_APP_SECTION = "app_section"
const val KEY_THEME = "theme"
const val KEY_SOURCES_ORDER = "sources_order"
const val KEY_SOURCES_HIDDEN = "sources_hidden"
const val KEY_TRAFFIC_WARNING = "traffic_warning"
const val KEY_PAGES_CACHE_CLEAR = "pages_cache_clear"
const val KEY_THUMBS_CACHE_CLEAR = "thumbs_cache_clear"
const val KEY_SEARCH_HISTORY_CLEAR = "search_history_clear"
const val KEY_UPDATES_FEED_CLEAR = "updates_feed_clear"
const val KEY_GRID_SIZE = "grid_size"
const val KEY_REMOTE_SOURCES = "remote_sources"
const val KEY_LOCAL_STORAGE = "local_storage"
const val KEY_READER_SWITCHERS = "reader_switchers"
const val KEY_TRACK_SOURCES = "track_sources"
const val KEY_APP_UPDATE = "app_update"
const val KEY_APP_UPDATE_AUTO = "app_update_auto"
const val KEY_TRACKER_NOTIFICATIONS = "tracker_notifications"
const val KEY_NOTIFICATIONS_SETTINGS = "notifications_settings"
const val KEY_NOTIFICATIONS_SOUND = "notifications_sound"
const val KEY_NOTIFICATIONS_VIBRATE = "notifications_vibrate"
const val KEY_NOTIFICATIONS_LIGHT = "notifications_light"
const val KEY_READER_ANIMATION = "reader_animation"
const val KEY_READER_PREFER_RTL = "reader_prefer_rtl"
const val KEY_APP_PASSWORD = "app_password"
const val KEY_PROTECT_APP = "protect_app"
const val KEY_APP_VERSION = "app_version"
} }
} }

View File

@@ -1,33 +1,32 @@
package org.koitharu.kotatsu.core.prefs package org.koitharu.kotatsu.core.prefs
import android.content.Context import android.content.Context
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
interface SourceConfig { interface SourceSettings {
fun getDomain(defaultValue: String): String fun getDomain(defaultValue: String): String
fun isUseSsl(defaultValue: Boolean): Boolean fun isUseSsl(defaultValue: Boolean): Boolean
private class PrefSourceConfig(context: Context, source: MangaSource) : SourceConfig { private class PrefSourceSettings(context: Context, source: MangaSource) : SourceSettings {
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE) private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
private val keyDomain = context.getString(R.string.key_parser_domain) override fun getDomain(defaultValue: String) = prefs.getString(KEY_DOMAIN, defaultValue)
private val keySsl = context.getString(R.string.key_parser_ssl)
override fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue)
?.takeUnless(String::isBlank) ?.takeUnless(String::isBlank)
?: defaultValue ?: defaultValue
override fun isUseSsl(defaultValue: Boolean) = prefs.getBoolean(keySsl, defaultValue) override fun isUseSsl(defaultValue: Boolean) = prefs.getBoolean(KEY_USE_SSL, defaultValue)
} }
companion object { companion object {
@JvmStatic @JvmStatic
operator fun invoke(context: Context, source: MangaSource): SourceConfig = operator fun invoke(context: Context, source: MangaSource): SourceSettings =
PrefSourceConfig(context, source) PrefSourceSettings(context, source)
const val KEY_DOMAIN = "domain"
const val KEY_USE_SSL = "ssl"
} }
} }

View File

@@ -5,7 +5,7 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.get import org.koin.core.component.get
import org.koin.core.component.inject import org.koin.core.component.inject
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.prefs.SourceConfig import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.utils.ext.await import org.koitharu.kotatsu.utils.ext.await
open class MangaLoaderContext : KoinComponent { open class MangaLoaderContext : KoinComponent {
@@ -64,7 +64,7 @@ open class MangaLoaderContext : KoinComponent {
return okHttp.newCall(request.build()).await() return okHttp.newCall(request.build()).await()
} }
open fun getSettings(source: MangaSource) = SourceConfig(get(), source) open fun getSettings(source: MangaSource) = SourceSettings(get(), source)
fun insertCookies(domain: String, vararg cookies: String) { fun insertCookies(domain: String, vararg cookies: String) {
val url = HttpUrl.Builder() val url = HttpUrl.Builder()

View File

@@ -1,7 +1,6 @@
package org.koitharu.kotatsu.ui.base package org.koitharu.kotatsu.ui.base
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
@@ -15,8 +14,4 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
super.onResume() super.onResume()
activity?.setTitle(titleId) activity?.setTitle(titleId)
} }
fun <T : Preference> findPreference(@StringRes keyId: Int): T? =
findPreference(getString(keyId))
} }

View File

@@ -197,8 +197,8 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) { when (key) {
getString(R.string.key_sources_hidden), AppSettings.KEY_SOURCES_HIDDEN,
getString(R.string.key_sources_order) -> { AppSettings.KEY_SOURCES_ORDER -> {
initSideMenu(MangaProviderFactory.getSources(includeHidden = false)) initSideMenu(MangaProviderFactory.getSources(includeHidden = false))
} }
} }

View File

@@ -203,8 +203,8 @@ abstract class MangaListFragment<E> : BaseFragment(R.layout.fragment_list),
return return
} }
when (key) { when (key) {
getString(R.string.key_list_mode) -> initListMode(settings.listMode) AppSettings.KEY_LIST_MODE -> initListMode(settings.listMode)
getString(R.string.key_grid_size) -> UiUtils.SpanCountResolver.update(recyclerView) AppSettings.KEY_GRID_SIZE -> UiUtils.SpanCountResolver.update(recyclerView)
} }
} }

View File

@@ -116,8 +116,8 @@ abstract class MangaListSheet<E> : BaseBottomSheet(R.layout.sheet_list),
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) { when (key) {
getString(R.string.key_list_mode) -> initListMode(settings.listMode) AppSettings.KEY_LIST_MODE -> initListMode(settings.listMode)
getString(R.string.key_grid_size) -> UiUtils.SpanCountResolver.update(recyclerView) AppSettings.KEY_GRID_SIZE -> UiUtils.SpanCountResolver.update(recyclerView)
} }
} }

View File

@@ -68,7 +68,7 @@ class ReversedReaderFragment : AbstractReader(R.layout.fragment_reader_standard)
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) { when (key) {
getString(R.string.key_reader_animation) -> { AppSettings.KEY_READER_ANIMATION -> {
if (settings.readerAnimation) { if (settings.readerAnimation) {
pager.setPageTransformer(PageAnimTransformer()) pager.setPageTransformer(PageAnimTransformer())
} else { } else {

View File

@@ -64,7 +64,7 @@ class PagerReaderFragment : AbstractReader(R.layout.fragment_reader_standard),
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) { when (key) {
getString(R.string.key_reader_animation) -> { AppSettings.KEY_READER_ANIMATION -> {
if (settings.readerAnimation) { if (settings.readerAnimation) {
pager.setPageTransformer(PageAnimTransformer()) pager.setPageTransformer(PageAnimTransformer())
} else { } else {

View File

@@ -9,6 +9,7 @@ import kotlinx.coroutines.withContext
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.local.Cache import org.koitharu.kotatsu.core.local.Cache
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.domain.tracking.TrackingRepository import org.koitharu.kotatsu.domain.tracking.TrackingRepository
import org.koitharu.kotatsu.ui.base.BasePreferenceFragment import org.koitharu.kotatsu.ui.base.BasePreferenceFragment
import org.koitharu.kotatsu.ui.search.MangaSuggestionsProvider import org.koitharu.kotatsu.ui.search.MangaSuggestionsProvider
@@ -23,7 +24,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_history) addPreferencesFromResource(R.xml.pref_history)
findPreference<Preference>(R.string.key_pages_cache_clear)?.let { pref -> findPreference<Preference>(AppSettings.KEY_PAGES_CACHE_CLEAR)?.let { pref ->
viewLifecycleScope.launchWhenResumed { viewLifecycleScope.launchWhenResumed {
val size = withContext(Dispatchers.IO) { val size = withContext(Dispatchers.IO) {
CacheUtils.computeCacheSize(pref.context, Cache.PAGES.dir) CacheUtils.computeCacheSize(pref.context, Cache.PAGES.dir)
@@ -31,7 +32,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
pref.summary = FileSizeUtils.formatBytes(pref.context, size) pref.summary = FileSizeUtils.formatBytes(pref.context, size)
} }
} }
findPreference<Preference>(R.string.key_thumbs_cache_clear)?.let { pref -> findPreference<Preference>(AppSettings.KEY_THUMBS_CACHE_CLEAR)?.let { pref ->
viewLifecycleScope.launchWhenResumed { viewLifecycleScope.launchWhenResumed {
val size = withContext(Dispatchers.IO) { val size = withContext(Dispatchers.IO) {
CacheUtils.computeCacheSize(pref.context, Cache.THUMBS.dir) CacheUtils.computeCacheSize(pref.context, Cache.THUMBS.dir)
@@ -39,11 +40,11 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
pref.summary = FileSizeUtils.formatBytes(pref.context, size) pref.summary = FileSizeUtils.formatBytes(pref.context, size)
} }
} }
findPreference<Preference>(R.string.key_search_history_clear)?.let { p -> findPreference<Preference>(AppSettings.KEY_SEARCH_HISTORY_CLEAR)?.let { p ->
val items = MangaSuggestionsProvider.getItemsCount(p.context) val items = MangaSuggestionsProvider.getItemsCount(p.context)
p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items) p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items)
} }
findPreference<Preference>(R.string.key_updates_feed_clear)?.let { p -> findPreference<Preference>(AppSettings.KEY_UPDATES_FEED_CLEAR)?.let { p ->
viewLifecycleScope.launchWhenResumed { viewLifecycleScope.launchWhenResumed {
val items = trackerRepo.count() val items = trackerRepo.count()
p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items) p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items)
@@ -53,15 +54,15 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
override fun onPreferenceTreeClick(preference: Preference): Boolean { override fun onPreferenceTreeClick(preference: Preference): Boolean {
return when (preference.key) { return when (preference.key) {
getString(R.string.key_pages_cache_clear) -> { AppSettings.KEY_PAGES_CACHE_CLEAR -> {
clearCache(preference, Cache.PAGES) clearCache(preference, Cache.PAGES)
true true
} }
getString(R.string.key_thumbs_cache_clear) -> { AppSettings.KEY_THUMBS_CACHE_CLEAR -> {
clearCache(preference, Cache.THUMBS) clearCache(preference, Cache.THUMBS)
true true
} }
getString(R.string.key_search_history_clear) -> { AppSettings.KEY_SEARCH_HISTORY_CLEAR -> {
MangaSuggestionsProvider.clearHistory(preference.context) MangaSuggestionsProvider.clearHistory(preference.context)
preference.summary = preference.context.resources preference.summary = preference.context.resources
.getQuantityString(R.plurals.items, 0, 0) .getQuantityString(R.plurals.items, 0, 0)
@@ -72,7 +73,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
).show() ).show()
true true
} }
getString(R.string.key_updates_feed_clear) -> { AppSettings.KEY_UPDATES_FEED_CLEAR -> {
viewLifecycleScope.launch { viewLifecycleScope.launch {
trackerRepo.clearLogs() trackerRepo.clearLogs()
preference.summary = preference.context.resources preference.summary = preference.context.resources

View File

@@ -16,6 +16,7 @@ import kotlinx.coroutines.launch
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ListMode import org.koitharu.kotatsu.core.prefs.ListMode
import org.koitharu.kotatsu.ui.base.BasePreferenceFragment import org.koitharu.kotatsu.ui.base.BasePreferenceFragment
import org.koitharu.kotatsu.ui.base.dialog.StorageSelectDialog import org.koitharu.kotatsu.ui.base.dialog.StorageSelectDialog
@@ -35,29 +36,29 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_main) addPreferencesFromResource(R.xml.pref_main)
findPreference<Preference>(R.string.key_list_mode)?.summary = findPreference<Preference>(AppSettings.KEY_LIST_MODE)?.summary =
LIST_MODES[settings.listMode]?.let(::getString) LIST_MODES[settings.listMode]?.let(::getString)
findPreference<SeekBarPreference>(R.string.key_grid_size)?.run { findPreference<SeekBarPreference>(AppSettings.KEY_GRID_SIZE)?.run {
summary = "%d%%".format(value) summary = "%d%%".format(value)
setOnPreferenceChangeListener { preference, newValue -> setOnPreferenceChangeListener { preference, newValue ->
preference.summary = "%d%%".format(newValue) preference.summary = "%d%%".format(newValue)
true true
} }
} }
findPreference<MultiSelectListPreference>(R.string.key_reader_switchers)?.summaryProvider = findPreference<MultiSelectListPreference>(AppSettings.KEY_READER_SWITCHERS)?.summaryProvider =
MultiSummaryProvider(R.string.gestures_only) MultiSummaryProvider(R.string.gestures_only)
findPreference<MultiSelectListPreference>(R.string.key_track_sources)?.summaryProvider = findPreference<MultiSelectListPreference>(AppSettings.KEY_TRACK_SOURCES)?.summaryProvider =
MultiSummaryProvider(R.string.dont_check) MultiSummaryProvider(R.string.dont_check)
findPreference<Preference>(R.string.key_app_update_auto)?.run { findPreference<Preference>(AppSettings.KEY_APP_UPDATE_AUTO)?.run {
isVisible = AppUpdateChecker.isUpdateSupported(context) isVisible = AppUpdateChecker.isUpdateSupported(context)
} }
findPreference<Preference>(R.string.key_local_storage)?.run { findPreference<Preference>(AppSettings.KEY_LOCAL_STORAGE)?.run {
summary = settings.getStorageDir(context)?.getStorageName(context) summary = settings.getStorageDir(context)?.getStorageName(context)
?: getString(R.string.not_available) ?: getString(R.string.not_available)
} }
findPreference<SwitchPreference>(R.string.key_protect_app)?.isChecked = findPreference<SwitchPreference>(AppSettings.KEY_PROTECT_APP)?.isChecked =
!settings.appPassword.isNullOrEmpty() !settings.appPassword.isNullOrEmpty()
findPreference<Preference>(R.string.key_app_version)?.run { findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
title = getString(R.string.app_version, BuildConfig.VERSION_NAME) title = getString(R.string.app_version, BuildConfig.VERSION_NAME)
isEnabled = AppUpdateChecker.isUpdateSupported(context) isEnabled = AppUpdateChecker.isUpdateSupported(context)
} }
@@ -65,13 +66,13 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
when (key) { when (key) {
getString(R.string.key_list_mode) -> findPreference<Preference>(R.string.key_list_mode)?.summary = AppSettings.KEY_LIST_MODE -> findPreference<Preference>(key)?.summary =
LIST_MODES[settings.listMode]?.let(::getString) LIST_MODES[settings.listMode]?.let(::getString)
getString(R.string.key_theme) -> { AppSettings.KEY_THEME -> {
AppCompatDelegate.setDefaultNightMode(settings.theme) AppCompatDelegate.setDefaultNightMode(settings.theme)
} }
getString(R.string.key_local_storage) -> { AppSettings.KEY_LOCAL_STORAGE -> {
findPreference<Preference>(R.string.key_local_storage)?.run { findPreference<Preference>(key)?.run {
summary = settings.getStorageDir(context)?.getStorageName(context) summary = settings.getStorageDir(context)?.getStorageName(context)
?: getString(R.string.not_available) ?: getString(R.string.not_available)
} }
@@ -91,7 +92,7 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
findPreference<PreferenceScreen>(R.string.key_remote_sources)?.run { findPreference<PreferenceScreen>(AppSettings.KEY_REMOTE_SOURCES)?.run {
val total = MangaSource.values().size - 1 val total = MangaSource.values().size - 1
summary = getString( summary = getString(
R.string.enabled_d_from_d, total - settings.hiddenSources.size, total R.string.enabled_d_from_d, total - settings.hiddenSources.size, total
@@ -101,11 +102,11 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) { return when (preference?.key) {
getString(R.string.key_list_mode) -> { AppSettings.KEY_LIST_MODE -> {
ListModeSelectDialog.show(childFragmentManager) ListModeSelectDialog.show(childFragmentManager)
true true
} }
getString(R.string.key_notifications_settings) -> { AppSettings.KEY_NOTIFICATIONS_SETTINGS -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName) .putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
@@ -116,7 +117,7 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
} }
true true
} }
getString(R.string.key_local_storage) -> { AppSettings.KEY_LOCAL_STORAGE -> {
val ctx = context ?: return false val ctx = context ?: return false
StorageSelectDialog.Builder(ctx, settings.getStorageDir(ctx), this) StorageSelectDialog.Builder(ctx, settings.getStorageDir(ctx), this)
.setTitle(preference.title) .setTitle(preference.title)
@@ -125,7 +126,7 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
.show() .show()
true true
} }
getString(R.string.key_protect_app) -> { AppSettings.KEY_PROTECT_APP -> {
if ((preference as? SwitchPreference ?: return false).isChecked) { if ((preference as? SwitchPreference ?: return false).isChecked) {
enableAppProtection(preference) enableAppProtection(preference)
} else { } else {
@@ -133,7 +134,7 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
} }
true true
} }
getString(R.string.key_app_version) -> { AppSettings.KEY_APP_VERSION -> {
checkForUpdates() checkForUpdates()
true true
} }
@@ -197,12 +198,12 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
private fun checkForUpdates() { private fun checkForUpdates() {
viewLifecycleScope.launch { viewLifecycleScope.launch {
findPreference<Preference>(R.string.key_app_version)?.run { findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
setSummary(R.string.checking_for_updates) setSummary(R.string.checking_for_updates)
isSelectable = false isSelectable = false
} }
val result = AppUpdateChecker(activity ?: return@launch).checkNow() val result = AppUpdateChecker(activity ?: return@launch).checkNow()
findPreference<Preference>(R.string.key_app_version)?.run { findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
setSummary( setSummary(
when (result) { when (result) {
true -> R.string.check_for_updates true -> R.string.check_for_updates

View File

@@ -4,6 +4,7 @@ import android.media.RingtoneManager
import android.os.Bundle import android.os.Bundle
import androidx.preference.Preference import androidx.preference.Preference
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.ui.base.BasePreferenceFragment import org.koitharu.kotatsu.ui.base.BasePreferenceFragment
import org.koitharu.kotatsu.ui.settings.utils.RingtonePickContract import org.koitharu.kotatsu.ui.settings.utils.RingtonePickContract
import org.koitharu.kotatsu.utils.ext.toUriOrNull import org.koitharu.kotatsu.utils.ext.toUriOrNull
@@ -12,7 +13,7 @@ class NotificationSettingsLegacyFragment : BasePreferenceFragment(R.string.notif
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_notifications) addPreferencesFromResource(R.xml.pref_notifications)
findPreference<Preference>(R.string.key_notifications_sound)?.run { findPreference<Preference>(AppSettings.KEY_NOTIFICATIONS_SOUND)?.run {
val uri = settings.notificationSound.toUriOrNull() val uri = settings.notificationSound.toUriOrNull()
summary = RingtoneManager.getRingtone(context, uri).getTitle(context) summary = RingtoneManager.getRingtone(context, uri).getTitle(context)
} }
@@ -20,10 +21,10 @@ class NotificationSettingsLegacyFragment : BasePreferenceFragment(R.string.notif
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) { return when (preference?.key) {
getString(R.string.key_notifications_sound) -> { AppSettings.KEY_NOTIFICATIONS_SOUND -> {
registerForActivityResult(RingtonePickContract(preference.title.toString())) { uri -> registerForActivityResult(RingtonePickContract(preference.title.toString())) { uri ->
settings.notificationSound = uri?.toString().orEmpty() settings.notificationSound = uri?.toString().orEmpty()
findPreference<Preference>(R.string.key_notifications_sound)?.run { findPreference<Preference>(AppSettings.KEY_NOTIFICATIONS_SOUND)?.run {
summary = RingtoneManager.getRingtone(context, uri).getTitle(context) summary = RingtoneManager.getRingtone(context, uri).getTitle(context)
} }
}.launch(settings.notificationSound.toUriOrNull()) }.launch(settings.notificationSound.toUriOrNull())

View File

@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.ui.settings
import android.os.Bundle import android.os.Bundle
import androidx.preference.MultiSelectListPreference import androidx.preference.MultiSelectListPreference
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.ui.base.BasePreferenceFragment import org.koitharu.kotatsu.ui.base.BasePreferenceFragment
import org.koitharu.kotatsu.ui.settings.utils.MultiSummaryProvider import org.koitharu.kotatsu.ui.settings.utils.MultiSummaryProvider
@@ -10,7 +11,7 @@ class ReaderSettingsFragment : BasePreferenceFragment(R.string.reader_settings)
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_reader) addPreferencesFromResource(R.xml.pref_reader)
findPreference<MultiSelectListPreference>(R.string.key_reader_switchers)?.let { findPreference<MultiSelectListPreference>(AppSettings.KEY_READER_SWITCHERS)?.let {
it.summaryProvider = MultiSummaryProvider(R.string.gestures_only) it.summaryProvider = MultiSummaryProvider(R.string.gestures_only)
} }
} }

View File

@@ -6,6 +6,7 @@ import androidx.preference.PreferenceFragmentCompat
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.ui.settings.utils.EditTextSummaryProvider import org.koitharu.kotatsu.ui.settings.utils.EditTextSummaryProvider
import org.koitharu.kotatsu.utils.ext.withArgs import org.koitharu.kotatsu.utils.ext.withArgs
@@ -23,13 +24,13 @@ class SourceSettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.sharedPreferencesName = source.name preferenceManager.sharedPreferencesName = source.name
val repo = source.repository as? RemoteMangaRepository ?: return val repo = source.repository as? RemoteMangaRepository ?: return
val keys = repo.onCreatePreferences().map(::getString) val keys = repo.onCreatePreferences()
addPreferencesFromResource(R.xml.pref_source) addPreferencesFromResource(R.xml.pref_source)
for (i in 0 until preferenceScreen.preferenceCount) { for (i in 0 until preferenceScreen.preferenceCount) {
val pref = preferenceScreen.getPreference(i) val pref = preferenceScreen.getPreference(i)
pref.isVisible = pref.key in keys pref.isVisible = pref.key in keys
} }
findPreference<EditTextPreference>(getString(R.string.key_parser_domain))?.summaryProvider = findPreference<EditTextPreference>(SourceSettings.KEY_DOMAIN)?.summaryProvider =
EditTextSummaryProvider(R.string._default) EditTextSummaryProvider(R.string._default)
} }

View File

@@ -5,11 +5,11 @@ import androidx.core.content.edit
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
class BoolPreferenceDelegate(private val key: String, private val defValue: Boolean) : class BoolPreferenceDelegate(private val key: String, private val defaultValue: Boolean) :
ReadWriteProperty<SharedPreferences, Boolean> { ReadWriteProperty<SharedPreferences, Boolean> {
override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Boolean { override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Boolean {
return thisRef.getBoolean(key, defValue) return thisRef.getBoolean(key, defaultValue)
} }
override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Boolean) { override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Boolean) {

View File

@@ -5,11 +5,11 @@ import androidx.core.content.edit
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
class IntPreferenceDelegate(private val key: String, private val defValue: Int) : class IntPreferenceDelegate(private val key: String, private val defaultValue: Int) :
ReadWriteProperty<SharedPreferences, Int> { ReadWriteProperty<SharedPreferences, Int> {
override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Int { override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Int {
return thisRef.getInt(key, defValue) return thisRef.getInt(key, defaultValue)
} }
override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Int) { override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Int) {

View File

@@ -5,11 +5,11 @@ import androidx.core.content.edit
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
class LongPreferenceDelegate(private val key: String, private val defValue: Long) : class LongPreferenceDelegate(private val key: String, private val defaultValue: Long) :
ReadWriteProperty<SharedPreferences, Long> { ReadWriteProperty<SharedPreferences, Long> {
override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Long { override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Long {
return thisRef.getLong(key, defValue) return thisRef.getLong(key, defaultValue)
} }
override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Long) { override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Long) {

View File

@@ -1,35 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="key_list_mode">list_mode</string>
<string name="key_app_section">app_section</string>
<string name="key_theme">theme</string>
<string name="key_sources_order">sources_order</string>
<string name="key_sources_hidden">sources_hidden</string>
<string name="key_traffic_warning">traffic_warning</string>
<string name="key_pages_cache_clear">pages_cache_clear</string>
<string name="key_thumbs_cache_clear">thumbs_cache_clear</string>
<string name="key_search_history_clear">search_history_clear</string>
<string name="key_updates_feed_clear">updates_feed_clear</string>
<string name="key_grid_size">grid_size</string>
<string name="key_remote_sources">remote_sources</string>
<string name="key_local_storage">local_storage</string>
<string name="key_reader_switchers">reader_switchers</string>
<string name="key_track_sources">track_sources</string>
<string name="key_app_update">app_update</string>
<string name="key_app_update_auto">app_update_auto</string>
<string name="key_tracker_notifications">tracker_notifications</string>
<string name="key_notifications_settings">notifications_settings</string>
<string name="key_notifications_sound">notifications_sound</string>
<string name="key_notifications_vibrate">notifications_vibrate</string>
<string name="key_notifications_light">notifications_light</string>
<string name="key_reader_animation">reader_animation</string>
<string name="key_reader_prefer_rtl">reader_prefer_rtl</string>
<string name="key_app_password">app_password</string>
<string name="key_protect_app">protect_app</string>
<string name="key_app_version">app_version</string>
<string name="key_parser_domain">domain</string>
<string name="key_parser_ssl">ssl</string>
<string-array name="values_theme"> <string-array name="values_theme">
<item>-1</item> <item>-1</item>
<item>1</item> <item>1</item>

View File

@@ -4,13 +4,13 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference <Preference
android:key="@string/key_search_history_clear" android:key="search_history_clear"
android:persistent="false" android:persistent="false"
android:title="@string/clear_search_history" android:title="@string/clear_search_history"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference <Preference
android:key="@string/key_updates_feed_clear" android:key="updates_feed_clear"
android:persistent="false" android:persistent="false"
android:title="@string/clear_updates_feed" android:title="@string/clear_updates_feed"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
@@ -20,13 +20,13 @@
android:title="@string/cache"> android:title="@string/cache">
<Preference <Preference
android:key="@string/key_thumbs_cache_clear" android:key="thumbs_cache_clear"
android:persistent="false" android:persistent="false"
android:title="@string/clear_thumbs_cache" android:title="@string/clear_thumbs_cache"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference <Preference
android:key="@string/key_pages_cache_clear" android:key="pages_cache_clear"
android:persistent="false" android:persistent="false"
android:title="@string/clear_pages_cache" android:title="@string/clear_pages_cache"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

View File

@@ -8,20 +8,20 @@
android:defaultValue="-1" android:defaultValue="-1"
android:entries="@array/themes" android:entries="@array/themes"
android:entryValues="@array/values_theme" android:entryValues="@array/values_theme"
android:key="@string/key_theme" android:key="theme"
android:title="@string/theme" android:title="@string/theme"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<Preference <Preference
android:key="@string/key_list_mode" android:key="list_mode"
android:persistent="false" android:persistent="false"
android:title="@string/list_mode" android:title="@string/list_mode"
app:allowDividerAbove="true" app:allowDividerAbove="true"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SeekBarPreference <SeekBarPreference
android:key="@string/key_grid_size" android:key="grid_size"
android:max="150" android:max="150"
android:title="@string/grid_size" android:title="@string/grid_size"
app:defaultValue="100" app:defaultValue="100"
@@ -33,13 +33,13 @@
<PreferenceScreen <PreferenceScreen
android:fragment="org.koitharu.kotatsu.ui.settings.sources.SourcesSettingsFragment" android:fragment="org.koitharu.kotatsu.ui.settings.sources.SourcesSettingsFragment"
android:key="@string/key_remote_sources" android:key="remote_sources"
android:title="@string/remote_sources" android:title="@string/remote_sources"
app:allowDividerAbove="true" app:allowDividerAbove="true"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference <Preference
android:key="@string/key_local_storage" android:key="local_storage"
android:title="@string/manga_save_location" android:title="@string/manga_save_location"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
@@ -49,7 +49,7 @@
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference <SwitchPreference
android:key="@string/key_protect_app" android:key="protect_app"
android:persistent="false" android:persistent="false"
android:summary="@string/protect_application_summary" android:summary="@string/protect_application_summary"
android:title="@string/protect_application" android:title="@string/protect_application"
@@ -59,20 +59,20 @@
android:defaultValue="@array/values_reader_switchers_default" android:defaultValue="@array/values_reader_switchers_default"
android:entries="@array/reader_switchers" android:entries="@array/reader_switchers"
android:entryValues="@array/values_reader_switchers" android:entryValues="@array/values_reader_switchers"
android:key="@string/key_reader_switchers" android:key="reader_switchers"
android:title="@string/switch_pages" android:title="@string/switch_pages"
app:allowDividerAbove="true" app:allowDividerAbove="true"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_reader_animation" android:key="reader_animation"
android:title="@string/pages_animation" android:title="@string/pages_animation"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_reader_prefer_rtl" android:key="reader_prefer_rtl"
android:summary="@string/prefer_rtl_reader_summary" android:summary="@string/prefer_rtl_reader_summary"
android:title="@string/prefer_rtl_reader" android:title="@string/prefer_rtl_reader"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
@@ -86,20 +86,20 @@
android:defaultValue="@array/values_track_sources_default" android:defaultValue="@array/values_track_sources_default"
android:entries="@array/track_sources" android:entries="@array/track_sources"
android:entryValues="@array/values_track_sources" android:entryValues="@array/values_track_sources"
android:key="@string/key_track_sources" android:key="track_sources"
android:title="@string/track_sources" android:title="@string/track_sources"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_tracker_notifications" android:key="tracker_notifications"
android:summary="@string/show_notification_new_chapters" android:summary="@string/show_notification_new_chapters"
android:title="@string/notifications" android:title="@string/notifications"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference <Preference
android:dependency="@string/key_tracker_notifications" android:dependency="tracker_notifications"
android:key="@string/key_notifications_settings" android:key="notifications_settings"
android:title="@string/notifications_settings" android:title="@string/notifications_settings"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
@@ -111,7 +111,7 @@
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_app_update_auto" android:key="app_update_auto"
android:summary="@string/show_notification_app_update" android:summary="@string/show_notification_app_update"
android:title="@string/application_update" android:title="@string/application_update"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
@@ -119,7 +119,7 @@
tools:isPreferenceVisible="true" /> tools:isPreferenceVisible="true" />
<Preference <Preference
android:key="@string/key_app_version" android:key="app_version"
android:persistent="false" android:persistent="false"
android:summary="@string/check_for_updates" android:summary="@string/check_for_updates"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

View File

@@ -4,19 +4,19 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference <Preference
android:key="@string/key_notifications_sound" android:key="notifications_sound"
android:title="@string/notification_sound" android:title="@string/notification_sound"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_notifications_vibrate" android:key="notifications_vibrate"
android:title="@string/vibration" android:title="@string/vibration"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_notifications_light" android:key="notifications_light"
android:title="@string/light_indicator" android:title="@string/light_indicator"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

View File

@@ -7,19 +7,19 @@
android:defaultValue="@array/values_reader_switchers_default" android:defaultValue="@array/values_reader_switchers_default"
android:entries="@array/reader_switchers" android:entries="@array/reader_switchers"
android:entryValues="@array/values_reader_switchers" android:entryValues="@array/values_reader_switchers"
android:key="@string/key_reader_switchers" android:key="reader_switchers"
android:title="@string/switch_pages" android:title="@string/switch_pages"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_reader_animation" android:key="reader_animation"
android:title="@string/pages_animation" android:title="@string/pages_animation"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_reader_prefer_rtl" android:key="reader_prefer_rtl"
android:summary="@string/prefer_rtl_reader_summary" android:summary="@string/prefer_rtl_reader_summary"
android:title="@string/prefer_rtl_reader" android:title="@string/prefer_rtl_reader"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

View File

@@ -3,12 +3,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference <EditTextPreference
android:key="@string/key_parser_domain" android:key="domain"
android:title="@string/domain" android:title="@string/domain"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="@string/key_parser_ssl" android:key="ssl"
android:title="@string/use_ssl" android:title="@string/use_ssl"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

View File

@@ -13,7 +13,7 @@ import org.koin.test.KoinTest
import org.koin.test.get import org.koin.test.get
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
import org.koitharu.kotatsu.core.prefs.SourceConfig import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.domain.MangaLoaderContext import org.koitharu.kotatsu.domain.MangaLoaderContext
import org.koitharu.kotatsu.utils.AssertX import org.koitharu.kotatsu.utils.AssertX
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@@ -106,8 +106,8 @@ class RemoteRepositoryTest(source: MangaSource) : KoinTest {
module { module {
single<MangaLoaderContext> { single<MangaLoaderContext> {
object : MangaLoaderContext() { object : MangaLoaderContext() {
override fun getSettings(source: MangaSource): SourceConfig { override fun getSettings(source: MangaSource): SourceSettings {
return SourceConfigMock() return SourceSettingsMock()
} }
} }
} }

View File

@@ -1,8 +1,8 @@
package org.koitharu.kotatsu.parsers package org.koitharu.kotatsu.parsers
import org.koitharu.kotatsu.core.prefs.SourceConfig import org.koitharu.kotatsu.core.prefs.SourceSettings
class SourceConfigMock : SourceConfig { class SourceSettingsMock : SourceSettings {
override fun getDomain(defaultValue: String) = defaultValue override fun getDomain(defaultValue: String) = defaultValue