- implement prefernce highlighting after settings search
This commit is contained in:
parent
437a34b5dc
commit
78072ad285
3 changed files with 49 additions and 4 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue