diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index f57d698..d802dc0 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -38,6 +38,8 @@ import android.os.Looper; import android.support.v4.media.session.MediaSessionCompat; import android.text.Html; import android.text.Spanned; +import android.util.DisplayMetrics; +import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -246,7 +248,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token); Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp); - Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPpReply); } TorrentOptions torrentOptions = new TorrentOptions.Builder() @@ -298,7 +299,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } }); if (!Helper.isLoggedIn(PeertubeActivity.this) || sepiaSearch) { - binding.writeCommentContainerReply.setVisibility(View.GONE); binding.writeCommentContainer.setVisibility(View.GONE); } playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true); @@ -382,8 +382,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd comments = new ArrayList<>(); binding.closeReply.setOnClickListener(v -> closeCommentThread()); + binding.closePost.setOnClickListener(v -> closePostComment()); - commentListAdapter = new CommentListAdapter(comments, isMyVideo || Helper.isVideoOwner(PeertubeActivity.this, peertube)); + commentListAdapter = new CommentListAdapter(comments, isMyVideo || Helper.isVideoOwner(PeertubeActivity.this, peertube), false); commentListAdapter.allCommentRemoved = PeertubeActivity.this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this); binding.peertubeComments.setLayoutManager(mLayoutManager); @@ -419,6 +420,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } + binding.postCommentButton.setOnClickListener(v-> openPostComment(null, 0)); } @@ -459,7 +461,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } - public void manageVIewCommentReply(APIResponse apiResponse) { + public void manageVIewCommentReply(Comment comment, APIResponse apiResponse) { if (apiResponse == null || apiResponse.getError() != null || apiResponse.getCommentThreadData() == null) { if (apiResponse == null || apiResponse.getError() == null) Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); @@ -469,7 +471,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } List commentThreadDataList = apiResponse.getCommentThreadData().getChildren(); commentsThread = generateCommentReply(commentThreadDataList, new ArrayList<>()); - commentReplyListAdapter = new CommentListAdapter(commentsThread, Helper.isVideoOwner(PeertubeActivity.this, peertube)); + comment.setInReplyToCommentId(null); + comment.setTotalReplies(0); + commentsThread.add(0, comment); + commentReplyListAdapter = new CommentListAdapter(commentsThread, Helper.isVideoOwner(PeertubeActivity.this, peertube), true); LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this); binding.peertubeReply.setLayoutManager(mLayoutManager); binding.peertubeReply.setNestedScrollingEnabled(false); @@ -742,24 +747,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (!Helper.isLoggedIn(PeertubeActivity.this) || sepiaSearch) { binding.writeCommentContainer.setVisibility(View.GONE); - binding.writeCommentContainerReply.setVisibility(View.GONE); } - binding.send.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { - String comment = binding.addCommentWrite.getText().toString(); - if (comment.trim().length() > 0) { - PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); - viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, comment).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, 0, apiResponse1)); - binding.addCommentWrite.setText(""); - } - } else { - if (sepiaSearch) { - Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show(); - } else { - Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); - } - } - }); binding.peertubePlaylist.setOnClickListener(v -> { PlaylistsVM viewModelOwnerPlaylist = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); @@ -770,13 +758,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); commentViewModel.getThread(sepiaSearch ? peertubeInstance : null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { - binding.writeCommentContainerReply.setVisibility(View.VISIBLE); binding.writeCommentContainer.setVisibility(View.VISIBLE); } binding.peertubeComments.setVisibility(View.VISIBLE); } else { binding.peertubeComments.setVisibility(View.GONE); - binding.writeCommentContainerReply.setVisibility(View.GONE); binding.writeCommentContainer.setVisibility(View.GONE); binding.noActionText.setText(getString(R.string.comment_no_allowed_peertube)); binding.noAction.setVisibility(View.VISIBLE); @@ -1193,9 +1179,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd @Override public void onBackPressed() { - if (binding.replyThread.getVisibility() == View.VISIBLE) { + if(binding.postComment.getVisibility() == View.VISIBLE){ + closePostComment(); + } else if (binding.replyThread.getVisibility() == View.VISIBLE) { closeCommentThread(); - } else { + } else { if (playInMinimized && player != null) { enterVideoMode(); } else { @@ -1285,24 +1273,18 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd fullScreenDialog.show(); } - public void openCommentThread(Comment comment, int position) { + + + + + public void openCommentThread(Comment comment) { CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); binding.peertubeReply.setVisibility(View.GONE); - commentViewModel.getRepliesComment(videoUuid, comment.getId()).observe(PeertubeActivity.this, this::manageVIewCommentReply); + commentViewModel.getRepliesComment(videoUuid, comment.getId()).observe(PeertubeActivity.this, apiResponse->manageVIewCommentReply(comment, apiResponse)); + - Account account = comment.getAccount(); - Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.commentAccountProfile); - binding.commentAccountDisplayname.setText(account.getDisplayName()); - binding.commentAccountUsername.setText(account.getAcct()); - Spanned commentSpan; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - commentSpan = Html.fromHtml(comment.getText(), Html.FROM_HTML_MODE_COMPACT); - else - commentSpan = Html.fromHtml(comment.getText()); - binding.commentContent.setText(commentSpan); - binding.commentDate.setText(Helper.dateDiff(PeertubeActivity.this, comment.getCreatedAt())); binding.replyThread.setVisibility(View.VISIBLE); TranslateAnimation animate = new TranslateAnimation( binding.peertubeInformationContainer.getWidth(), @@ -1324,26 +1306,33 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } }); animate.setDuration(500); - binding.addCommentWriteReply.setText(String.format("@%s ", comment.getAccount().getAcct())); - binding.addCommentWriteReply.setSelection(binding.addCommentWriteReply.getText().length()); binding.replyThread.startAnimation(animate); - binding.sendReply.setOnClickListener(null); - binding.sendReply.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { - String commentView = binding.addCommentWriteReply.getText().toString(); + } + + private void sendComment(Comment comment, int position) { + if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { + if( comment == null) { + String commentStr = binding.addCommentWrite.getText().toString(); + if (commentStr.trim().length() > 0) { + PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); + viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, commentStr).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, 0, apiResponse1)); + binding.addCommentWrite.setText(""); + } + }else{ + String commentView = binding.addCommentWrite.getText().toString(); if (commentView.trim().length() > 0) { PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); viewModelComment.comment(REPLY, peertube.getId(), comment.getId(), commentView).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(REPLY, position, apiResponse1)); - binding.addCommentWriteReply.setText(""); - } - } else { - if (sepiaSearch) { - Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show(); - } else { - Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); + binding.addCommentWrite.setText(""); } } - }); + } else { + if (sepiaSearch) { + Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show(); + } else { + Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); + } + } } private void closeCommentThread() { @@ -1371,6 +1360,87 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd binding.replyThread.startAnimation(animate); } + + public void openPostComment(Comment comment, int position) { + if( comment != null) { + binding.replyContent.setVisibility(View.VISIBLE); + Account account = comment.getAccount(); + Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.commentAccountProfile); + binding.commentAccountDisplayname.setText(account.getDisplayName()); + binding.commentAccountUsername.setText(account.getAcct()); + Spanned commentSpan; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + commentSpan = Html.fromHtml(comment.getText(), Html.FROM_HTML_MODE_COMPACT); + else + commentSpan = Html.fromHtml(comment.getText()); + binding.commentContent.setText(commentSpan); + binding.commentDate.setText(Helper.dateDiff(PeertubeActivity.this, comment.getCreatedAt())); + }else{ + binding.replyContent.setVisibility(View.GONE); + } + binding.postComment.setVisibility(View.VISIBLE); + DisplayMetrics displayMetrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + int height = displayMetrics.heightPixels; + TranslateAnimation animateComment = new TranslateAnimation( + 0, + 0, + height, + binding.mediaVideo.getHeight()); + animateComment.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + } + + @Override + public void onAnimationEnd(Animation animation) { + binding.peertubeInformationContainer.setVisibility(View.GONE); + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + }); + animateComment.setDuration(500); + binding.postComment.startAnimation(animateComment); + if( comment != null) { + binding.addCommentWrite.setText(String.format("@%s ", comment.getAccount().getAcct())); + binding.addCommentWrite.setSelection(binding.addCommentWrite.getText().length()); + } + + binding.send.setOnClickListener(null); + binding.send.setOnClickListener(v-> sendComment(comment, position)); + } + + private void closePostComment() { + DisplayMetrics displayMetrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + int height = displayMetrics.heightPixels; + binding.peertubeInformationContainer.setVisibility(View.VISIBLE); + Log.v(Helper.TAG,"end: " + binding.mediaVideo.getHeight() + " - " + height); + TranslateAnimation animateComment = new TranslateAnimation( + 0, + 0, + binding.mediaVideo.getHeight(), + height); + animateComment.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + } + + @Override + public void onAnimationEnd(Animation animation) { + binding.postComment.setVisibility(View.GONE); + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + }); + animateComment.setDuration(500); + binding.postComment.startAnimation(animateComment); + } + @SuppressWarnings({"unused", "RedundantSuppression"}) public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int position, APIResponse apiResponse) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java index 27b648e..1a1ff61 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java @@ -33,6 +33,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; @@ -41,7 +42,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.widget.PopupMenu; -import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; @@ -59,15 +59,14 @@ import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.data.CommentData.Comment; import app.fedilab.fedilabtube.client.entities.Report; +import app.fedilab.fedilabtube.helper.CommentDecorationHelper; import app.fedilab.fedilabtube.helper.EmojiHelper; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; -import studio.carbonylgroup.textfieldboxes.ExtendedEditText; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY; -import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; public class CommentListAdapter extends RecyclerView.Adapter { @@ -78,11 +77,13 @@ public class CommentListAdapter extends RecyclerView.Adapter comments, boolean isVideoOwner) { + public CommentListAdapter(List comments, boolean isVideoOwner, boolean isThread) { this.comments = comments; commentListAdapter = this; this.isVideoOwner = isVideoOwner; + this.isThread = isThread; } @Override @@ -120,6 +121,19 @@ public class CommentListAdapter extends RecyclerView.Adapter { PopupMenu popup = new PopupMenu(context, holder.more_actions); popup.getMenuInflater() @@ -224,9 +238,10 @@ public class CommentListAdapter extends RecyclerView.Adapter ((PeertubeActivity) context).openCommentThread(comment, i)); - holder.comment_content.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment, i)); + + if (context instanceof PeertubeActivity && !isThread) { + holder.main_container.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment)); + holder.comment_content.setOnClickListener(v -> ((PeertubeActivity) context).openCommentThread(comment)); } if (comment.getTotalReplies() > 0) { holder.number_of_replies.setVisibility(View.VISIBLE); @@ -269,33 +284,13 @@ public class CommentListAdapter extends RecyclerView.Adapter { - comment.setReplyViewOpen(!comment.isReplyViewOpen()); - notifyItemChanged(i); - }); - - holder.send_reply.setOnClickListener(null); - holder.send_reply.setOnClickListener(v -> { - if (isLoggedIn(context)) { - String commentView = holder.add_comment_write_reply.getText().toString(); - if (commentView.trim().length() > 0) { - PostActionsVM viewModelComment = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class); - viewModelComment.comment(REPLY, comment.getVideoId(), comment.getId(), commentView).observe((LifecycleOwner) context, apiResponse1 -> manageVIewPostActions(REPLY, (int) holder.main_container.getTag(), apiResponse1)); - holder.add_comment_write_reply.setText(""); - comment.setReplyViewOpen(false); - notifyItemChanged(i); - } - } - }); + holder.post_reply_button.setOnClickListener(v -> ((PeertubeActivity) context).openPostComment(comment, i)); + holder.replyButton.setOnClickListener(v -> ((PeertubeActivity) context).openPostComment(comment, i)); } public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int i, APIResponse apiResponse) { @@ -361,13 +356,12 @@ public class CommentListAdapter extends RecyclerView.Adapter. */ +import java.util.List; + +import app.fedilab.fedilabtube.client.data.CommentData; + +public class CommentDecorationHelper { + + public static int getIndentation(String replyToCommentId, List comments){ + return numberOfIndentation(0, replyToCommentId, comments); + } + + private static int numberOfIndentation(int currentIdentation, String replyToCommentId, List comments) { + + String targetedComment = null; + for(CommentData.Comment comment: comments) { + if( replyToCommentId.compareTo(comment.getId()) == 0) { + targetedComment = comment.getInReplyToCommentId(); + break; + } + } + if ( targetedComment != null) { + currentIdentation++; + return numberOfIndentation(currentIdentation, targetedComment, comments); + }else{ + return Math.min(currentIdentation, 5); + } + } +} diff --git a/app/src/main/res/layout/activity_peertube.xml b/app/src/main/res/layout/activity_peertube.xml index f32c535..3726c61 100644 --- a/app/src/main/res/layout/activity_peertube.xml +++ b/app/src/main/res/layout/activity_peertube.xml @@ -244,80 +244,13 @@ android:textColor="?attr/colorAccent" android:layout_marginTop="2dp" /> - - - - - - - - - - - - - +