Skip to content

Commit

Permalink
Fix search preference with new carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed Oct 24, 2024
1 parent 09f8262 commit 4e3b53d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,11 @@ abstract class BaseFragment : Fragment() {
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
}

fun onSearchResultClicked(result: SearchPreferenceResult) {
open fun onSearchResultClicked(result: SearchPreferenceResult) {
for (searchableFragment in searchableFragments) {
if (searchableFragment.xml == result.resourceFile) {
replaceFragment(parentFragmentManager, searchableFragment.fragment)
var finalFragment: ControlledPreferenceFragmentCompat? = null
if (searchableFragment.fragment is LockscreenClockParent) {
finalFragment = LockscreenClockParent.getPreferenceFragment()
}
SearchPreferenceResult.highlight(finalFragment, result.key);
SearchPreferenceResult.highlight(parentFragmentManager as ControlledPreferenceFragmentCompat, result.key);
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ abstract class ControlledPreferenceFragmentCompat : PreferenceFragmentCompat() {
var resultFragment: ControlledPreferenceFragmentCompat? = null
if (fragment is LockscreenClockParent) {
resultFragment = LockscreenClockParent.getPreferenceFragment()
fragment.scrollToPreference()
}
SearchPreferenceResult.highlight(resultFragment, result.key);
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import com.drdisagree.iconify.R
import com.drdisagree.iconify.common.Preferences.LSCLOCK_STYLE
import com.drdisagree.iconify.common.Preferences.LSCLOCK_SWITCH
import com.drdisagree.iconify.common.Resources.LOCKSCREEN_CLOCK_LAYOUT
import com.drdisagree.iconify.common.Resources.searchableFragments
import com.drdisagree.iconify.config.RPrefs.getBoolean
import com.drdisagree.iconify.config.RPrefs.getInt
import com.drdisagree.iconify.config.RPrefs.putBoolean
import com.drdisagree.iconify.config.RPrefs.putInt
import com.drdisagree.iconify.databinding.FragmentXposedLockscreenClockBinding
import com.drdisagree.iconify.ui.activities.MainActivity.Companion.replaceFragment
import com.drdisagree.iconify.ui.base.BaseFragment
import com.drdisagree.iconify.ui.base.ControlledPreferenceFragmentCompat
import com.drdisagree.iconify.ui.models.ClockCarouselItemViewModel
import com.drdisagree.iconify.ui.preferences.preferencesearch.SearchPreferenceResult
import com.drdisagree.iconify.ui.utils.ViewHelper.setHeader
import com.drdisagree.iconify.ui.views.ClockCarouselView
import com.drdisagree.iconify.utils.SystemUtils
Expand Down Expand Up @@ -147,6 +150,17 @@ class LockscreenClockParent : BaseFragment() {
}, 50)
}

override fun onSearchResultClicked(result: SearchPreferenceResult) {
for (searchableFragment in searchableFragments) {
if (searchableFragment.xml == result.resourceFile) {
replaceFragment(parentFragmentManager, searchableFragment.fragment)
scrollToPreference()
SearchPreferenceResult.highlight(lockscreenClockFragment, result.key);
break
}
}
}

private fun loadAndSetWallpaper() {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
val bitmap = loadWallpaper(requireContext(), isLockscreen = true).await()
Expand All @@ -172,6 +186,12 @@ class LockscreenClockParent : BaseFragment() {
requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}

fun scrollToPreference() {
Handler(Looper.getMainLooper()).postDelayed({
binding?.scrollView!!.smoothScrollTo(0, binding.fragmentContainer.top)
}, 180)
}

companion object {

private val lockscreenClockFragment = LockscreenClock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context=".ui.fragments.xposed.LockscreenClockParent">

<com.drdisagree.iconify.ui.widgets.HorizontalTouchMovementAwareNestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
Expand Down

0 comments on commit 4e3b53d

Please sign in to comment.