aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-11-22 12:35:14 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-11-22 12:35:14 +0000
commit1b39925cf8f050597e8c98266b724d2cb0334223 (patch)
tree00545e5b1bf3b516528fd65f65ea21fbb160f64d /app
parent841fec87dc81eb8559beaf605f0ef06cf0ca90c5 (diff)
downloadinfinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.tar
infinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.tar.gz
infinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.tar.bz2
infinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.tar.lz
infinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.tar.xz
infinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.tar.zst
infinity-for-reddit-1b39925cf8f050597e8c98266b724d2cb0334223.zip
Version 5.1.1. Fix anonymous subreddits and multireddits do not show in MainActivity TabLayout. Fix changing tab names not working in anonymous mode.
Diffstat (limited to '')
-rw-r--r--app/build.gradle4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java91
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java16
3 files changed, 45 insertions, 66 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 86e49619..63dec2b3 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21
targetSdkVersion 30
- versionCode 84
- versionName "5.1.0"
+ versionCode 85
+ versionName "5.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
index 1b509410..990fbe83 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -38,7 +38,6 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
-import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
@@ -852,51 +851,37 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
- if (mAccessToken == null) {
- switch (position) {
- case 0:
- tab.setText(R.string.home);
- break;
- case 1:
- tab.setText(R.string.popular);
- break;
- case 2:
- tab.setText(R.string.all);
- break;
- }
- } else {
- switch (position) {
- case 0:
- tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)));
- break;
- case 1:
- tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)));
- break;
- case 2:
- tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
- break;
- }
- if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits ||
- mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits)
- && sectionsPagerAdapter != null) {
- if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) {
- tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName());
- } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) {
- tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount
- - sectionsPagerAdapter.favoriteMultiReddits.size()).getName());
- } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
- - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) {
- tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount
- - sectionsPagerAdapter.favoriteMultiReddits.size()
- - sectionsPagerAdapter.multiReddits.size()).getName());
- } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
+ switch (position) {
+ case 0:
+ tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)));
+ break;
+ case 1:
+ tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)));
+ break;
+ case 2:
+ tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
+ break;
+ }
+ if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits ||
+ mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits)
+ && sectionsPagerAdapter != null) {
+ if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) {
+ tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName());
+ } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) {
+ tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount
+ - sectionsPagerAdapter.favoriteMultiReddits.size()).getName());
+ } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
+ - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) {
+ tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount
+ - sectionsPagerAdapter.favoriteMultiReddits.size()
+ - sectionsPagerAdapter.multiReddits.size()).getName());
+ } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
+ - sectionsPagerAdapter.multiReddits.size()
+ - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) {
+ tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount
+ - sectionsPagerAdapter.favoriteMultiReddits.size()
- sectionsPagerAdapter.multiReddits.size()
- - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) {
- tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount
- - sectionsPagerAdapter.favoriteMultiReddits.size()
- - sectionsPagerAdapter.multiReddits.size()
- - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName());
- }
+ - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName());
}
}
}).attach();
@@ -922,7 +907,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
loadSubscriptions();
multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(),
- mRedditDataRoomDatabase, mAccountName))
+ mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName))
.get(MultiRedditViewModel.class);
multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> {
@@ -931,17 +916,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
});
- multiRedditViewModel.getAllMultiReddits().observe(this, new Observer<List<MultiReddit>>() {
- @Override
- public void onChanged(List<MultiReddit> multiReddits) {
- if (mShowMultiReddits && sectionsPagerAdapter != null) {
- sectionsPagerAdapter.setMultiReddits(multiReddits);
- }
+ multiRedditViewModel.getAllMultiReddits().observe(this, multiReddits -> {
+ if (mShowMultiReddits && sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.setMultiReddits(multiReddits);
}
});
subscribedSubredditViewModel = new ViewModelProvider(this,
- new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName))
+ new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName))
.get(SubscribedSubredditViewModel.class);
subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this,
subscribedSubredditData -> {
@@ -1693,9 +1675,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
public int getItemCount() {
- if (mAccessToken == null) {
- return 3;
- }
return tabCount + favoriteMultiReddits.size() + multiReddits.size() +
favoriteSubscribedSubreddits.size() + subscribedSubreddits.size();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java
index dddbda85..44f45eef 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java
@@ -492,26 +492,26 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab3AddImageView.setOnClickListener(view -> selectName(2));
- showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false));
- showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply());
+ showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false));
+ showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply());
showMultiredditsLinearLayout.setOnClickListener(view -> {
showMultiredditsSwitchMaterial.performClick();
});
- showFavoriteMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false));
- showFavoriteMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, b).apply());
+ showFavoriteMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false));
+ showFavoriteMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, b).apply());
showFavoriteMultiredditsLinearLayout.setOnClickListener(view -> {
showFavoriteMultiredditsSwitchMaterial.performClick();
});
- showSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false));
- showSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, b).apply());
+ showSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false));
+ showSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, b).apply());
showSubscribedSubredditsLinearLayout.setOnClickListener(view -> {
showSubscribedSubredditsSwitchMaterial.performClick();
});
- showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false));
- showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply());
+ showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false));
+ showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply());
showFavoriteSubscribedSubredditsLinearLayout.setOnClickListener(view -> {
showFavoriteSubscribedSubredditsSwitchMaterial.performClick();
});