From 923b70e49c24e85d56d1cef32ff988b51d49568d Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 22 Aug 2022 22:46:01 +0300 Subject: [PATCH] feat: removed title rows from BoardActivity --- .../mthmmy/activities/board/BoardAdapter.java | 85 ++++--------------- 1 file changed, 17 insertions(+), 68 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java index 3594fe79..6468d130 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java @@ -32,11 +32,9 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; * {@link RecyclerView.Adapter} that can display a {@link gr.thmmy.mthmmy.model.Board}. */ class BoardAdapter extends RecyclerView.Adapter { - private final int VIEW_TYPE_SUB_BOARD_TITLE = 0; - private final int VIEW_TYPE_SUB_BOARD = 1; - private final int VIEW_TYPE_TOPIC_TITLE = 2; - private final int VIEW_TYPE_TOPIC = 3; - private final int VIEW_TYPE_LOADING = 4; + private final int VIEW_TYPE_SUB_BOARD = 0; + private final int VIEW_TYPE_TOPIC = 1; + private final int VIEW_TYPE_LOADING = 2; private final Context context; private ArrayList parsedSubBoards; @@ -56,13 +54,11 @@ class BoardAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { - if (position <= parsedSubBoards.size()) { - if (position == 0) return VIEW_TYPE_SUB_BOARD_TITLE; + if (position < parsedSubBoards.size()) { return VIEW_TYPE_SUB_BOARD; } - else if (position <= parsedSubBoards.size() + parsedTopics.size() + 1) { - if (position == parsedSubBoards.size() + 1) return VIEW_TYPE_TOPIC_TITLE; - if (parsedTopics.get(position - parsedSubBoards.size() - 1 - 1) != null) + else if (position < parsedSubBoards.size() + parsedTopics.size()) { + if (parsedTopics.get(position - parsedSubBoards.size()) != null) //?? return VIEW_TYPE_TOPIC; } return VIEW_TYPE_LOADING; @@ -70,52 +66,11 @@ class BoardAdapter extends RecyclerView.Adapter { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - if (viewType == VIEW_TYPE_SUB_BOARD_TITLE) { - TextView subBoardTitle = new TextView(context); - subBoardTitle.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT - , LinearLayout.LayoutParams.WRAP_CONTENT)); - subBoardTitle.setText(context.getString(R.string.child_board_title)); - subBoardTitle.setTypeface(subBoardTitle.getTypeface(), Typeface.BOLD); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - subBoardTitle.setBackgroundColor(context.getColor(R.color.background_light)); - subBoardTitle.setTextColor(context.getColor(R.color.accent)); - } - else { - //noinspection deprecation - subBoardTitle.setBackgroundColor(context.getResources().getColor(R.color.background_light)); - //noinspection deprecation - subBoardTitle.setTextColor(context.getResources().getColor(R.color.accent)); - } - subBoardTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - subBoardTitle.setTextSize(20f); - - return new TitlesViewHolder(subBoardTitle); - } - else if (viewType == VIEW_TYPE_SUB_BOARD) { + if (viewType == VIEW_TYPE_SUB_BOARD) { View subBoard = LayoutInflater.from(parent.getContext()). inflate(R.layout.activity_board_sub_board_row, parent, false); return new SubBoardViewHolder(subBoard); } - else if (viewType == VIEW_TYPE_TOPIC_TITLE) { - TextView topicTitle = new TextView(context); - topicTitle.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT - , LinearLayout.LayoutParams.WRAP_CONTENT)); - topicTitle.setText(context.getString(R.string.topic_title)); - topicTitle.setTypeface(topicTitle.getTypeface(), Typeface.BOLD); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - topicTitle.setTextColor(context.getColor(R.color.primary_text)); - } - else { - //noinspection deprecation - topicTitle.setTextColor(context.getResources().getColor(R.color.primary_text)); - } - topicTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - topicTitle.setTextSize(20f); - - return new TitlesViewHolder(topicTitle); - } else if (viewType == VIEW_TYPE_TOPIC) { View topic = LayoutInflater.from(parent.getContext()). inflate(R.layout.activity_board_topic_row, parent, false); @@ -132,7 +87,7 @@ class BoardAdapter extends RecyclerView.Adapter { @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) { if (holder instanceof SubBoardViewHolder) { - final Board subBoard = parsedSubBoards.get(position - 1); + final Board subBoard = parsedSubBoards.get(position); final SubBoardViewHolder subBoardViewHolder = (SubBoardViewHolder) holder; if (boardExpandableVisibility.size() != parsedSubBoards.size()) { @@ -149,7 +104,7 @@ class BoardAdapter extends RecyclerView.Adapter { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }); - if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1)) { + if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition())) { subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); } @@ -158,7 +113,7 @@ class BoardAdapter extends RecyclerView.Adapter { subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); } subBoardViewHolder.showHideExpandable.setOnClickListener(view -> { - final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1); + final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition()); if (visible) { subBoardViewHolder.boardExpandable.setVisibility(View.GONE); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); @@ -167,7 +122,7 @@ class BoardAdapter extends RecyclerView.Adapter { subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); } - boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible); + boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition(), !visible); }); subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); String mods = subBoard.getMods(); @@ -202,7 +157,7 @@ class BoardAdapter extends RecyclerView.Adapter { } } else if (holder instanceof TopicViewHolder) { - final Topic topic = parsedTopics.get(position - parsedSubBoards.size() - 1 - 1); + final Topic topic = parsedTopics.get(position - parsedSubBoards.size()); final TopicViewHolder topicViewHolder = (TopicViewHolder) holder; if (topicExpandableVisibility.size() != parsedTopics.size()) { @@ -220,7 +175,7 @@ class BoardAdapter extends RecyclerView.Adapter { context.startActivity(intent); }); if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards - .size() - 2)) { + .size())) { topicViewHolder.topicExpandable.setVisibility(View.VISIBLE); topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); } @@ -230,7 +185,7 @@ class BoardAdapter extends RecyclerView.Adapter { } topicViewHolder.showHideExpandable.setOnClickListener(view -> { final boolean visible = topicExpandableVisibility.get(topicViewHolder. - getAdapterPosition() - parsedSubBoards.size() - 2); + getAdapterPosition() - parsedSubBoards.size()); if (visible) { topicViewHolder.topicExpandable.setVisibility(View.GONE); topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); @@ -240,7 +195,7 @@ class BoardAdapter extends RecyclerView.Adapter { topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp); } topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() - - parsedSubBoards.size() - 2, !visible); + parsedSubBoards.size(), !visible); }); topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets() , "fonts/fontawesome-webfont.ttf")); @@ -280,8 +235,8 @@ class BoardAdapter extends RecyclerView.Adapter { @Override public int getItemCount() { int items = 0; - if (parsedSubBoards != null) items += parsedSubBoards.size() + 1; - if (parsedTopics != null) items += parsedTopics.size() + 1; + if (parsedSubBoards != null) items += parsedSubBoards.size(); + if (parsedTopics != null) items += parsedTopics.size(); return items; } @@ -320,12 +275,6 @@ class BoardAdapter extends RecyclerView.Adapter { } } - private static class TitlesViewHolder extends RecyclerView.ViewHolder { - TitlesViewHolder(View title) { - super(title); - } - } - private static class LoadingViewHolder extends RecyclerView.ViewHolder { final MaterialProgressBar progressBar;