Skip to content

Commit

Permalink
Fix preference search crash
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <[email protected]>
  • Loading branch information
Mahmud0808 committed Nov 5, 2024
1 parent f150190 commit f1bb01e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ abstract class ControlledPreferenceFragmentCompat : PreferenceFragmentCompat() {
if (fragment is LockscreenClockParent) {
resultFragment = LockscreenClockParent.getPreferenceFragment()
fragment.scrollToPreference()
} else {
resultFragment = fragment as ControlledPreferenceFragmentCompat
}
SearchPreferenceResult.highlight(resultFragment, result.key);
SearchPreferenceResult.highlight(resultFragment, result.key)
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
Expand All @@ -32,10 +30,15 @@ public class SearchPreferenceResult {
}

public static void highlight(final PreferenceFragmentCompat prefsFragment, final String key) {
new Handler(Looper.getMainLooper()).post(() -> doHighlight(prefsFragment, key));
new Handler(Looper.getMainLooper()).postDelayed(() -> doHighlight(prefsFragment, key), 100);
}

private static void doHighlight(final PreferenceFragmentCompat prefsFragment, final String key) {
if (prefsFragment == null) {
Log.w("doHighlight", "Preference fragment is null.");
return;
}

final Preference prefResult = prefsFragment.findPreference(key);

if (prefResult == null) {
Expand Down Expand Up @@ -154,7 +157,7 @@ public String getScreen() {
*/
@SuppressWarnings("unused")
public void highlight(final PreferenceFragmentCompat prefsFragment) {
new Handler(Looper.getMainLooper()).post(() -> doHighlight(prefsFragment, getKey()));
new Handler(Looper.getMainLooper()).postDelayed(() -> doHighlight(prefsFragment, getKey()), 100);
}

/**
Expand Down

0 comments on commit f1bb01e

Please sign in to comment.