diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-03-14 12:37:39 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-03-14 12:37:39 +0000 |
commit | 5811ca9ff01811d3432583e4875cb4cf309294a0 (patch) | |
tree | 95d3d2be2c7661550b0a2160a80309cebc9a36a1 /app/src/main | |
parent | 67fa19cdc147a18786718869e5ac96746117a3ca (diff) | |
download | infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.tar infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.tar.gz infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.tar.bz2 infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.tar.lz infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.tar.xz infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.tar.zst infinity-for-reddit-5811ca9ff01811d3432583e4875cb4cf309294a0.zip |
Add an indicator in NavigationDrawerRecyclerViewAdapter.MenuGroupTitleViewHolder.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java | 53 | ||||
-rw-r--r-- | app/src/main/res/layout/item_nav_drawer_menu_group_title.xml | 24 |
2 files changed, 60 insertions, 17 deletions
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 3780f24d..9a51e181 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java @@ -290,13 +290,28 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re int type; if (position == 1) { ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_account); + if (collapseAccountSection) { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px); + } else { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px); + } type = 0; } else if (position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)) { ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post); + if (collapsePostSection) { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px); + } else { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px); + } type = 1; } else if (position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0)) { ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences); + if (collapsePreferencesSection) { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px); + } else { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px); + } type = 2; } else { if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS @@ -304,9 +319,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re - (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) { ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites); + if (collapseFavoriteSubredditsSection) { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px); + } else { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px); + } type = 3; } else { ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions); + if (collapseSubscribedSubredditsSection) { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px); + } else { + ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px); + } type = 4; } } @@ -316,50 +341,50 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re case 0: if (collapseAccountSection) { collapseAccountSection = !collapseAccountSection; - notifyItemRangeInserted(position + 1, ACCOUNT_SECTION_ITEMS); + notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, ACCOUNT_SECTION_ITEMS); } else { collapseAccountSection = !collapseAccountSection; - notifyItemRangeRemoved(position + 1, ACCOUNT_SECTION_ITEMS); + notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, ACCOUNT_SECTION_ITEMS); } break; case 1: if (collapsePostSection) { collapsePostSection = !collapsePostSection; - notifyItemRangeInserted(position + 1, POST_SECTION_ITEMS); + notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, POST_SECTION_ITEMS); } else { collapsePostSection = !collapsePostSection; - notifyItemRangeRemoved(position + 1, POST_SECTION_ITEMS); + notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, POST_SECTION_ITEMS); } break; case 2: if (collapsePreferencesSection) { collapsePreferencesSection = !collapsePreferencesSection; - notifyItemRangeInserted(position + 1, PREFERENCES_SECTION_ITEMS); + notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, PREFERENCES_SECTION_ITEMS); } else { collapsePreferencesSection = !collapsePreferencesSection; - notifyItemRangeRemoved(position + 1, PREFERENCES_SECTION_ITEMS); + notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, PREFERENCES_SECTION_ITEMS); } break; case 3: if (collapseFavoriteSubredditsSection) { collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection; - notifyItemRangeInserted(position + 1, favoriteSubscribedSubreddits.size()); + notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, favoriteSubscribedSubreddits.size()); } else { collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection; - notifyItemRangeRemoved(position + 1, favoriteSubscribedSubreddits.size()); + notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, favoriteSubscribedSubreddits.size()); } break; case 4: if (collapseSubscribedSubredditsSection) { collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection; - notifyItemRangeInserted(position + 1, subscribedSubreddits.size()); + notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, subscribedSubreddits.size()); } else { collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection; - notifyItemRangeRemoved(position + 1, subscribedSubreddits.size()); + notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, subscribedSubreddits.size()); } break; } - notifyDataSetChanged(); + notifyItemChanged(holder.getBindingAdapterPosition()); }); } else if (holder instanceof MenuItemViewHolder) { int stringId = 0; @@ -748,12 +773,16 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { + @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) TextView titleTextView; + @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) + ImageView collapseIndicatorImageView; MenuGroupTitleViewHolder(@NonNull View itemView) { super(itemView); - titleTextView = (TextView) itemView; + ButterKnife.bind(this, itemView); titleTextView.setTextColor(secondaryTextColor); + collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } diff --git a/app/src/main/res/layout/item_nav_drawer_menu_group_title.xml b/app/src/main/res/layout/item_nav_drawer_menu_group_title.xml index 01901b25..fbdef5bc 100644 --- a/app/src/main/res/layout/item_nav_drawer_menu_group_title.xml +++ b/app/src/main/res/layout/item_nav_drawer_menu_group_title.xml @@ -1,8 +1,22 @@ <?xml version="1.0" encoding="utf-8"?> -<TextView xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="16dp" - android:text="@string/label_post" - android:textSize="?attr/font_default" - android:fontFamily="?attr/font_family" />
\ No newline at end of file + android:padding="16dp"> + + <TextView + android:id="@+id/title_text_view_item_nav_drawer_menu_group_title" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:layout_gravity="center_vertical" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" /> + + <ImageView + android:id="@+id/collapse_indicator_image_view_item_nav_drawer_menu_group_title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" /> + +</LinearLayout>
\ No newline at end of file |