Fix a crash when starting the app with new elements in the list

This commit is contained in:
Thomas 2022-05-16 17:55:28 +02:00
parent b6f8dbf1ce
commit 0c8f2a4a03
4 changed files with 25 additions and 29 deletions

View file

@ -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);

View file

@ -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();
};

View file

@ -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);
}

View file

@ -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);
new Pinned(activity).updatePinned(pinned);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
}
}
@ -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.position = pinned.pinnedTimelines.size();
pinnedTimeline.mastodonList = mastodonList;
finalPinned1.pinnedTimelines.add(pinnedTimeline);
pinned.pinnedTimelines.add(pinnedTimeline);
try {
boolean exist = new Pinned(activity).pinnedExist(finalPinned1);
boolean exist = new Pinned(activity).pinnedExist(pinned);
if (exist) {
new Pinned(activity).updatePinned(finalPinned1);
new Pinned(activity).updatePinned(pinned);
} else {
new Pinned(activity).insertPinned(finalPinned1);
new Pinned(activity).insertPinned(pinned);
}
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
}
}