Add an indicator in NavigationDrawerRecyclerViewAdapter.MenuGroupTitleViewHolder.

This commit is contained in:
Alex Ning 2021-03-14 20:37:39 +08:00
parent 67fa19cdc1
commit 5811ca9ff0
2 changed files with 60 additions and 17 deletions

View File

@ -290,13 +290,28 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
int type; int type;
if (position == 1) { if (position == 1) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_account); ((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; type = 0;
} else if (position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)) { } else if (position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post); ((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; type = 1;
} else if (position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0) } else if (position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)) { - (collapsePostSection ? POST_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences); ((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; type = 2;
} else { } else {
if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS
@ -304,9 +319,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
- (collapsePostSection ? POST_SECTION_ITEMS : 0) - (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) { - (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites); ((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; type = 3;
} else { } else {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions); ((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; type = 4;
} }
} }
@ -316,50 +341,50 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
case 0: case 0:
if (collapseAccountSection) { if (collapseAccountSection) {
collapseAccountSection = !collapseAccountSection; collapseAccountSection = !collapseAccountSection;
notifyItemRangeInserted(position + 1, ACCOUNT_SECTION_ITEMS); notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, ACCOUNT_SECTION_ITEMS);
} else { } else {
collapseAccountSection = !collapseAccountSection; collapseAccountSection = !collapseAccountSection;
notifyItemRangeRemoved(position + 1, ACCOUNT_SECTION_ITEMS); notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, ACCOUNT_SECTION_ITEMS);
} }
break; break;
case 1: case 1:
if (collapsePostSection) { if (collapsePostSection) {
collapsePostSection = !collapsePostSection; collapsePostSection = !collapsePostSection;
notifyItemRangeInserted(position + 1, POST_SECTION_ITEMS); notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, POST_SECTION_ITEMS);
} else { } else {
collapsePostSection = !collapsePostSection; collapsePostSection = !collapsePostSection;
notifyItemRangeRemoved(position + 1, POST_SECTION_ITEMS); notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, POST_SECTION_ITEMS);
} }
break; break;
case 2: case 2:
if (collapsePreferencesSection) { if (collapsePreferencesSection) {
collapsePreferencesSection = !collapsePreferencesSection; collapsePreferencesSection = !collapsePreferencesSection;
notifyItemRangeInserted(position + 1, PREFERENCES_SECTION_ITEMS); notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, PREFERENCES_SECTION_ITEMS);
} else { } else {
collapsePreferencesSection = !collapsePreferencesSection; collapsePreferencesSection = !collapsePreferencesSection;
notifyItemRangeRemoved(position + 1, PREFERENCES_SECTION_ITEMS); notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, PREFERENCES_SECTION_ITEMS);
} }
break; break;
case 3: case 3:
if (collapseFavoriteSubredditsSection) { if (collapseFavoriteSubredditsSection) {
collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection; collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection;
notifyItemRangeInserted(position + 1, favoriteSubscribedSubreddits.size()); notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, favoriteSubscribedSubreddits.size());
} else { } else {
collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection; collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection;
notifyItemRangeRemoved(position + 1, favoriteSubscribedSubreddits.size()); notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, favoriteSubscribedSubreddits.size());
} }
break; break;
case 4: case 4:
if (collapseSubscribedSubredditsSection) { if (collapseSubscribedSubredditsSection) {
collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection; collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection;
notifyItemRangeInserted(position + 1, subscribedSubreddits.size()); notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, subscribedSubreddits.size());
} else { } else {
collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection; collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection;
notifyItemRangeRemoved(position + 1, subscribedSubreddits.size()); notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, subscribedSubreddits.size());
} }
break; break;
} }
notifyDataSetChanged(); notifyItemChanged(holder.getBindingAdapterPosition());
}); });
} else if (holder instanceof MenuItemViewHolder) { } else if (holder instanceof MenuItemViewHolder) {
int stringId = 0; int stringId = 0;
@ -748,12 +773,16 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
} }
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.title_text_view_item_nav_drawer_menu_group_title)
TextView titleTextView; TextView titleTextView;
@BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title)
ImageView collapseIndicatorImageView;
MenuGroupTitleViewHolder(@NonNull View itemView) { MenuGroupTitleViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
titleTextView = (TextView) itemView; ButterKnife.bind(this, itemView);
titleTextView.setTextColor(secondaryTextColor); titleTextView.setTextColor(secondaryTextColor);
collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN);
} }
} }

View File

@ -1,8 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp" android:padding="16dp">
android:text="@string/label_post"
android:textSize="?attr/font_default" <TextView
android:fontFamily="?attr/font_family" /> 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>