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);
|
final List<Integer> mainNavList = getMainNavList(main_nav_ids);
|
||||||
if (setDefaultFromSettings) {
|
if (setDefaultFromSettings) {
|
||||||
final String defaultTabIdString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
final String defaultTabResNameString = settingsHelper.getString(Constants.DEFAULT_TAB);
|
||||||
try {
|
try {
|
||||||
final int defaultNavId = TextUtils.isEmpty(defaultTabIdString)
|
int navId = 0;
|
||||||
? R.navigation.profile_nav_graph
|
if (!TextUtils.isEmpty(defaultTabResNameString)) {
|
||||||
: Integer.parseInt(defaultTabIdString);
|
navId = getResources().getIdentifier(defaultTabResNameString, "navigation", getPackageName());
|
||||||
|
}
|
||||||
|
final int defaultNavId = navId <= 0 ? R.navigation.profile_nav_graph
|
||||||
|
: navId;
|
||||||
final int index = mainNavList.indexOf(defaultNavId);
|
final int index = mainNavList.indexOf(defaultNavId);
|
||||||
if (index >= 0) firstFragmentGraphIndex = index;
|
if (index >= 0) firstFragmentGraphIndex = index;
|
||||||
setBottomNavSelectedItem(defaultNavId);
|
setBottomNavSelectedItem(defaultNavId);
|
||||||
|
@ -128,7 +128,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
|||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
final int resourceId = mainNavIds.getResourceId(i, -1);
|
final int resourceId = mainNavIds.getResourceId(i, -1);
|
||||||
if (resourceId < 0) continue;
|
if (resourceId < 0) continue;
|
||||||
values[i] = String.valueOf(resourceId);
|
values[i] = getResources().getResourceEntryName(resourceId);
|
||||||
}
|
}
|
||||||
mainNavIds.recycle();
|
mainNavIds.recycle();
|
||||||
preference.setKey(Constants.DEFAULT_TAB);
|
preference.setKey(Constants.DEFAULT_TAB);
|
||||||
|
@ -51,7 +51,7 @@ public class ThemePreferencesFragment extends BasePreferencesFragment {
|
|||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
final int resourceId = lightThemeValues.getResourceId(i, -1);
|
final int resourceId = lightThemeValues.getResourceId(i, -1);
|
||||||
if (resourceId < 0) continue;
|
if (resourceId < 0) continue;
|
||||||
values[i] = String.valueOf(resourceId);
|
values[i] = getResources().getResourceEntryName(resourceId);
|
||||||
}
|
}
|
||||||
lightThemeValues.recycle();
|
lightThemeValues.recycle();
|
||||||
preference.setKey(Constants.PREF_LIGHT_THEME);
|
preference.setKey(Constants.PREF_LIGHT_THEME);
|
||||||
@ -76,7 +76,7 @@ public class ThemePreferencesFragment extends BasePreferencesFragment {
|
|||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
final int resourceId = darkThemeValues.getResourceId(i, -1);
|
final int resourceId = darkThemeValues.getResourceId(i, -1);
|
||||||
if (resourceId < 0) continue;
|
if (resourceId < 0) continue;
|
||||||
values[i] = String.valueOf(resourceId);
|
values[i] = getResources().getResourceEntryName(resourceId);
|
||||||
}
|
}
|
||||||
darkThemeValues.recycle();
|
darkThemeValues.recycle();
|
||||||
preference.setKey(Constants.PREF_DARK_THEME);
|
preference.setKey(Constants.PREF_DARK_THEME);
|
||||||
|
@ -3,7 +3,6 @@ package awais.instagrabber.utils;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
@ -24,14 +23,9 @@ public final class ThemeUtils {
|
|||||||
themeCode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
|
themeCode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
|
||||||
}
|
}
|
||||||
final boolean isNight = isNight(context, themeCode);
|
final boolean isNight = isNight(context, themeCode);
|
||||||
int themeResId = 0;
|
final String themeResName = isNight ? settingsHelper.getString(Constants.PREF_DARK_THEME)
|
||||||
try {
|
: settingsHelper.getString(Constants.PREF_LIGHT_THEME);
|
||||||
themeResId = Integer.parseInt(isNight ? settingsHelper.getString(Constants.PREF_DARK_THEME)
|
final int themeResId = context.getResources().getIdentifier(themeResName, "style", context.getPackageName());
|
||||||
: settingsHelper.getString(Constants.PREF_LIGHT_THEME));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Log.e(TAG, "changeTheme: ", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
final int finalThemeResId;
|
final int finalThemeResId;
|
||||||
if (themeResId <= 0) {
|
if (themeResId <= 0) {
|
||||||
// Nothing set in settings
|
// Nothing set in settings
|
||||||
|
Loading…
Reference in New Issue
Block a user