2828
2929import rikka .material .preference .MaterialSwitchPreference ;
3030
31- public abstract class BasePreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences .OnSharedPreferenceChangeListener {
31+ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat
32+ implements SharedPreferences .OnSharedPreferenceChangeListener {
3233 protected SharedPreferences mPrefs ;
3334
3435 @ Override
@@ -49,7 +50,8 @@ public void handleOnBackPressed() {
4950
5051 @ NonNull
5152 @ Override
52- public View onCreateView (@ NonNull LayoutInflater inflater , @ Nullable ViewGroup container , @ Nullable Bundle savedInstanceState ) {
53+ public View onCreateView (@ NonNull LayoutInflater inflater , @ Nullable ViewGroup container ,
54+ @ Nullable Bundle savedInstanceState ) {
5355 chanceStates (null );
5456 monitorPreference ();
5557 return super .onCreateView (inflater , container , savedInstanceState );
@@ -93,7 +95,10 @@ private void monitorPreference() {
9395
9496 private boolean checkStoragePermission (Object newValue ) {
9597 if (newValue instanceof Boolean && (Boolean ) newValue ) {
96- if ((Build .VERSION .SDK_INT >= Build .VERSION_CODES .R && !Environment .isExternalStorageManager ()) || (Build .VERSION .SDK_INT < Build .VERSION_CODES .R && ContextCompat .checkSelfPermission (requireContext (), Manifest .permission .WRITE_EXTERNAL_STORAGE ) != PackageManager .PERMISSION_GRANTED )) {
98+ if ((Build .VERSION .SDK_INT >= Build .VERSION_CODES .R && !Environment .isExternalStorageManager ())
99+ || (Build .VERSION .SDK_INT < Build .VERSION_CODES .R
100+ && ContextCompat .checkSelfPermission (requireContext (),
101+ Manifest .permission .WRITE_EXTERNAL_STORAGE ) != PackageManager .PERMISSION_GRANTED )) {
97102 App .showRequestStoragePermission (requireActivity ());
98103 return false ;
99104 }
@@ -159,14 +164,12 @@ private void chanceStates(String key) {
159164 setPreferenceState ("showonlinetext" , !freezelastseen );
160165 setPreferenceState ("dotonline" , !freezelastseen );
161166
162-
163167 var separategroups = mPrefs .getBoolean ("separategroups" , false );
164168 setPreferenceState ("filtergroups" , !separategroups );
165169
166170 var filtergroups = mPrefs .getBoolean ("filtergroups" , false );
167171 setPreferenceState ("separategroups" , !filtergroups );
168172
169-
170173 var callBlockContacts = findPreference ("call_block_contacts" );
171174 var callWhiteContacts = findPreference ("call_white_contacts" );
172175 if (callBlockContacts != null && callWhiteContacts != null ) {
@@ -190,58 +193,62 @@ private void chanceStates(String key) {
190193 }
191194
192195 public void setDisplayHomeAsUpEnabled (boolean enabled ) {
193- if (getActivity () == null ) return ;
196+ if (getActivity () == null )
197+ return ;
194198 var actionBar = ((AppCompatActivity ) getActivity ()).getSupportActionBar ();
195199 if (actionBar != null ) {
196200 actionBar .setDisplayHomeAsUpEnabled (enabled );
197201 }
198202 }
199-
203+
200204 /**
201205 * Scroll to a specific preference by key.
202206 * This is called when navigating from search results.
203207 */
204208 public void scrollToPreference (String preferenceKey ) {
205- if (preferenceKey == null ) return ;
206-
209+ if (preferenceKey == null )
210+ return ;
211+
207212 // Small delay to ensure preference screen is fully loaded
208213 getView ().postDelayed (() -> {
209214 var preference = findPreference (preferenceKey );
210215 if (preference != null ) {
211216 scrollToPreference (preference );
212-
217+
213218 // Highlight the preference for visibility
214219 highlightPreference (preference );
215220 }
216221 }, 100 );
217222 }
218-
223+
219224 /**
220225 * Highlight a preference with a temporary background color.
221226 */
222227 private void highlightPreference (androidx .preference .Preference preference ) {
223228 // Wait longer to ensure RecyclerView has laid out the views after scrolling
224229 getView ().postDelayed (() -> {
225230 androidx .recyclerview .widget .RecyclerView recyclerView = getListView ();
226- if (recyclerView == null || preference == null || preference .getKey () == null ) return ;
227-
231+ if (recyclerView == null || preference == null || preference .getKey () == null )
232+ return ;
233+
228234 // Find the preference view by iterating through visible items
229235 String targetKey = preference .getKey ();
230236 boolean found = false ;
231-
237+
232238 for (int i = 0 ; i < recyclerView .getChildCount (); i ++) {
233239 android .view .View child = recyclerView .getChildAt (i );
234240 androidx .recyclerview .widget .RecyclerView .ViewHolder holder = recyclerView .getChildViewHolder (child );
235-
241+
236242 if (holder instanceof androidx .preference .PreferenceViewHolder ) {
237243 androidx .preference .PreferenceViewHolder prefHolder = (androidx .preference .PreferenceViewHolder ) holder ;
238-
244+
239245 // Try to match by adapter position
240246 int position = prefHolder .getBindingAdapterPosition ();
241247 if (position != androidx .recyclerview .widget .RecyclerView .NO_POSITION ) {
242248 try {
243249 // Get all preferences recursively
244- androidx .preference .Preference pref = findPreferenceAtPosition (getPreferenceScreen (), position );
250+ androidx .preference .Preference pref = findPreferenceAtPosition (getPreferenceScreen (),
251+ position );
245252 if (pref != null && pref .getKey () != null && pref .getKey ().equals (targetKey )) {
246253 animateHighlight (prefHolder .itemView );
247254 found = true ;
@@ -253,21 +260,22 @@ private void highlightPreference(androidx.preference.Preference preference) {
253260 }
254261 }
255262 }
256-
263+
257264 // If not found, try a second time after a longer delay
258265 if (!found ) {
259266 getView ().postDelayed (() -> tryHighlightAgain (targetKey ), 500 );
260267 }
261268 }, 500 );
262269 }
263-
270+
264271 private void tryHighlightAgain (String targetKey ) {
265272 androidx .recyclerview .widget .RecyclerView recyclerView = getListView ();
266- if (recyclerView == null ) return ;
267-
273+ if (recyclerView == null )
274+ return ;
275+
268276 for (int i = 0 ; i < recyclerView .getChildCount (); i ++) {
269277 android .view .View child = recyclerView .getChildAt (i );
270-
278+
271279 // Simple approach: check all text views in the item for matching preference
272280 if (child instanceof android .view .ViewGroup ) {
273281 android .view .ViewGroup group = (android .view .ViewGroup ) child ;
@@ -286,20 +294,23 @@ private void tryHighlightAgain(String targetKey) {
286294 }
287295 }
288296 }
289-
290- private androidx .preference .Preference findPreferenceAtPosition (androidx .preference .PreferenceGroup group , int targetPosition ) {
291- if (group == null ) return null ;
292-
297+
298+ private androidx .preference .Preference findPreferenceAtPosition (androidx .preference .PreferenceGroup group ,
299+ int targetPosition ) {
300+ if (group == null )
301+ return null ;
302+
293303 int currentPosition = 0 ;
294304 for (int i = 0 ; i < group .getPreferenceCount (); i ++) {
295305 androidx .preference .Preference pref = group .getPreference (i );
296- if (pref == null ) continue ;
297-
306+ if (pref == null )
307+ continue ;
308+
298309 if (currentPosition == targetPosition ) {
299310 return pref ;
300311 }
301312 currentPosition ++;
302-
313+
303314 // Recursively check groups
304315 if (pref instanceof androidx .preference .PreferenceGroup ) {
305316 androidx .preference .PreferenceGroup subGroup = (androidx .preference .PreferenceGroup ) pref ;
@@ -312,7 +323,7 @@ private androidx.preference.Preference findPreferenceAtPosition(androidx.prefere
312323 }
313324 return null ;
314325 }
315-
326+
316327 private int countPreferences (androidx .preference .PreferenceGroup group ) {
317328 int count = 0 ;
318329 for (int i = 0 ; i < group .getPreferenceCount (); i ++) {
@@ -325,32 +336,32 @@ private int countPreferences(androidx.preference.PreferenceGroup group) {
325336 }
326337 return count ;
327338 }
328-
339+
329340 /**
330341 * Animate a highlight effect on the view.
331342 */
332343 private void animateHighlight (android .view .View view ) {
333- if (view == null || getContext () == null ) return ;
334-
344+ if (view == null || getContext () == null )
345+ return ;
346+
335347 // Get primary color using android attribute
336348 android .util .TypedValue typedValue = new android .util .TypedValue ();
337349 view .getContext ().getTheme ().resolveAttribute (android .R .attr .colorPrimary , typedValue , true );
338350 int primaryColor = typedValue .data ;
339-
351+
340352 // Make it 20% opacity (dim)
341353 int highlightColor = android .graphics .Color .argb (
342- 51 , // ~20% of 255
343- android .graphics .Color .red (primaryColor ),
344- android .graphics .Color .green (primaryColor ),
345- android .graphics .Color .blue (primaryColor )
346- );
347-
354+ 51 , // ~20% of 255
355+ android .graphics .Color .red (primaryColor ),
356+ android .graphics .Color .green (primaryColor ),
357+ android .graphics .Color .blue (primaryColor ));
358+
348359 // Save original background
349360 android .graphics .drawable .Drawable originalBackground = view .getBackground ();
350-
361+
351362 // Set highlight background
352363 view .setBackgroundColor (highlightColor );
353-
364+
354365 // Fade out after 1.5 seconds
355366 view .postDelayed (() -> {
356367 if (originalBackground != null ) {
0 commit comments