From a0e11d19c0624dce5f716070e7ae82fed8b05e24 Mon Sep 17 00:00:00 2001 From: Cato the Cat Date: Wed, 25 Dec 2024 21:24:45 +0300 Subject: [PATCH] Fix random post closing errors --- .../main/java/com/cato/glasssky/Timeline.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/cato/glasssky/Timeline.java b/app/src/main/java/com/cato/glasssky/Timeline.java index 5c9c0d5..848e05f 100644 --- a/app/src/main/java/com/cato/glasssky/Timeline.java +++ b/app/src/main/java/com/cato/glasssky/Timeline.java @@ -216,14 +216,16 @@ public void onImageLoaded(Bitmap bitmap) { } catch (JSONException e) { throw new RuntimeException(e); } - if(!text.isEmpty()) { - extraCards = images.length() + 5; - mCardScrollView.setSelection(extraCards - (images.length() + 1)); - } else { - extraCards = images.length() + 4; - mCardScrollView.setSelection(extraCards - (images.length())); - } - mAdapter.notifyDataSetChanged(); + runOnUiThread(() -> { + if(!text.isEmpty()) { + extraCards = images.length() + 5; + mCardScrollView.setSelection(extraCards - (images.length() + 1)); + } else { + extraCards = images.length() + 4; + mCardScrollView.setSelection(extraCards - (images.length())); + } + mAdapter.notifyDataSetChanged(); + }); SetPosts(responseArray); } } @@ -256,8 +258,10 @@ public void onImageLoaded(Bitmap bitmap) { } else { extraCards = 5; } - mCardScrollView.setSelection(extraCards - 2); - mAdapter.notifyDataSetChanged(); + runOnUiThread(() -> { + mCardScrollView.setSelection(extraCards - 2); + mAdapter.notifyDataSetChanged(); + }); SetPosts(responseArray); } });