mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-18 04:37:30 +00:00
save resource entry names in preferences instead of ids
This commit is contained in:
parent
e26a25e72f
commit
25b2b504cb
@ -405,11 +405,14 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
||||
}
|
||||
final List<Integer> mainNavList = getMainNavList(main_nav_ids);
|
||||
if (setDefaultFromSettings) {
|
||||
final String defaultTabIdString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
||||
final String defaultTabResNameString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
||||
try {
|
||||
final int defaultNavId = TextUtils.isEmpty(defaultTabIdString)
|
||||
? R.navigation.profile_nav_graph
|
||||
: Integer.parseInt(defaultTabIdString);
|
||||
int navId = 0;
|
||||
if (!TextUtils.isEmpty(defaultTabResNameString)) {
|
||||
navId = getResources().getIdentifier(defaultTabResNameString, "navigation", getPackageName());
|
||||
}
|
||||
final int defaultNavId = navId <= 0 ? R.navigation.profile_nav_graph
|
||||
: navId;
|
||||
final int index = mainNavList.indexOf(defaultNavId);
|
||||
if (index >= 0) firstFragmentGraphIndex = index;
|
||||
setBottomNavSelectedItem(defaultNavId);
|
||||
|
@ -128,7 +128,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
||||
for (int i = 0; i < length; i++) {
|
||||
final int resourceId = mainNavIds.getResourceId(i, -1);
|
||||
if (resourceId < 0) continue;
|
||||
values[i] = String.valueOf(resourceId);
|
||||
values[i] = getResources().getResourceEntryName(resourceId);
|
||||
}
|
||||
mainNavIds.recycle();
|
||||
preference.setKey(Constants.DEFAULT_TAB);
|
||||
|
@ -51,7 +51,7 @@ public class ThemePreferencesFragment extends BasePreferencesFragment {
|
||||
for (int i = 0; i < length; i++) {
|
||||
final int resourceId = lightThemeValues.getResourceId(i, -1);
|
||||
if (resourceId < 0) continue;
|
||||
values[i] = String.valueOf(resourceId);
|
||||
values[i] = getResources().getResourceEntryName(resourceId);
|
||||
}
|
||||
lightThemeValues.recycle();
|
||||
preference.setKey(Constants.PREF_LIGHT_THEME);
|
||||
@ -76,7 +76,7 @@ public class ThemePreferencesFragment extends BasePreferencesFragment {
|
||||
for (int i = 0; i < length; i++) {
|
||||
final int resourceId = darkThemeValues.getResourceId(i, -1);
|
||||
if (resourceId < 0) continue;
|
||||
values[i] = String.valueOf(resourceId);
|
||||
values[i] = getResources().getResourceEntryName(resourceId);
|
||||
}
|
||||
darkThemeValues.recycle();
|
||||
preference.setKey(Constants.PREF_DARK_THEME);
|
||||
|
@ -3,7 +3,6 @@ package awais.instagrabber.utils;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
@ -24,14 +23,9 @@ public final class ThemeUtils {
|
||||
themeCode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
|
||||
}
|
||||
final boolean isNight = isNight(context, themeCode);
|
||||
int themeResId = 0;
|
||||
try {
|
||||
themeResId = Integer.parseInt(isNight ? settingsHelper.getString(Constants.PREF_DARK_THEME)
|
||||
: settingsHelper.getString(Constants.PREF_LIGHT_THEME));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "changeTheme: ", e);
|
||||
}
|
||||
|
||||
final String themeResName = isNight ? settingsHelper.getString(Constants.PREF_DARK_THEME)
|
||||
: settingsHelper.getString(Constants.PREF_LIGHT_THEME);
|
||||
final int themeResId = context.getResources().getIdentifier(themeResName, "style", context.getPackageName());
|
||||
final int finalThemeResId;
|
||||
if (themeResId <= 0) {
|
||||
// Nothing set in settings
|
||||
|
Loading…
Reference in New Issue
Block a user