|
@ -33,7 +33,6 @@ import android.widget.TextView; |
|
|
|
|
|
|
|
|
import com.squareup.picasso.Picasso; |
|
|
import com.squareup.picasso.Picasso; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@ -69,23 +68,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
private static int THUMBNAIL_SIZE; |
|
|
private static int THUMBNAIL_SIZE; |
|
|
private final Context context; |
|
|
private final Context context; |
|
|
private final OnPostFocusChangeListener postFocusListener; |
|
|
private final OnPostFocusChangeListener postFocusListener; |
|
|
private final ArrayList<Integer> toQuoteList = new ArrayList<>(); |
|
|
|
|
|
private final List<Post> postsList; |
|
|
private final List<Post> postsList; |
|
|
/** |
|
|
|
|
|
* Used to hold the state of visibility and other attributes for views that are animated or |
|
|
|
|
|
* otherwise changed. Used in combination with {@link #isUserExtraInfoVisibile} and |
|
|
|
|
|
* {@link #isQuoteButtonChecked}. |
|
|
|
|
|
*/ |
|
|
|
|
|
private final ArrayList<boolean[]> viewProperties = new ArrayList<>(); |
|
|
|
|
|
/** |
|
|
|
|
|
* Index of state indicator in the boolean array. If true user's extra info are expanded and |
|
|
|
|
|
* visible. |
|
|
|
|
|
*/ |
|
|
|
|
|
private static final int isUserExtraInfoVisibile = 0; |
|
|
|
|
|
/** |
|
|
|
|
|
* Index of state indicator in the boolean array. If true quote button for this post is checked. |
|
|
|
|
|
*/ |
|
|
|
|
|
private static final int isQuoteButtonChecked = 1; |
|
|
|
|
|
private TopicViewModel viewModel; |
|
|
private TopicViewModel viewModel; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -100,14 +83,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
viewModel = ViewModelProviders.of(context).get(TopicViewModel.class); |
|
|
viewModel = ViewModelProviders.of(context).get(TopicViewModel.class); |
|
|
|
|
|
|
|
|
THUMBNAIL_SIZE = (int) context.getResources().getDimension(R.dimen.thumbnail_size); |
|
|
THUMBNAIL_SIZE = (int) context.getResources().getDimension(R.dimen.thumbnail_size); |
|
|
for (int i = 0; i < postsList.size(); ++i) { |
|
|
|
|
|
//Initializes properties, array's values will be false by default
|
|
|
|
|
|
viewProperties.add(new boolean[3]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Integer> getToQuoteList() { |
|
|
|
|
|
return toQuoteList; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -318,7 +293,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
} else holder.cardChildLinear.setBackground(null); |
|
|
} else holder.cardChildLinear.setBackground(null); |
|
|
|
|
|
|
|
|
//Avoid's view's visibility recycling
|
|
|
//Avoid's view's visibility recycling
|
|
|
if (!currentPost.isDeleted() && viewProperties.get(position)[isUserExtraInfoVisibile]) { |
|
|
if (!currentPost.isDeleted() && viewModel.isUserExtraInfoVisible(holder.getAdapterPosition())) { |
|
|
holder.userExtraInfo.setVisibility(View.VISIBLE); |
|
|
holder.userExtraInfo.setVisibility(View.VISIBLE); |
|
|
holder.userExtraInfo.setAlpha(1.0f); |
|
|
holder.userExtraInfo.setAlpha(1.0f); |
|
|
|
|
|
|
|
@ -357,19 +332,14 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
}); |
|
|
}); |
|
|
holder.header.setOnClickListener(v -> { |
|
|
holder.header.setOnClickListener(v -> { |
|
|
//Clicking the header makes it expand/collapse
|
|
|
//Clicking the header makes it expand/collapse
|
|
|
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); |
|
|
viewModel.toggleUserInfo(holder.getAdapterPosition()); |
|
|
tmp[isUserExtraInfoVisibile] = !tmp[isUserExtraInfoVisibile]; |
|
|
|
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
|
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.username, |
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.username, |
|
|
holder.subject, Color.parseColor("#FFFFFF"), |
|
|
holder.subject, Color.parseColor("#FFFFFF"), |
|
|
Color.parseColor("#757575"), holder.userExtraInfo); |
|
|
Color.parseColor("#757575"), holder.userExtraInfo); |
|
|
}); |
|
|
}); |
|
|
//Clicking the expanded part of a header (the extra info) makes it collapse
|
|
|
//Clicking the expanded part of a header (the extra info) makes it collapse
|
|
|
holder.userExtraInfo.setOnClickListener(v -> { |
|
|
holder.userExtraInfo.setOnClickListener(v -> { |
|
|
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); |
|
|
viewModel.hideUserInfo(holder.getAdapterPosition()); |
|
|
tmp[isUserExtraInfoVisibile] = false; |
|
|
|
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
|
|
|
|
|
|
|
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.username, |
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.username, |
|
|
holder.subject, Color.parseColor("#FFFFFF"), |
|
|
holder.subject, Color.parseColor("#FFFFFF"), |
|
|
Color.parseColor("#757575"), (LinearLayout) v); |
|
|
Color.parseColor("#757575"), (LinearLayout) v); |
|
@ -438,25 +408,17 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) { |
|
|
if (!BaseActivity.getSessionManager().isLoggedIn() || !viewModel.canReply()) { |
|
|
holder.quoteToggle.setVisibility(View.GONE); |
|
|
holder.quoteToggle.setVisibility(View.GONE); |
|
|
} else { |
|
|
} else { |
|
|
if (viewProperties.get(position)[isQuoteButtonChecked]) |
|
|
if (viewModel.getToQuoteList().contains(currentPost.getPostIndex())) |
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); |
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); |
|
|
else |
|
|
else |
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); |
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); |
|
|
//Sets graphics behavior
|
|
|
//Sets graphics behavior
|
|
|
holder.quoteToggle.setOnClickListener(view -> { |
|
|
holder.quoteToggle.setOnClickListener(view -> { |
|
|
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); |
|
|
viewModel.postIndexToggle(currentPost.getPostIndex()); |
|
|
if (tmp[isQuoteButtonChecked]) { |
|
|
if (viewModel.getToQuoteList().contains(currentPost.getPostIndex())) |
|
|
if (toQuoteList.contains(postsList.indexOf(currentPost))) { |
|
|
|
|
|
toQuoteList.remove(toQuoteList.indexOf(postsList.indexOf(currentPost))); |
|
|
|
|
|
} else |
|
|
|
|
|
Timber.i("An error occurred while trying to exclude post fromtoQuoteList, post wasn't there!"); |
|
|
|
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); |
|
|
|
|
|
} else { |
|
|
|
|
|
toQuoteList.add(postsList.indexOf(currentPost)); |
|
|
|
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); |
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); |
|
|
} |
|
|
else |
|
|
tmp[isQuoteButtonChecked] = !tmp[isQuoteButtonChecked]; |
|
|
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); |
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} else if (currentHolder instanceof QuickReplyViewHolder) { |
|
|
} else if (currentHolder instanceof QuickReplyViewHolder) { |
|
@ -536,14 +498,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void resetTopic() { |
|
|
|
|
|
viewProperties.clear(); |
|
|
|
|
|
for (int i = 0; i < postsList.size(); ++i) { |
|
|
|
|
|
//Initializes properties, array's values will be false by default
|
|
|
|
|
|
viewProperties.add(new boolean[3]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public int getItemCount() { |
|
|
public int getItemCount() { |
|
|
return postsList.size(); |
|
|
return postsList.size(); |
|
|