Browse Source

fix: add additional checks to expandable views of BoardAdapter

develop
Ezerous 2 years ago
parent
commit
88430f3126
  1. 54
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java

54
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java

@ -3,7 +3,6 @@ package gr.thmmy.mthmmy.activities.board;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -104,7 +103,7 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
}); });
if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition())) { if (boardExpandableVisibility.get(subBoardViewHolder.getBindingAdapterPosition())) {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
} }
@ -113,16 +112,19 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} }
subBoardViewHolder.showHideExpandable.setOnClickListener(view -> { subBoardViewHolder.showHideExpandable.setOnClickListener(view -> {
final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition()); final int pos = subBoardViewHolder.getBindingAdapterPosition();
if (visible) { if (pos >=0 && pos < boardExpandableVisibility.size()){
subBoardViewHolder.boardExpandable.setVisibility(View.GONE); final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getBindingAdapterPosition());
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); if (visible) {
subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
}
else {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
boardExpandableVisibility.set(subBoardViewHolder.getBindingAdapterPosition(), !visible);
} }
else {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition(), !visible);
}); });
subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); subBoardViewHolder.boardTitle.setText(subBoard.getTitle());
String mods = subBoard.getMods(); String mods = subBoard.getMods();
@ -174,7 +176,7 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent); context.startActivity(intent);
}); });
if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards if (topicExpandableVisibility.get(topicViewHolder.getBindingAdapterPosition() - parsedSubBoards
.size())) { .size())) {
topicViewHolder.topicExpandable.setVisibility(View.VISIBLE); topicViewHolder.topicExpandable.setVisibility(View.VISIBLE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
@ -184,27 +186,29 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} }
topicViewHolder.showHideExpandable.setOnClickListener(view -> { topicViewHolder.showHideExpandable.setOnClickListener(view -> {
final boolean visible = topicExpandableVisibility.get(topicViewHolder. final int pos = topicViewHolder.getBindingAdapterPosition() - parsedSubBoards.size();
getAdapterPosition() - parsedSubBoards.size()); if (pos >=0 && pos < topicExpandableVisibility.size()) {
if (visible) { final boolean visible = topicExpandableVisibility.get(topicViewHolder.
topicViewHolder.topicExpandable.setVisibility(View.GONE); getBindingAdapterPosition() - parsedSubBoards.size());
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); if (visible) {
} topicViewHolder.topicExpandable.setVisibility(View.GONE);
else { topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
topicViewHolder.topicExpandable.setVisibility(View.VISIBLE); }
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); else {
topicViewHolder.topicExpandable.setVisibility(View.VISIBLE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
topicExpandableVisibility.set(topicViewHolder.getBindingAdapterPosition() -
parsedSubBoards.size(), !visible);
} }
topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() -
parsedSubBoards.size(), !visible);
}); });
topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets() topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets()
, "fonts/fontawesome-webfont.ttf")); , "fonts/fontawesome-webfont.ttf"));
topicViewHolder.topicUnreadDot.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/fontawesome-webfont.ttf")); topicViewHolder.topicUnreadDot.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/fontawesome-webfont.ttf"));
if (topic.isUnread()) if (topic.isUnread())
topicViewHolder.topicUnreadDot.setVisibility(View.VISIBLE); topicViewHolder.topicUnreadDot.setVisibility(View.VISIBLE);
else { else
topicViewHolder.topicUnreadDot.setVisibility(View.GONE); topicViewHolder.topicUnreadDot.setVisibility(View.GONE);
}
String lockedSticky = topic.getSubject(); String lockedSticky = topic.getSubject();
if (topic.isLocked()) if (topic.isLocked())
lockedSticky += " " + context.getResources().getString(R.string.fa_lock); lockedSticky += " " + context.getResources().getString(R.string.fa_lock);

Loading…
Cancel
Save