mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 21:18:56 +01:00
Select categories for global update
This commit is contained in:
@@ -6,7 +6,8 @@ import android.support.v7.preference.PreferenceFragmentCompat
|
||||
import android.support.v7.preference.XpPreferenceFragment
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateAlarm
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateTrigger
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.plusAssign
|
||||
import eu.kanade.tachiyomi.widget.preference.IntListPreference
|
||||
@@ -14,6 +15,7 @@ import eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog
|
||||
import eu.kanade.tachiyomi.widget.preference.SimpleDialogPreference
|
||||
import net.xpece.android.support.preference.MultiSelectListPreference
|
||||
import rx.Observable
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class SettingsGeneralFragment : SettingsFragment(),
|
||||
@@ -30,6 +32,8 @@ class SettingsGeneralFragment : SettingsFragment(),
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
|
||||
|
||||
val columnsPreference by lazy {
|
||||
findPreference(getString(R.string.pref_library_columns_dialog_key)) as SimpleDialogPreference
|
||||
@@ -47,6 +51,10 @@ class SettingsGeneralFragment : SettingsFragment(),
|
||||
findPreference(getString(R.string.pref_theme_key)) as IntListPreference
|
||||
}
|
||||
|
||||
val categoryUpdate by lazy {
|
||||
findPreference(getString(R.string.pref_library_update_categories_key)) as MultiSelectListPreference
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
super.onViewCreated(view, savedState)
|
||||
|
||||
@@ -60,10 +68,30 @@ class SettingsGeneralFragment : SettingsFragment(),
|
||||
.subscribe { updateColumnsSummary(it.first, it.second) }
|
||||
|
||||
updateInterval.setOnPreferenceChangeListener { preference, newValue ->
|
||||
LibraryUpdateAlarm.startAlarm(activity, (newValue as String).toInt())
|
||||
val enabled = (newValue as String).toInt() > 0
|
||||
if (enabled)
|
||||
LibraryUpdateTrigger.setupTask(context)
|
||||
else
|
||||
LibraryUpdateTrigger.cancelTask(context)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
categoryUpdate.apply {
|
||||
entries = dbCategories.map { it.name }.toTypedArray()
|
||||
entryValues = dbCategories.map { it.id.toString() }.toTypedArray()
|
||||
}
|
||||
|
||||
subscriptions += preferences.libraryUpdateCategories().asObservable()
|
||||
.subscribe {
|
||||
Timber.e(it.joinToString())
|
||||
categoryUpdate.summary = it
|
||||
.mapNotNull { id -> dbCategories.find { it.id == id.toInt() } }
|
||||
.sortedBy { it.order }
|
||||
.joinToString { it.name }
|
||||
}
|
||||
|
||||
themePreference.setOnPreferenceChangeListener { preference, newValue ->
|
||||
(activity as SettingsActivity).parentFlags = SettingsActivity.FLAG_THEME_CHANGED
|
||||
activity.recreate()
|
||||
|
||||
Reference in New Issue
Block a user