From 78072ad2853256b8c0a53aae466866c4f1fb7b6d Mon Sep 17 00:00:00 2001
From: lmj0011 <9396189+lmj0011@users.noreply.github.com>
Date: Fri, 28 Aug 2020 12:52:30 -0500
Subject: [PATCH 1/2] - implement prefernce highlighting after settings search
---
.../ui/setting/SettingsController.kt | 34 +++++++++++++++++++
.../settingssearch/SettingsSearchHelper.kt | 11 +++++-
.../settingssearch/SettingsSearchHolder.kt | 8 +++--
3 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt
index 6915b17df..a6a3e11ff 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt
@@ -1,6 +1,9 @@
package eu.kanade.tachiyomi.ui.setting
+import android.animation.ArgbEvaluator
+import android.animation.ValueAnimator
import android.content.Context
+import android.graphics.Color
import android.os.Bundle
import android.util.TypedValue
import android.view.ContextThemeWrapper
@@ -9,6 +12,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceController
+import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceScreen
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType
@@ -26,6 +30,7 @@ import uy.kohesive.injekt.api.get
abstract class SettingsController : PreferenceController() {
+ var preferenceKey: String? = null
val preferences: PreferencesHelper = Injekt.get()
val scope = CoroutineScope(Job() + Dispatchers.Main)
@@ -39,6 +44,24 @@ abstract class SettingsController : PreferenceController() {
return super.onCreateView(inflater, container, savedInstanceState)
}
+ override fun onAttach(view: View) {
+ super.onAttach(view)
+
+ preferenceKey?.let { prefKey ->
+ val adapter = listView.adapter
+ scrollToPreference(prefKey)
+
+ listView.post {
+ if (adapter is PreferenceGroup.PreferencePositionCallback) {
+ val pos = adapter.getPreferenceAdapterPosition(prefKey)
+ listView.findViewHolderForAdapterPosition(pos)?.let {
+ animatePreferenceHighlight(it.itemView)
+ }
+ }
+ }
+ }
+ }
+
override fun onDestroyView(view: View) {
super.onDestroyView(view)
untilDestroySubscriptions.unsubscribe()
@@ -58,6 +81,17 @@ abstract class SettingsController : PreferenceController() {
return ContextThemeWrapper(activity, tv.resourceId)
}
+ private fun animatePreferenceHighlight(view: View) {
+ val duration = 500L
+ val repeat = 2
+
+ val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), Color.TRANSPARENT, Color.WHITE)
+ colorAnimation.duration = duration
+ colorAnimation.repeatCount = repeat
+ colorAnimation.addUpdateListener { animator -> view.setBackgroundColor(animator.animatedValue as Int) }
+ colorAnimation.reverse()
+ }
+
open fun getTitle(): String? {
return preferenceScreen?.title?.toString()
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt
index a2a1ae265..9da5103ed 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt
@@ -94,12 +94,21 @@ object SettingsSearchHelper {
val summary = if (pref.summary != null) pref.summary.toString() else ""
val breadcrumbsStr = breadcrumbs + " > ${pref.title}"
- prefSearchResultList.add(SettingsSearchResult(title, summary, breadcrumbsStr, ctrl))
+ prefSearchResultList.add(
+ SettingsSearchResult(
+ key = pref.key,
+ title = title,
+ summary = summary,
+ breadcrumb = breadcrumbsStr,
+ searchController = ctrl
+ )
+ )
}
}
}
data class SettingsSearchResult(
+ val key: String?,
val title: String,
val summary: String,
val breadcrumb: String,
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt
index 11ab80819..7313fc9fe 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt
@@ -17,9 +17,11 @@ class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
init {
title_wrapper.setOnClickListener {
adapter.getItem(bindingAdapterPosition)?.let {
- val ctrl = it.settingsSearchResult.searchController
- // needs to be a new instance to avoid this error https://github.com/bluelinelabs/Conductor/issues/446
- adapter.titleClickListener.onTitleClick(ctrl::class.createInstance())
+ val ctrl = it.settingsSearchResult.searchController::class.createInstance()
+ ctrl.preferenceKey = it.settingsSearchResult.key
+
+ // must pass a new Controller instance to avoid this error https://github.com/bluelinelabs/Conductor/issues/446
+ adapter.titleClickListener.onTitleClick(ctrl)
}
}
}
From 50c7b32b00f3c73c62152ea5bc1e4f4543018819 Mon Sep 17 00:00:00 2001
From: lmj0011 <9396189+lmj0011@users.noreply.github.com>
Date: Fri, 28 Aug 2020 20:47:18 -0500
Subject: [PATCH 2/2] - Ensure all Preferences have a key set or else the
highlighting effect will have no effect on it. - remove
ExtensionFilterController and SourceFilterController from
settingControllersList in SettingsSearchHelper, since those are related to
Extensions and not Settings
---
.../data/preference/PreferenceKeys.kt | 42 +++++++++++++++++++
.../tachiyomi/ui/more/AboutController.kt | 13 ++++++
.../ui/setting/SettingsAdvancedController.kt | 7 +++-
.../ui/setting/SettingsBackupController.kt | 2 +
.../ui/setting/SettingsGeneralController.kt | 1 +
.../ui/setting/SettingsLibraryController.kt | 2 +
.../settingssearch/SettingsSearchHelper.kt | 4 --
app/src/main/res/values/strings.xml | 1 +
8 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt
index 2c7f66dcf..410df4b2c 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt
@@ -165,6 +165,48 @@ object PreferenceKeys {
const val enableDoh = "enable_doh"
+ const val disableBatteryOptimization = "pref_disable_battery_optimization"
+
+ const val clearDatabase = "pref_clear_database"
+
+ const val clearCookies = "pref_clear_cookies"
+
+ const val refreshLibraryCovers = "pref_refresh_library_covers"
+
+ const val refreshLibraryTracking = "pref_refresh_library_tracking"
+
+ const val createBackup = "pref_create_backup"
+
+ const val restoreBackup = "pref_restore_backup"
+
+ const val manageNotifications = "pref_manage_notifications"
+
+ const val libraryColumns = "pref_library_columns"
+
+ const val actionEditCategories = "pref_action_edit_categories"
+
+ const val parentalControlsInfo = "pref_parental_controls_info"
+
+ const val aboutVersion = "pref_about_version"
+
+ const val aboutBuildTime = "pref_about_build_time"
+
+ const val aboutCheckForUpdates = "pref_about_check_for_updates"
+
+ const val aboutWhatsNew = "pref_about_whats_new"
+
+ const val aboutNotices = "pref_about_notices"
+
+ const val aboutWebsite = "pref_about_website"
+
+ const val aboutDiscord = "pref_about_discord"
+
+ const val aboutGitHub = "pref_about_github"
+
+ const val aboutLabelExtensions = "pref_about_label_extensions"
+
+ const val aboutLicenses = "pref_about_licenses"
+
fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"
fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId"
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt
index 7ee57ce56..2c3fb84ad 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt
@@ -10,6 +10,7 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.mikepenz.aboutlibraries.LibsBuilder
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R
+import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.updater.UpdateChecker
import eu.kanade.tachiyomi.data.updater.UpdateResult
import eu.kanade.tachiyomi.data.updater.UpdaterService
@@ -45,6 +46,7 @@ class AboutController : SettingsController() {
titleRes = R.string.pref_category_about
preference {
+ key = Keys.aboutVersion
titleRes = R.string.version
summary = if (BuildConfig.DEBUG) {
"Preview r${BuildConfig.COMMIT_COUNT} (${BuildConfig.COMMIT_SHA})"
@@ -55,17 +57,20 @@ class AboutController : SettingsController() {
onClick { copyDebugInfo() }
}
preference {
+ key = Keys.aboutBuildTime
titleRes = R.string.build_time
summary = getFormattedBuildTime()
}
if (isUpdaterEnabled) {
preference {
+ key = Keys.aboutCheckForUpdates
titleRes = R.string.check_for_updates
onClick { checkVersion() }
}
}
preference {
+ key = Keys.aboutWhatsNew
titleRes = R.string.whats_new
onClick {
@@ -81,6 +86,7 @@ class AboutController : SettingsController() {
}
if (BuildConfig.DEBUG) {
preference {
+ key = Keys.aboutNotices
titleRes = R.string.notices
onClick {
@@ -91,7 +97,10 @@ class AboutController : SettingsController() {
}
preferenceCategory {
+ titleRes = R.string.about_resources
+
preference {
+ key = Keys.aboutWebsite
titleRes = R.string.website
val url = "https://tachiyomi.org"
summary = url
@@ -101,6 +110,7 @@ class AboutController : SettingsController() {
}
}
preference {
+ key = Keys.aboutDiscord
title = "Discord"
val url = "https://discord.gg/tachiyomi"
summary = url
@@ -110,6 +120,7 @@ class AboutController : SettingsController() {
}
}
preference {
+ key = Keys.aboutGitHub
title = "GitHub"
val url = "https://github.com/inorichi/tachiyomi"
summary = url
@@ -119,6 +130,7 @@ class AboutController : SettingsController() {
}
}
preference {
+ key = Keys.aboutLabelExtensions
titleRes = R.string.label_extensions
val url = "https://github.com/inorichi/tachiyomi-extensions"
summary = url
@@ -128,6 +140,7 @@ class AboutController : SettingsController() {
}
}
preference {
+ key = Keys.aboutLicenses
titleRes = R.string.licenses
onClick {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
index 7ac4b8532..1b06065fc 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
@@ -33,7 +33,6 @@ import rx.schedulers.Schedulers
import uy.kohesive.injekt.injectLazy
class SettingsAdvancedController : SettingsController() {
-
private val network: NetworkHelper by injectLazy()
private val chapterCache: ChapterCache by injectLazy()
@@ -43,7 +42,6 @@ class SettingsAdvancedController : SettingsController() {
@SuppressLint("BatteryLife")
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.pref_category_advanced
-
switchPreference {
key = "acra.enable"
titleRes = R.string.pref_enable_acra
@@ -53,6 +51,7 @@ class SettingsAdvancedController : SettingsController() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
preference {
+ key = Keys.disableBatteryOptimization
titleRes = R.string.pref_disable_battery_optimization
summaryRes = R.string.pref_disable_battery_optimization_summary
@@ -86,6 +85,7 @@ class SettingsAdvancedController : SettingsController() {
onClick { clearChapterCache() }
}
preference {
+ key = Keys.clearDatabase
titleRes = R.string.pref_clear_database
summaryRes = R.string.pref_clear_database_summary
@@ -101,6 +101,7 @@ class SettingsAdvancedController : SettingsController() {
titleRes = R.string.label_network
preference {
+ key = Keys.clearCookies
titleRes = R.string.pref_clear_cookies
onClick {
@@ -120,11 +121,13 @@ class SettingsAdvancedController : SettingsController() {
titleRes = R.string.label_library
preference {
+ key = Keys.refreshLibraryCovers
titleRes = R.string.pref_refresh_library_covers
onClick { LibraryUpdateService.start(context, target = Target.COVERS) }
}
preference {
+ key = Keys.refreshLibraryTracking
titleRes = R.string.pref_refresh_library_tracking
summaryRes = R.string.pref_refresh_library_tracking_summary
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt
index c42d21dfe..d9ca82cb6 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt
@@ -53,6 +53,7 @@ class SettingsBackupController : SettingsController() {
titleRes = R.string.backup
preference {
+ key = Keys.createBackup
titleRes = R.string.pref_create_backup
summaryRes = R.string.pref_create_backup_summ
@@ -67,6 +68,7 @@ class SettingsBackupController : SettingsController() {
}
}
preference {
+ key = Keys.restoreBackup
titleRes = R.string.pref_restore_backup
summaryRes = R.string.pref_restore_backup_summ
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt
index e7feda39c..fbe106e2c 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt
@@ -47,6 +47,7 @@ class SettingsGeneralController : SettingsController() {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
preference {
+ key = Keys.manageNotifications
titleRes = R.string.pref_manage_notifications
onClick {
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt
index 477d880e7..f4dd9869c 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt
@@ -50,6 +50,7 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_category_display
preference {
+ key = Keys.libraryColumns
titleRes = R.string.pref_library_columns
onClick {
LibraryColumnsDialog().showDialog(router)
@@ -83,6 +84,7 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_category_library_categories
preference {
+ key = Keys.actionEditCategories
titleRes = R.string.action_edit_categories
val catCount = dbCategories.size
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt
index 9da5103ed..527e1dc78 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt
@@ -6,8 +6,6 @@ import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceManager
-import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterController
-import eu.kanade.tachiyomi.ui.browse.source.SourceFilterController
import eu.kanade.tachiyomi.ui.more.AboutController
import eu.kanade.tachiyomi.ui.setting.SettingsAdvancedController
import eu.kanade.tachiyomi.ui.setting.SettingsBackupController
@@ -41,8 +39,6 @@ object SettingsSearchHelper {
SettingsReaderController::class,
SettingsSecurityController::class,
SettingsTrackingController::class,
- ExtensionFilterController::class,
- SourceFilterController::class,
AboutController::class
)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f1d38f72b..94172f369 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -411,6 +411,7 @@
Open source licenses
Check for updates
Updated to v%1$s
+ Resources
Send crash reports