clean adapter for comment
This commit is contained in:
parent
dd7d253a1b
commit
c2f99e130d
|
@ -33,15 +33,14 @@ import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
@ -59,6 +58,7 @@ import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
|
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
|
||||||
import app.fedilab.fedilabtube.client.entities.Report;
|
import app.fedilab.fedilabtube.client.entities.Report;
|
||||||
|
import app.fedilab.fedilabtube.databinding.DrawerCommentBinding;
|
||||||
import app.fedilab.fedilabtube.helper.CommentDecorationHelper;
|
import app.fedilab.fedilabtube.helper.CommentDecorationHelper;
|
||||||
import app.fedilab.fedilabtube.helper.EmojiHelper;
|
import app.fedilab.fedilabtube.helper.EmojiHelper;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
|
@ -104,8 +104,8 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
context = parent.getContext();
|
context = parent.getContext();
|
||||||
LayoutInflater layoutInflater = LayoutInflater.from(this.context);
|
DrawerCommentBinding itemBinding = DrawerCommentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_comment, parent, false));
|
return new ViewHolder(itemBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint({"SetJavaScriptEnabled", "ClickableViewAccessibility"})
|
@SuppressLint({"SetJavaScriptEnabled", "ClickableViewAccessibility"})
|
||||||
|
@ -121,23 +121,23 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
|
|
||||||
if (comment == null)
|
if (comment == null)
|
||||||
return;
|
return;
|
||||||
holder.main_container.setTag(i);
|
holder.binding.mainContainer.setTag(i);
|
||||||
|
|
||||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
(int) Helper.convertDpToPixel(40, context),
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
(int) Helper.convertDpToPixel(40, context)
|
||||||
);
|
);
|
||||||
if (comment.isReply()) {
|
if (comment.isReply()) {
|
||||||
int ident = CommentDecorationHelper.getIndentation(comment.getInReplyToCommentId(), comments);
|
int ident = CommentDecorationHelper.getIndentation(comment.getInReplyToCommentId(), comments);
|
||||||
holder.decoration.setVisibility(View.VISIBLE);
|
holder.binding.decoration.setVisibility(View.VISIBLE);
|
||||||
params.setMargins((int) Helper.convertDpToPixel(ident * 10, context), 0, 0, 0);
|
params.setMargins((int) Helper.convertDpToPixel(ident * 10, context), 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
holder.decoration.setVisibility(View.GONE);
|
holder.binding.decoration.setVisibility(View.GONE);
|
||||||
params.setMargins(0, 0, 0, 0);
|
params.setMargins(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
holder.main_container.setLayoutParams(params);
|
holder.binding.commentAccountProfile.setLayoutParams(params);
|
||||||
holder.more_actions.setOnClickListener(view -> {
|
holder.binding.moreActions.setOnClickListener(view -> {
|
||||||
PopupMenu popup = new PopupMenu(context, holder.more_actions);
|
PopupMenu popup = new PopupMenu(context, holder.binding.moreActions);
|
||||||
popup.getMenuInflater()
|
popup.getMenuInflater()
|
||||||
.inflate(R.menu.comment_menu, popup.getMenu());
|
.inflate(R.menu.comment_menu, popup.getMenu());
|
||||||
if (!Helper.isOwner(context, comment.getAccount())) {
|
if (!Helper.isOwner(context, comment.getAccount())) {
|
||||||
|
@ -219,7 +219,7 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
});
|
});
|
||||||
popup.show();
|
popup.show();
|
||||||
});
|
});
|
||||||
holder.comment_content.setOnTouchListener((view, motionEvent) -> {
|
holder.binding.commentContent.setOnTouchListener((view, motionEvent) -> {
|
||||||
if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) {
|
if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) {
|
||||||
try {
|
try {
|
||||||
view.requestFocus();
|
view.requestFocus();
|
||||||
|
@ -234,22 +234,22 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
commentSpan = Html.fromHtml(EmojiHelper.shortnameToUnicode(comment.getText()), Html.FROM_HTML_MODE_COMPACT);
|
commentSpan = Html.fromHtml(EmojiHelper.shortnameToUnicode(comment.getText()), Html.FROM_HTML_MODE_COMPACT);
|
||||||
else
|
else
|
||||||
commentSpan = Html.fromHtml(EmojiHelper.shortnameToUnicode(comment.getText()));
|
commentSpan = Html.fromHtml(EmojiHelper.shortnameToUnicode(comment.getText()));
|
||||||
holder.comment_content.setText(commentSpan, TextView.BufferType.SPANNABLE);
|
holder.binding.commentContent.setText(commentSpan, TextView.BufferType.SPANNABLE);
|
||||||
|
|
||||||
holder.comment_content.setMovementMethod(LinkMovementMethod.getInstance());
|
holder.binding.commentContent.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
holder.comment_account_displayname.setText(comment.getAccount().getDisplayName());
|
holder.binding.commentAccountDisplayname.setText(comment.getAccount().getDisplayName());
|
||||||
|
|
||||||
|
|
||||||
if (context instanceof PeertubeActivity && !isThread) {
|
if (context instanceof PeertubeActivity && !isThread) {
|
||||||
holder.main_container.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment));
|
holder.binding.mainContainer.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment));
|
||||||
holder.comment_content.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment));
|
holder.binding.commentContent.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment));
|
||||||
}
|
}
|
||||||
if (comment.getTotalReplies() > 0) {
|
if (comment.getTotalReplies() > 0) {
|
||||||
holder.number_of_replies.setVisibility(View.VISIBLE);
|
holder.binding.numberOfReplies.setVisibility(View.VISIBLE);
|
||||||
holder.number_of_replies.setText(context.getResources().getQuantityString(R.plurals.number_of_replies, comment.getTotalReplies(), comment.getTotalReplies()));
|
holder.binding.numberOfReplies.setText(context.getResources().getQuantityString(R.plurals.number_of_replies, comment.getTotalReplies(), comment.getTotalReplies()));
|
||||||
} else {
|
} else {
|
||||||
holder.number_of_replies.setVisibility(View.GONE);
|
holder.binding.numberOfReplies.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comment.getAccount() != null) {
|
if (comment.getAccount() != null) {
|
||||||
|
@ -265,10 +265,10 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, android.R.color.darker_gray)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, android.R.color.darker_gray)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
holder.comment_account_username.setText(wordtoSpan);
|
holder.binding.commentAccountUsername.setText(wordtoSpan);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.comment_date.setText(Helper.dateDiff(context, comment.getCreatedAt()));
|
holder.binding.commentDate.setText(Helper.dateDiff(context, comment.getCreatedAt()));
|
||||||
|
|
||||||
String avatarUrl;
|
String avatarUrl;
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
|
@ -276,9 +276,9 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
} else {
|
} else {
|
||||||
avatarUrl = comment.getAccount().getAvatar() != null ? comment.getAccount().getAvatar().getPath() : null;
|
avatarUrl = comment.getAccount().getAvatar() != null ? comment.getAccount().getAvatar().getPath() : null;
|
||||||
}
|
}
|
||||||
Helper.loadGiF(context, avatarUrl, holder.comment_account_profile);
|
Helper.loadGiF(context, avatarUrl, holder.binding.commentAccountProfile);
|
||||||
|
|
||||||
holder.comment_account_profile.setOnClickListener(v -> {
|
holder.binding.commentAccountProfile.setOnClickListener(v -> {
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
Intent intent = new Intent(context, ShowAccountActivity.class);
|
Intent intent = new Intent(context, ShowAccountActivity.class);
|
||||||
b.putParcelable("account", comment.getAccount());
|
b.putParcelable("account", comment.getAccount());
|
||||||
|
@ -287,17 +287,17 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
});
|
});
|
||||||
if (comment.isReply()) {
|
if (comment.isReply()) {
|
||||||
holder.replyButton.setVisibility(View.VISIBLE);
|
holder.binding.replyButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.replyButton.setVisibility(View.GONE);
|
holder.binding.replyButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (i == 0 && isThread) {
|
if (i == 0 && isThread) {
|
||||||
holder.post_reply_button.setVisibility(View.VISIBLE);
|
holder.binding.postReplyButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.post_reply_button.setVisibility(View.GONE);
|
holder.binding.postReplyButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
holder.post_reply_button.setOnClickListener(v -> ((PeertubeActivity) context).openPostComment(comment, i));
|
holder.binding.postReplyButton.setOnClickListener(v -> ((PeertubeActivity) context).openPostComment(comment, i));
|
||||||
holder.replyButton.setOnClickListener(v -> ((PeertubeActivity) context).openPostComment(comment, i));
|
holder.binding.replyButton.setOnClickListener(v -> ((PeertubeActivity) context).openPostComment(comment, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int i, APIResponse apiResponse) {
|
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int i, APIResponse apiResponse) {
|
||||||
|
@ -358,40 +358,15 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||||
void onAllCommentRemoved();
|
void onAllCommentRemoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
DrawerCommentBinding binding;
|
||||||
|
|
||||||
TextView comment_content;
|
ViewHolder(DrawerCommentBinding itemView) {
|
||||||
TextView comment_account_username;
|
super(itemView.getRoot());
|
||||||
TextView comment_account_displayname;
|
binding = itemView;
|
||||||
ImageView comment_account_profile;
|
|
||||||
TextView comment_date, replyButton;
|
|
||||||
LinearLayout main_container;
|
|
||||||
TextView more_actions, number_of_replies;
|
|
||||||
Button post_reply_button;
|
|
||||||
View decoration;
|
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
|
||||||
ViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
comment_content = itemView.findViewById(R.id.comment_content);
|
|
||||||
comment_account_username = itemView.findViewById(R.id.comment_account_username);
|
|
||||||
comment_account_profile = itemView.findViewById(R.id.comment_account_profile);
|
|
||||||
comment_account_displayname = itemView.findViewById(R.id.comment_account_displayname);
|
|
||||||
comment_date = itemView.findViewById(R.id.comment_date);
|
|
||||||
main_container = itemView.findViewById(R.id.main_container);
|
|
||||||
more_actions = itemView.findViewById(R.id.more_actions);
|
|
||||||
number_of_replies = itemView.findViewById(R.id.number_of_replies);
|
|
||||||
replyButton = itemView.findViewById(R.id.replyButton);
|
|
||||||
decoration = itemView.findViewById(R.id.decoration);
|
|
||||||
post_reply_button = itemView.findViewById(R.id.post_reply_button);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView() {
|
|
||||||
return itemView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue