Fix issue where preferences used the Display name instead of the full account name

Closes #275
This commit is contained in:
Bazsalanszky 2024-08-09 10:37:23 +02:00
parent 336223cc36
commit c1c8d99de2

View File

@ -865,12 +865,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
} else if (stringId == R.string.enable_nsfw) {
if (sectionsPagerAdapter != null) {
mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, true).apply();
mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.NSFW_BASE, true).apply();
sectionsPagerAdapter.changeNSFW(true);
}
} else if (stringId == R.string.disable_nsfw) {
if (sectionsPagerAdapter != null) {
mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false).apply();
mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.NSFW_BASE, false).apply();
sectionsPagerAdapter.changeNSFW(false);
}
} else if (stringId == R.string.settings) {
@ -928,17 +928,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
navDrawerRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
navDrawerRecyclerView.setAdapter(adapter.getConcatAdapter());
int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3);
mShowFavoriteMultiReddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false);
mShowMultiReddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false);
mShowFavoriteSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false);
mShowSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false);
int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3);
mShowFavoriteMultiReddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false);
mShowMultiReddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false);
mShowFavoriteSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false);
mShowSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false);
sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteMultiReddits,
mShowMultiReddits, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
if (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) {
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
} else {
@ -947,13 +947,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {
case 0:
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.subscribed_feed)));
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.subscribed_feed)));
break;
case 1:
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.local)));
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.local)));
break;
case 2:
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
break;
}
if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits ||
@ -1001,7 +1001,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
loadSubscriptions();
multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(),
mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName))
mRedditDataRoomDatabase, mAccountQualifiedName == null ? "-" : mAccountQualifiedName))
.get(MultiRedditViewModel.class);
multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> {
@ -1594,7 +1594,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
return false;
});
boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false);
boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.NSFW_BASE, false);
thingEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@ -1706,7 +1706,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private void randomThing() {
RandomBottomSheetFragment randomBottomSheetFragment = new RandomBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false));
bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.NSFW_BASE, false));
randomBottomSheetFragment.setArguments(bundle);
randomBottomSheetFragment.show(getSupportFragmentManager(), randomBottomSheetFragment.getTag());
}
@ -1767,8 +1767,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
public Fragment createFragment(int position) {
if (position == 0) {
int postType = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME);
String name = mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, "");
int postType = mMainActivityTabsSharedPreferences.getInt((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME);
String name = mMainActivityTabsSharedPreferences.getString((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, "");
return generatePostFragment(postType, name);
} else {
if (showFavoriteMultiReddits) {
@ -1810,11 +1810,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
int postType;
String name;
if (position == 1) {
postType = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR);
name = mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, "");
postType = mMainActivityTabsSharedPreferences.getInt((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR);
name = mMainActivityTabsSharedPreferences.getString((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, "");
} else {
postType = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL);
name = mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, "");
postType = mMainActivityTabsSharedPreferences.getInt((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL);
name = mMainActivityTabsSharedPreferences.getString((mAccountQualifiedName == null ? "" : mAccountQualifiedName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, "");
}
return generatePostFragment(postType, name);
}