From 2f3e29b037764754f56f83de8951f36c4ac0ff0b Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 14 Nov 2020 17:52:17 +0100 Subject: [PATCH] Improve comments --- .../fedilab/fedilabtube/PeertubeActivity.java | 23 +++++++++++-------- app/src/main/res/layout/activity_peertube.xml | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 94727ee..7563762 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -1263,12 +1263,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd 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, apiResponse -> manageVIewCommentReply(comment, apiResponse)); - binding.replyThread.setVisibility(View.VISIBLE); TranslateAnimation animate = new TranslateAnimation( binding.peertubeInformationContainer.getWidth(), @@ -1279,12 +1277,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd @Override public void onAnimationStart(Animation animation) { } - @Override public void onAnimationEnd(Animation animation) { binding.peertubeInformationContainer.setVisibility(View.GONE); } - @Override public void onAnimationRepeat(Animation animation) { } @@ -1296,20 +1292,21 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private void sendComment(Comment comment, int position) { if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { if (comment == null) { - String commentStr = binding.addCommentWrite.getText().toString(); + String commentStr = binding.addCommentWrite.getText() != null ? 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(); + String commentView = binding.addCommentWrite.getText() != null ? 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.addCommentWrite.setText(""); } } + closePostComment(); } else { if (sepiaSearch) { 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() { binding.peertubeInformationContainer.setVisibility(View.VISIBLE); + hideKeyboard(this); TranslateAnimation animate = new TranslateAnimation( 0, binding.replyThread.getWidth(), @@ -1369,7 +1367,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd 0, 0, height, - binding.mediaVideo.getHeight()); + 0); animateComment.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { @@ -1378,6 +1376,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd @Override public void onAnimationEnd(Animation animation) { 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 @@ -1388,7 +1392,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd binding.postComment.startAnimation(animateComment); if (comment != null) { 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); @@ -1400,10 +1404,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int height = displayMetrics.heightPixels; binding.peertubeInformationContainer.setVisibility(View.VISIBLE); + hideKeyboard(this); TranslateAnimation animateComment = new TranslateAnimation( 0, 0, - binding.mediaVideo.getHeight(), + 0, height); animateComment.setAnimationListener(new Animation.AnimationListener() { @Override diff --git a/app/src/main/res/layout/activity_peertube.xml b/app/src/main/res/layout/activity_peertube.xml index 68e6d82..2c2adf9 100644 --- a/app/src/main/res/layout/activity_peertube.xml +++ b/app/src/main/res/layout/activity_peertube.xml @@ -335,6 +335,7 @@ android:orientation="vertical" android:showDividers="end">