aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-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();