aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-06 13:04:02 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-06 13:04:02 +0000
commit236b6b66f1bc60bdcec1322367f0239174e2d802 (patch)
tree57bef35ffb6958b059ec36274b2a576aa6a8e10e /app/src/main/java/ml/docilealligator/infinityforreddit
parent372f373601ddb0abdc81f732bd6d2b58e67a4dfa (diff)
downloadinfinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.tar
infinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.tar.gz
infinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.tar.bz2
infinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.tar.lz
infinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.tar.xz
infinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.tar.zst
infinity-for-reddit-236b6b66f1bc60bdcec1322367f0239174e2d802.zip
Scroll to bottom if new comments arrive in ViewRPANBroadcastFragment.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
index 4eed627c..5fa26888 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
@@ -16,6 +16,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.ExoPlaybackException;
@@ -267,7 +268,21 @@ public class ViewRPANBroadcastFragment extends Fragment {
payload.getString(JSONUtils.BODY_KEY),
payload.getLong(JSONUtils.CREATED_UTC_KEY));
- handler.post(() -> adapter.addRPANComment(rpanComment));
+ handler.post(() -> {
+ LinearLayoutManager manager = ((LinearLayoutManager) recyclerView.getLayoutManager());
+ boolean shouldScrollToBottom = false;
+ if (manager != null) {
+ int lastPosition = manager.findLastCompletelyVisibleItemPosition();
+ int currentItemCount = adapter.getItemCount();
+ if (currentItemCount > 0 && lastPosition == currentItemCount - 1) {
+ shouldScrollToBottom = true;
+ }
+ }
+ adapter.addRPANComment(rpanComment);
+ if (shouldScrollToBottom) {
+ recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);
+ }
+ });
}
} catch (JSONException e) {
e.printStackTrace();