Fix navigation drawer issues.

This commit is contained in:
Docile-Alligator 2022-03-11 12:10:35 +08:00
parent 53755d4381
commit aab502238d
4 changed files with 9 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -25,6 +26,7 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1; private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
private static final int VIEW_TYPE_MENU_ITEM = 2; private static final int VIEW_TYPE_MENU_ITEM = 2;
private static final int ACCOUNT_SECTION_ITEMS = 4; private static final int ACCOUNT_SECTION_ITEMS = 4;
private static final int ANONYMOUS_ACCOUNT_SECTION_ITEMS = 2;
private BaseActivity baseActivity; private BaseActivity baseActivity;
private int inboxCount; private int inboxCount;
@ -77,10 +79,10 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
holder.itemView.setOnClickListener(view -> { holder.itemView.setOnClickListener(view -> {
if (collapseAccountSection) { if (collapseAccountSection) {
collapseAccountSection = !collapseAccountSection; collapseAccountSection = !collapseAccountSection;
notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, ACCOUNT_SECTION_ITEMS); notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, isLoggedIn ? ACCOUNT_SECTION_ITEMS : ANONYMOUS_ACCOUNT_SECTION_ITEMS);
} else { } else {
collapseAccountSection = !collapseAccountSection; collapseAccountSection = !collapseAccountSection;
notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, ACCOUNT_SECTION_ITEMS); notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, isLoggedIn ? ACCOUNT_SECTION_ITEMS : ANONYMOUS_ACCOUNT_SECTION_ITEMS);
} }
notifyItemChanged(holder.getBindingAdapterPosition()); notifyItemChanged(holder.getBindingAdapterPosition());
}); });
@ -103,7 +105,7 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
stringId = R.string.multi_reddit; stringId = R.string.multi_reddit;
drawableId = R.drawable.ic_multi_reddit_24dp; drawableId = R.drawable.ic_multi_reddit_24dp;
break; break;
case 4: default:
setOnClickListener = false; setOnClickListener = false;
if (inboxCount > 0) { if (inboxCount > 0) {
((MenuItemViewHolder) holder).menuTextView.setText(baseActivity.getString(R.string.inbox_with_count, inboxCount)); ((MenuItemViewHolder) holder).menuTextView.setText(baseActivity.getString(R.string.inbox_with_count, inboxCount));
@ -141,10 +143,7 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
@Override @Override
public int getItemCount() { public int getItemCount() {
if (isLoggedIn) { return collapseAccountSection ? 1 : (isLoggedIn ? ACCOUNT_SECTION_ITEMS + 1 : ANONYMOUS_ACCOUNT_SECTION_ITEMS + 1);
return ACCOUNT_SECTION_ITEMS + 1;
}
return 3;
} }
public void setInboxCount(int inboxCount) { public void setInboxCount(int inboxCount) {

View File

@ -119,7 +119,7 @@ public class PostSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recycle
@Override @Override
public int getItemCount() { public int getItemCount() {
return isLoggedIn ? POST_SECTION_ITEMS + 1 : 0; return isLoggedIn ? (collapsePostSection ? 1: POST_SECTION_ITEMS + 1) : 0;
} }
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {

View File

@ -143,7 +143,7 @@ public class PreferenceSectionRecyclerViewAdapter extends RecyclerView.Adapter<R
@Override @Override
public int getItemCount() { public int getItemCount() {
return PREFERENCES_SECTION_ITEMS + 1; return collapsePreferencesSection ? 1 : PREFERENCES_SECTION_ITEMS + 1;
} }
public void setNSFWEnabled(boolean isNSFWEnabled) { public void setNSFWEnabled(boolean isNSFWEnabled) {

View File

@ -103,7 +103,7 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
@Override @Override
public int getItemCount() { public int getItemCount() {
return REDDIT_SECTION_ITEMS + 1; return collapseRedditSection ? 1 : REDDIT_SECTION_ITEMS + 1;
} }
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {