mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Add simple method for preference bindings
This commit is contained in:
parent
1f70be688a
commit
4524c705da
8 changed files with 31 additions and 34 deletions
|
@ -22,6 +22,15 @@ import java.text.SimpleDateFormat
|
|||
import java.util.*
|
||||
|
||||
class SettingsAboutFragment : SettingsFragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance(rootKey: String): SettingsAboutFragment {
|
||||
val args = Bundle()
|
||||
args.putString(XpPreferenceFragment.ARG_PREFERENCE_ROOT, rootKey)
|
||||
return SettingsAboutFragment().apply { arguments = args }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for new releases
|
||||
*/
|
||||
|
@ -32,17 +41,7 @@ class SettingsAboutFragment : SettingsFragment() {
|
|||
*/
|
||||
private var releaseSubscription: Subscription? = null
|
||||
|
||||
val automaticUpdates by lazy {
|
||||
findPreference(getString(R.string.pref_enable_automatic_updates_key)) as SwitchPreference
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(rootKey: String): SettingsAboutFragment {
|
||||
val args = Bundle()
|
||||
args.putString(XpPreferenceFragment.ARG_PREFERENCE_ROOT, rootKey)
|
||||
return SettingsAboutFragment().apply { arguments = args }
|
||||
}
|
||||
}
|
||||
val automaticUpdates: SwitchPreference by bindPref(R.string.pref_enable_automatic_updates_key)
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.XpPreferenceFragment
|
||||
import android.view.View
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
|
@ -33,13 +34,13 @@ class SettingsAdvancedFragment : SettingsFragment() {
|
|||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
|
||||
private val clearCache by lazy { findPreference(getString(R.string.pref_clear_chapter_cache_key)) }
|
||||
private val clearCache: Preference by bindPref(R.string.pref_clear_chapter_cache_key)
|
||||
|
||||
private val clearDatabase by lazy { findPreference(getString(R.string.pref_clear_database_key)) }
|
||||
private val clearDatabase: Preference by bindPref(R.string.pref_clear_database_key)
|
||||
|
||||
private val clearCookies by lazy { findPreference(getString(R.string.pref_clear_cookies_key)) }
|
||||
private val clearCookies: Preference by bindPref(R.string.pref_clear_cookies_key)
|
||||
|
||||
private val refreshMetadata by lazy { findPreference(getString(R.string.pref_refresh_library_metadata_key)) }
|
||||
private val refreshMetadata: Preference by bindPref(R.string.pref_refresh_library_metadata_key)
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.XpPreferenceFragment
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
|
@ -36,7 +37,7 @@ class SettingsDownloadsFragment : SettingsFragment() {
|
|||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
val downloadDirPref by lazy { findPreference(getString(R.string.pref_download_directory_key)) }
|
||||
val downloadDirPref: Preference by bindPref(R.string.pref_download_directory_key)
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
|||
import android.support.annotation.CallSuper
|
||||
import android.support.graphics.drawable.VectorDrawableCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.XpPreferenceFragment
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
@ -83,4 +84,8 @@ open class SettingsFragment : XpPreferenceFragment() {
|
|||
"about_screen" to R.drawable.ic_help_black_24dp
|
||||
)
|
||||
|
||||
protected inline fun <reified T : Preference> bindPref(resId: Int): Lazy<T> {
|
||||
return lazy { findPreference(getString(resId)) as T }
|
||||
}
|
||||
|
||||
}
|
|
@ -34,26 +34,15 @@ class SettingsGeneralFragment : SettingsFragment(),
|
|||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
|
||||
val columnsPreference: SimpleDialogPreference by bindPref(R.string.pref_library_columns_dialog_key)
|
||||
|
||||
val columnsPreference by lazy {
|
||||
findPreference(getString(R.string.pref_library_columns_dialog_key)) as SimpleDialogPreference
|
||||
}
|
||||
val updateInterval: IntListPreference by bindPref(R.string.pref_library_update_interval_key)
|
||||
|
||||
val updateInterval by lazy {
|
||||
findPreference(getString(R.string.pref_library_update_interval_key)) as IntListPreference
|
||||
}
|
||||
val updateRestriction: MultiSelectListPreference by bindPref(R.string.pref_library_update_restriction_key)
|
||||
|
||||
val updateRestriction by lazy {
|
||||
findPreference(getString(R.string.pref_library_update_restriction_key)) as MultiSelectListPreference
|
||||
}
|
||||
val themePreference: IntListPreference by bindPref(R.string.pref_theme_key)
|
||||
|
||||
val themePreference by lazy {
|
||||
findPreference(getString(R.string.pref_theme_key)) as IntListPreference
|
||||
}
|
||||
|
||||
val categoryUpdate by lazy {
|
||||
findPreference(getString(R.string.pref_library_update_categories_key)) as MultiSelectListPreference
|
||||
}
|
||||
val categoryUpdate: MultiSelectListPreference by bindPref(R.string.pref_library_update_categories_key)
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.os.Bundle
|
|||
import android.support.v7.preference.PreferenceCategory
|
||||
import android.support.v7.preference.XpPreferenceFragment
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.mangasync.MangaSyncManager
|
||||
import eu.kanade.tachiyomi.data.mangasync.MangaSyncService
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
@ -28,7 +29,7 @@ class SettingsSyncFragment : SettingsFragment() {
|
|||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
val syncCategory by lazy { findPreference("pref_category_manga_sync_accounts") as PreferenceCategory }
|
||||
val syncCategory: PreferenceCategory by bindPref(R.string.pref_category_manga_sync_accounts_key)
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
<string name="pref_last_used_category_key">last_used_category</string>
|
||||
|
||||
<string name="pref_source_languages">pref_source_languages</string>
|
||||
<string name="pref_category_manga_sync_accounts_key">category_manga_sync_accounts</string>
|
||||
|
||||
<string name="pref_clear_chapter_cache_key">pref_clear_chapter_cache_key</string>
|
||||
<string name="pref_clear_database_key">pref_clear_database_key</string>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
android:dependency="@string/pref_auto_update_manga_sync_key"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_category_manga_sync_accounts"
|
||||
android:key="@string/pref_category_manga_sync_accounts_key"
|
||||
android:title="@string/services"
|
||||
android:persistent="false"/>
|
||||
|
||||
|
|
Loading…
Reference in a new issue