aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java181
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java9
4 files changed, 184 insertions, 17 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index b3bb499c..845f1b49 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -248,6 +248,12 @@ class AppModule {
}
@Provides
+ @Named("navigation_drawer")
+ SharedPreferences provideNavigationDrawerSharedPreferences() {
+ return mApplication.getSharedPreferences(SharedPreferencesUtils.NAVIGATION_DRAWER_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
+ }
+
+ @Provides
@Singleton
CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences,
@Named("dark_theme") SharedPreferences darkThemeSharedPreferences,
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 ac4308ca..1cf15575 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -198,6 +198,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
+ @Named("navigation_drawer")
+ SharedPreferences mNavigationDrawerSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
@@ -676,7 +679,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fab.setVisibility(View.VISIBLE);
adapter = new NavigationDrawerRecyclerViewAdapter(this, mSharedPreferences,
- mNsfwAndSpoilerSharedPreferences, mCustomThemeWrapper, mAccountName,
+ mNsfwAndSpoilerSharedPreferences, mNavigationDrawerSharedPreferences, mCustomThemeWrapper, mAccountName,
new NavigationDrawerRecyclerViewAdapter.ItemClickListener() {
@Override
public void onMenuClick(int stringId) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
index d6de3458..3780f24d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
@@ -29,9 +29,9 @@ import java.util.concurrent.Executor;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
@@ -55,6 +55,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 5;
private static final int VIEW_TYPE_ACCOUNT = 6;
private static final int CURRENT_MENU_ITEMS = 17;
+ private static final int ACCOUNT_SECTION_ITEMS = 4;
+ private static final int POST_SECTION_ITEMS = 5;
+ private static final int PREFERENCES_SECTION_ITEMS = 3;
private AppCompatActivity appCompatActivity;
private Resources resources;
@@ -69,6 +72,13 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
private ItemClickListener itemClickListener;
private boolean isLoggedIn;
private boolean isInMainPage = true;
+ private boolean collapseAccountSection;
+ private boolean collapsePostSection;
+ private boolean collapsePreferencesSection;
+ private boolean collapseFavoriteSubredditsSection;
+ private boolean collapseSubscribedSubredditsSection;
+ private boolean hideFavoriteSubredditsSection;
+ private boolean hideSubscribedSubredditsSection;
private ArrayList<SubscribedSubredditData> favoriteSubscribedSubreddits;
private ArrayList<SubscribedSubredditData> subscribedSubreddits;
private ArrayList<Account> accounts;
@@ -79,6 +89,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
public NavigationDrawerRecyclerViewAdapter(AppCompatActivity appCompatActivity, SharedPreferences sharedPreferences,
SharedPreferences nsfwAndSpoilerSharedPreferences,
+ SharedPreferences navigationDrawerSharedPreferences,
CustomThemeWrapper customThemeWrapper,
String accountName,
ItemClickListener itemClickListener) {
@@ -90,6 +101,14 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT_IN_THE_NAVIGATION_DRAWER, false);
isLoggedIn = accountName != null;
+ collapseAccountSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_ACCOUNT_SECTION, false);
+ collapsePostSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_POST_SECTION, false);
+ collapsePreferencesSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_PREFERENCES_SECTION, false);
+ collapseFavoriteSubredditsSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_FAVORITE_SUBREDDITS_SECTION, false);
+ collapseSubscribedSubredditsSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_SUBSCRIBED_SUBREDDITS_SECTION, false);
+ hideFavoriteSubredditsSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_FAVORITE_SUBREDDITS_SECTION, false);
+ hideSubscribedSubredditsSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBSCRIBED_SUBREDDITS_SECTIONS, false);
+
this.itemClickListener = itemClickListener;
primaryTextColor = customThemeWrapper.getPrimaryTextColor();
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
@@ -103,21 +122,38 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
public int getItemViewType(int position) {
if (isInMainPage) {
if (isLoggedIn) {
- if (position == CURRENT_MENU_ITEMS) {
+ if (position == CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
return VIEW_TYPE_MENU_GROUP_TITLE;
- } else if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS + favoriteSubscribedSubreddits.size() + 1) {
+ } else if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ + (collapseFavoriteSubredditsSection ? 0 : favoriteSubscribedSubreddits.size()) + 1) {
return VIEW_TYPE_MENU_GROUP_TITLE;
- } else if (position > CURRENT_MENU_ITEMS) {
- if (!favoriteSubscribedSubreddits.isEmpty() && position <= CURRENT_MENU_ITEMS + favoriteSubscribedSubreddits.size()) {
+ } else if (position > CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
+ if (!favoriteSubscribedSubreddits.isEmpty() && !collapseFavoriteSubredditsSection && position <= CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ + favoriteSubscribedSubreddits.size()) {
return VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT;
} else {
return VIEW_TYPE_SUBSCRIBED_SUBREDDIT;
}
} else if (position == 0) {
return VIEW_TYPE_NAV_HEADER;
- } else if (position == 1 || position == 6 || position == 12) {
+ } else if (position == 1
+ || position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ || position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)) {
return VIEW_TYPE_MENU_GROUP_TITLE;
- } else if (position == 16) {
+ } else if (position == 16 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
return VIEW_TYPE_DIVIDER;
} else {
return VIEW_TYPE_MENU_ITEM;
@@ -251,19 +287,80 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
});
} else if (holder instanceof MenuGroupTitleViewHolder) {
+ int type;
if (position == 1) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_account);
- } else if (position == 6) {
+ type = 0;
+ } else if (position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
- } else if (position == 12) {
+ type = 1;
+ } else if (position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences);
+ type = 2;
} else {
- if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS) {
+ if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites);
+ type = 3;
} else {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions);
+ type = 4;
}
}
+
+ ((MenuGroupTitleViewHolder) holder).itemView.setOnClickListener(view -> {
+ switch (type) {
+ case 0:
+ if (collapseAccountSection) {
+ collapseAccountSection = !collapseAccountSection;
+ notifyItemRangeInserted(position + 1, ACCOUNT_SECTION_ITEMS);
+ } else {
+ collapseAccountSection = !collapseAccountSection;
+ notifyItemRangeRemoved(position + 1, ACCOUNT_SECTION_ITEMS);
+ }
+ break;
+ case 1:
+ if (collapsePostSection) {
+ collapsePostSection = !collapsePostSection;
+ notifyItemRangeInserted(position + 1, POST_SECTION_ITEMS);
+ } else {
+ collapsePostSection = !collapsePostSection;
+ notifyItemRangeRemoved(position + 1, POST_SECTION_ITEMS);
+ }
+ break;
+ case 2:
+ if (collapsePreferencesSection) {
+ collapsePreferencesSection = !collapsePreferencesSection;
+ notifyItemRangeInserted(position + 1, PREFERENCES_SECTION_ITEMS);
+ } else {
+ collapsePreferencesSection = !collapsePreferencesSection;
+ notifyItemRangeRemoved(position + 1, PREFERENCES_SECTION_ITEMS);
+ }
+ break;
+ case 3:
+ if (collapseFavoriteSubredditsSection) {
+ collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection;
+ notifyItemRangeInserted(position + 1, favoriteSubscribedSubreddits.size());
+ } else {
+ collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection;
+ notifyItemRangeRemoved(position + 1, favoriteSubscribedSubreddits.size());
+ }
+ break;
+ case 4:
+ if (collapseSubscribedSubredditsSection) {
+ collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection;
+ notifyItemRangeInserted(position + 1, subscribedSubreddits.size());
+ } else {
+ collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection;
+ notifyItemRangeRemoved(position + 1, subscribedSubreddits.size());
+ }
+ break;
+ }
+ notifyDataSetChanged();
+ });
} else if (holder instanceof MenuItemViewHolder) {
int stringId = 0;
int drawableId = 0;
@@ -271,7 +368,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (isInMainPage) {
if (isLoggedIn) {
- switch (position) {
+ int pseudoPosition = position;
+ if (collapseAccountSection && collapsePostSection) {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS + POST_SECTION_ITEMS;
+ } else if (collapseAccountSection && collapsePreferencesSection) {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS;
+ } else if (collapseAccountSection) {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS;
+ } else if (collapsePostSection) {
+ if (position > ACCOUNT_SECTION_ITEMS + 1) {
+ pseudoPosition += POST_SECTION_ITEMS;
+ }
+ }
+ switch (pseudoPosition) {
case 2:
stringId = R.string.profile;
drawableId = R.drawable.ic_account_circle_24dp;
@@ -413,7 +522,11 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
}
} else if (holder instanceof FavoriteSubscribedThingViewHolder) {
- SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - CURRENT_MENU_ITEMS - 1);
+ SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - (CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0))
+ - 1);
String subredditName = subreddit.getName();
String iconUrl = subreddit.getIconUrl();
((FavoriteSubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName);
@@ -433,8 +546,17 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
itemClickListener.onSubscribedSubredditClick(subredditName);
});
} else if (holder instanceof SubscribedThingViewHolder) {
- SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.isEmpty() ? subscribedSubreddits.get(position - CURRENT_MENU_ITEMS - 1)
- : subscribedSubreddits.get(position - CURRENT_MENU_ITEMS - favoriteSubscribedSubreddits.size() - 2);
+ SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.isEmpty() ? subscribedSubreddits.get(position - (CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0))
+ - 1)
+ : subscribedSubreddits.get(position - (CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0))
+ - (collapseFavoriteSubredditsSection ? 0 : favoriteSubscribedSubreddits.size())
+ - 2);
String subredditName = subreddit.getName();
String iconUrl = subreddit.getIconUrl();
((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName);
@@ -501,10 +623,37 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (isInMainPage) {
if (isLoggedIn) {
if (!(favoriteSubscribedSubreddits.isEmpty() && subscribedSubreddits.isEmpty())) {
+ if (hideFavoriteSubredditsSection && hideSubscribedSubredditsSection) {
+ return CURRENT_MENU_ITEMS
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0);
+ } else if (hideFavoriteSubredditsSection) {
+ return CURRENT_MENU_ITEMS
+ + (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ - (collapseSubscribedSubredditsSection ? subscribedSubreddits.size() : 0);
+ } else if (hideSubscribedSubredditsSection) {
+ return CURRENT_MENU_ITEMS + (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ - (collapseFavoriteSubredditsSection ? favoriteSubscribedSubreddits.size() : 0);
+ }
return CURRENT_MENU_ITEMS + (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
- + (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1);
+ + (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ - (collapseFavoriteSubredditsSection ? favoriteSubscribedSubreddits.size() : 0)
+ - (collapseSubscribedSubredditsSection ? subscribedSubreddits.size() : 0);
}
- return CURRENT_MENU_ITEMS - 1;
+ return CURRENT_MENU_ITEMS - 1
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapsePostSection ? POST_SECTION_ITEMS : 0)
+ - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0);
} else {
return 4;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index 1d2ba964..74b882b0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -288,6 +288,15 @@ public class SharedPreferencesUtils {
public static final String ACCESS_TOKEN = "access_token";
public static final String ACCOUNT_IMAGE_URL = "account_image_url";
+ public static final String NAVIGATION_DRAWER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.navigation_drawer";
+ public static final String COLLAPSE_ACCOUNT_SECTION = "collapse_account_section";
+ public static final String COLLAPSE_POST_SECTION = "collapse_post_section";
+ public static final String COLLAPSE_PREFERENCES_SECTION = "collapse_preferences_section";
+ public static final String COLLAPSE_FAVORITE_SUBREDDITS_SECTION = "collapse_favorite_subreddits_section";
+ public static final String COLLAPSE_SUBSCRIBED_SUBREDDITS_SECTION = "collapse_subscribed_subreddits_section";
+ public static final String HIDE_FAVORITE_SUBREDDITS_SECTION = "hide_favorite_subreddits_sections";
+ public static final String HIDE_SUBSCRIBED_SUBREDDITS_SECTIONS = "hide_subscribed_subreddits_sections";
+
//Legacy Settings
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
public static final String MAIN_PAGE_TAB_2_TITLE_LEGACY = "main_page_tab_2_title";