Improve comments

This commit is contained in:
Thomas 2020-11-14 17:52:17 +01:00
parent dad94d753d
commit 2f3e29b037
2 changed files with 15 additions and 9 deletions

View File

@ -1263,12 +1263,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
public void openCommentThread(Comment comment) { public void openCommentThread(Comment comment) {
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
binding.peertubeReply.setVisibility(View.GONE); binding.peertubeReply.setVisibility(View.GONE);
commentViewModel.getRepliesComment(videoUuid, comment.getId()).observe(PeertubeActivity.this, apiResponse -> manageVIewCommentReply(comment, apiResponse)); commentViewModel.getRepliesComment(videoUuid, comment.getId()).observe(PeertubeActivity.this, apiResponse -> manageVIewCommentReply(comment, apiResponse));
binding.replyThread.setVisibility(View.VISIBLE); binding.replyThread.setVisibility(View.VISIBLE);
TranslateAnimation animate = new TranslateAnimation( TranslateAnimation animate = new TranslateAnimation(
binding.peertubeInformationContainer.getWidth(), binding.peertubeInformationContainer.getWidth(),
@ -1279,12 +1277,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override @Override
public void onAnimationStart(Animation animation) { public void onAnimationStart(Animation animation) {
} }
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
binding.peertubeInformationContainer.setVisibility(View.GONE); binding.peertubeInformationContainer.setVisibility(View.GONE);
} }
@Override @Override
public void onAnimationRepeat(Animation animation) { public void onAnimationRepeat(Animation animation) {
} }
@ -1296,20 +1292,21 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private void sendComment(Comment comment, int position) { private void sendComment(Comment comment, int position) {
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
if (comment == null) { if (comment == null) {
String commentStr = binding.addCommentWrite.getText().toString(); String commentStr = binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().toString() : "";
if (commentStr.trim().length() > 0) { if (commentStr.trim().length() > 0) {
PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); 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)); viewModelComment.comment(ADD_COMMENT, peertube.getId(), null, commentStr).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(ADD_COMMENT, 0, apiResponse1));
binding.addCommentWrite.setText(""); binding.addCommentWrite.setText("");
} }
} else { } else {
String commentView = binding.addCommentWrite.getText().toString(); String commentView = binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().toString() : "";
if (commentView.trim().length() > 0) { if (commentView.trim().length() > 0) {
PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); 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)); viewModelComment.comment(REPLY, peertube.getId(), comment.getId(), commentView).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(REPLY, position, apiResponse1));
binding.addCommentWrite.setText(""); binding.addCommentWrite.setText("");
} }
} }
closePostComment();
} else { } else {
if (sepiaSearch) { if (sepiaSearch) {
Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show(); Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show();
@ -1321,6 +1318,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private void closeCommentThread() { private void closeCommentThread() {
binding.peertubeInformationContainer.setVisibility(View.VISIBLE); binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
hideKeyboard(this);
TranslateAnimation animate = new TranslateAnimation( TranslateAnimation animate = new TranslateAnimation(
0, 0,
binding.replyThread.getWidth(), binding.replyThread.getWidth(),
@ -1369,7 +1367,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
0, 0,
0, 0,
height, height,
binding.mediaVideo.getHeight()); 0);
animateComment.setAnimationListener(new Animation.AnimationListener() { animateComment.setAnimationListener(new Animation.AnimationListener() {
@Override @Override
public void onAnimationStart(Animation animation) { public void onAnimationStart(Animation animation) {
@ -1378,6 +1376,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
binding.peertubeInformationContainer.setVisibility(View.GONE); binding.peertubeInformationContainer.setVisibility(View.GONE);
InputMethodManager inputMethodManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(
binding.addCommentWrite.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
binding.addCommentWrite.requestFocus();
} }
@Override @Override
@ -1388,7 +1392,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.postComment.startAnimation(animateComment); binding.postComment.startAnimation(animateComment);
if (comment != null) { if (comment != null) {
binding.addCommentWrite.setText(String.format("@%s ", comment.getAccount().getAcct())); binding.addCommentWrite.setText(String.format("@%s ", comment.getAccount().getAcct()));
binding.addCommentWrite.setSelection(binding.addCommentWrite.getText().length()); binding.addCommentWrite.setSelection(binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().length() : 0);
} }
binding.send.setOnClickListener(null); binding.send.setOnClickListener(null);
@ -1400,10 +1404,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels; int height = displayMetrics.heightPixels;
binding.peertubeInformationContainer.setVisibility(View.VISIBLE); binding.peertubeInformationContainer.setVisibility(View.VISIBLE);
hideKeyboard(this);
TranslateAnimation animateComment = new TranslateAnimation( TranslateAnimation animateComment = new TranslateAnimation(
0, 0,
0, 0,
binding.mediaVideo.getHeight(), 0,
height); height);
animateComment.setAnimationListener(new Animation.AnimationListener() { animateComment.setAnimationListener(new Animation.AnimationListener() {
@Override @Override

View File

@ -335,6 +335,7 @@
android:orientation="vertical" android:orientation="vertical"
android:showDividers="end"> android:showDividers="end">
<ImageView <ImageView
android:layout_margin="5dp"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:id="@+id/close_post" android:id="@+id/close_post"
android:layout_width="24dp" android:layout_width="24dp"