Fix defaults for certain preferences not being respected
@@ -17,6 +17,7 @@ package com.farmerbb.taskbar.fragment;
import android.annotation.SuppressLint;
import android.app.FragmentTransaction;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -25,10 +26,13 @@ import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
+import androidx.annotation.XmlRes;
+
import com.farmerbb.taskbar.BuildConfig;
import com.farmerbb.taskbar.R;
import com.farmerbb.taskbar.activity.ClearDataActivity;
@@ -206,4 +210,19 @@ public abstract class SettingsFragment extends PreferenceFragment implements Pre
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
+
+ @SuppressWarnings("JavaReflectionMemberAccess")
+ @Override
+ public void addPreferencesFromResource(@XmlRes int preferencesResId) {
+ try {
+ Context context = U.wrapContext(getActivity().getApplicationContext());
+ PreferenceScreen screen = (PreferenceScreen) Class.forName("android.preference.PreferenceManager")
+ .getMethod("inflateFromResource", Context.class, int.class, PreferenceScreen.class)
+ .invoke(getPreferenceManager(), context, preferencesResId, getPreferenceScreen());
+
+ setPreferenceScreen(screen);
+ } catch (Exception e) {
+ super.addPreferencesFromResource(preferencesResId);
+ }
+ }
}
\ No newline at end of file
