From 0c8f2a4a03cea470b261c07d96772e65ae73adc6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 16 May 2022 17:55:28 +0200 Subject: [PATCH] Fix a crash when starting the app with new elements in the list --- .../app/fedilab/android/BaseMainActivity.java | 4 +- .../android/activities/LoginActivity.java | 2 +- .../app/fedilab/android/helper/Helper.java | 3 +- .../android/helper/PinnedTimelineHelper.java | 45 ++++++++----------- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index b65159f4..fc6825c3 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -613,7 +613,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, null); //Fetch remote lists for the authenticated account and update them new ViewModelProvider(BaseMainActivity.this).get(TimelinesVM.class).getLists(currentInstance, currentToken) - .observe(this, mastodonLists -> PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, mastodonLists)); + .observe(this, mastodonLists -> + PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, mastodonLists) + ); }); }; mainHandler.post(myRunnable); diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java index 3241a41c..a7188eba 100644 --- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java @@ -122,7 +122,7 @@ public class LoginActivity extends BaseActivity { //The user is now authenticated, it will be redirected to MainActivity Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { - Intent mainActivity = new Intent(LoginActivity.this, BaseMainActivity.class); + Intent mainActivity = new Intent(LoginActivity.this, MainActivity.class); startActivity(mainActivity); finish(); }; diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 8bb6a022..1a54553a 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -121,6 +121,7 @@ import java.util.regex.Pattern; import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.activities.LoginActivity; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.WebviewActivity; import app.fedilab.android.broadcastreceiver.ToastMessage; import app.fedilab.android.client.entities.Account; @@ -629,7 +630,7 @@ public class Helper { BaseMainActivity.currentToken = newAccount.token; BaseMainActivity.currentInstance = newAccount.instance; editor.apply(); - Intent changeAccount = new Intent(activity, BaseMainActivity.class); + Intent changeAccount = new Intent(activity, MainActivity.class); changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); activity.startActivity(changeAccount); } diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 9a6f9bff..979af166 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -93,14 +93,11 @@ public class PinnedTimelineHelper { if (!present) { pinnedToRemove.add(pinnedTimeline); needRedraw = true; //Something changed, redraw must be done - Pinned finalPinned2 = pinned; - new Thread(() -> { - try { - new Pinned(activity).updatePinned(finalPinned2); - } catch (DBException e) { - e.printStackTrace(); - } - }).start(); + try { + new Pinned(activity).updatePinned(pinned); + } catch (DBException e) { + e.printStackTrace(); + } } } } @@ -118,26 +115,22 @@ public class PinnedTimelineHelper { } //Needs to be added if (!present) { - Pinned finalPinned1 = pinned; needRedraw = true; //Something changed, redraw must be done - new Thread(() -> { - PinnedTimeline pinnedTimeline = new PinnedTimeline(); - pinnedTimeline.type = Timeline.TimeLineEnum.LIST; - pinnedTimeline.position = finalPinned1.pinnedTimelines.size(); - pinnedTimeline.mastodonList = mastodonList; - finalPinned1.pinnedTimelines.add(pinnedTimeline); - try { - boolean exist = new Pinned(activity).pinnedExist(finalPinned1); - if (exist) { - new Pinned(activity).updatePinned(finalPinned1); - } else { - new Pinned(activity).insertPinned(finalPinned1); - } - } catch (DBException e) { - e.printStackTrace(); + PinnedTimeline pinnedTimeline = new PinnedTimeline(); + pinnedTimeline.type = Timeline.TimeLineEnum.LIST; + pinnedTimeline.position = pinned.pinnedTimelines.size(); + pinnedTimeline.mastodonList = mastodonList; + pinned.pinnedTimelines.add(pinnedTimeline); + try { + boolean exist = new Pinned(activity).pinnedExist(pinned); + if (exist) { + new Pinned(activity).updatePinned(pinned); + } else { + new Pinned(activity).insertPinned(pinned); } - }).start(); - + } catch (DBException e) { + e.printStackTrace(); + } } } }