From bba6a2edf157fcf780ae7e0a96b6af2117804b1c Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 27 Jan 2024 17:58:14 +0100 Subject: [PATCH] Fix a crash with profiles --- .../client/entities/app/CachedBundle.java | 23 +++++++++++++++++-- .../timeline/FragmentMastodonTimeline.java | 1 - 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java index 870ea680..06d6e168 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java @@ -14,8 +14,12 @@ package app.fedilab.android.mastodon.client.entities.app; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; + import android.content.ContentValues; import android.content.Context; +import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; @@ -24,6 +28,8 @@ import android.os.Looper; import android.os.Parcel; import android.util.Base64; +import androidx.preference.PreferenceManager; + import com.google.gson.annotations.SerializedName; import java.io.BufferedOutputStream; @@ -35,6 +41,7 @@ import java.util.Date; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import app.fedilab.android.MainApplication; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.exception.DBException; @@ -206,9 +213,15 @@ public class CachedBundle { if (db == null) { throw new DBException("db is null. Wrong initialization."); } - if (account == null || target_id == null) { + if (target_id == null) { return null; } + if (account == null) { + account = new BaseAccount(); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + account.user_id = sharedpreferences.getString(PREF_USER_ID, null); + account.instance = sharedpreferences.getString(PREF_USER_INSTANCE, null); + } try { Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " + Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " @@ -235,9 +248,15 @@ public class CachedBundle { if (db == null) { throw new DBException("db is null. Wrong initialization."); } - if (account == null || target_id == null) { + if (target_id == null) { return null; } + if (account == null) { + account = new BaseAccount(); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + account.user_id = sharedpreferences.getString(PREF_USER_ID, null); + account.instance = sharedpreferences.getString(PREF_USER_INSTANCE, null); + } try { Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " + Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index d5a34091..ece06dd4 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -375,7 +375,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. binding.swipeContainer.setRefreshing(false); binding.swipeContainer.setEnabled(false); } - if (arguments != null) { long bundleId = arguments.getLong(Helper.ARG_INTENT_ID, -1); if (bundleId != -1) {