some tries

This commit is contained in:
Thomas 2020-11-25 15:08:38 +01:00
parent dd7d253a1b
commit 250aa03e9a
4 changed files with 163 additions and 66 deletions

View File

@ -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,25 @@ 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.decorationCurved.setVisibility(View.VISIBLE);
holder.binding.decorationCurvedLine.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.decorationCurved.setVisibility(View.GONE);
holder.binding.decorationCurvedLine.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 +221,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 +236,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 +267,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 +278,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 +289,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 +360,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;
}
} }
} }

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size
android:width="60dp"
android:height="60dp" />
<corners android:bottomLeftRadius="60dp" />
<stroke
android:width="1dp"
android:color="@color/colorAccent" />
</shape>
</item>
<item
android:right="1dp"
android:top="-59dp">
<shape android:shape="line">
<size
android:width="60dp"
android:height="1dp" />
<stroke
android:width="1dp"
android:color="?attr/backgroundColor" />
</shape>
</item>
<item
android:right="-60dp"
android:top="-60dp">
<rotate
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-90">
<shape android:shape="line">
<size
android:width="60dp"
android:height="1dp" />
<stroke
android:width="1dp"
android:color="?attr/backgroundColor" />
</shape>
</rotate>
</item>
<item>
<clip>
<rotate
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-90">
<shape android:shape="line">
<size
android:width="60dp"
android:height="1dp" />
<stroke
android:width="1dp"
android:color="?attr/backgroundColor" />
</shape>
</rotate>
</clip>
</item>
</layer-list>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size
android:width="30dp"
android:height="30dp" />
<solid android:color="@color/colorAccent" />
<corners android:bottomLeftRadius="30dp" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="1dp">
<shape android:shape="rectangle">
<size
android:width="30dp"
android:height="30dp" />
<solid android:color="?attr/backgroundView" />
<corners android:bottomLeftRadius="30dp" />
</shape>
</item>
</layer-list>

View File

@ -28,11 +28,43 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<View <View
android:id="@+id/decoration" android:id="@+id/decoration_middle"
android:visibility="gone"
android:layout_width="2dp" android:layout_width="2dp"
android:layout_height="0dp" android:layout_height="0dp"
android:background="?attr/colorAccent" android:background="?attr/colorAccent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/decoration_curved"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/decoration_curved"
android:layout_width="15dp"
android:layout_height="15dp"
android:background="@drawable/rounded_decoration_2"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/decoration_curved_line"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="@color/colorAccent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/decoration_curved"
app:layout_constraintEnd_toStartOf="@+id/comment_account_profile"
app:layout_constraintStart_toEndOf="@+id/decoration_curved" />
<View
android:id="@+id/decoration_long"
android:layout_width="2dp"
android:layout_height="0dp"
android:background="?attr/colorAccent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -42,9 +74,10 @@
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:src="@drawable/missing_peertube"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:contentDescription="@string/profile_picture" android:contentDescription="@string/profile_picture"
app:layout_constraintStart_toStartOf="@id/decoration" app:layout_constraintStart_toStartOf="@id/decoration_long"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
@ -108,7 +141,7 @@
<TextView <TextView
android:id="@+id/number_of_replies" android:id="@+id/number_of_replies"
app:layout_constraintTop_toBottomOf="@+id/comment_content" app:layout_constraintTop_toBottomOf="@+id/comment_content"
app:layout_constraintStart_toStartOf="@id/decoration" app:layout_constraintStart_toStartOf="@id/comment_account_profile"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?attr/colorAccent"/> android:textColor="?attr/colorAccent"/>