From 2edfd8c9452164f110ff87c629b17cdd36dff5f8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 9 Jan 2024 15:57:12 +0100 Subject: All accounts are cached in db before being in Intent --- .../java/app/fedilab/android/BaseMainActivity.java | 8 +- .../fedilab/android/activities/AboutActivity.java | 4 +- .../mastodon/activities/AccountReportActivity.java | 4 +- .../mastodon/activities/ComposeActivity.java | 2 +- .../mastodon/activities/EditProfileActivity.java | 2 +- .../mastodon/activities/PartnerShipActivity.java | 4 +- .../mastodon/activities/ProfileActivity.java | 12 +- .../mastodon/activities/ReportActivity.java | 8 +- .../mastodon/activities/TimelineActivity.java | 4 +- .../activities/admin/AdminAccountActivity.java | 4 +- .../activities/admin/AdminReportActivity.java | 4 +- .../mastodon/client/entities/app/CachedBundle.java | 166 ++++++++++++++++++++- .../android/mastodon/helper/CrossActionHelper.java | 8 +- .../fedilab/android/mastodon/helper/Helper.java | 77 +++++----- .../android/mastodon/helper/SpannableHelper.java | 8 +- .../android/mastodon/ui/drawer/AccountAdapter.java | 10 +- .../ui/drawer/AccountFollowRequestAdapter.java | 4 +- .../ui/drawer/AccountsSearchTopBarAdapter.java | 4 +- .../mastodon/ui/drawer/NotificationAdapter.java | 11 +- .../android/mastodon/ui/drawer/StatusAdapter.java | 12 +- .../mastodon/ui/drawer/SuggestionAdapter.java | 4 +- .../ui/drawer/admin/AdminAccountAdapter.java | 4 +- .../ui/fragment/media/FragmentMediaProfile.java | 4 +- .../fragment/timeline/FragmentMastodonAccount.java | 5 +- .../timeline/FragmentMastodonTimeline.java | 3 +- .../fragment/timeline/FragmentProfileTimeline.java | 6 +- .../ui/pageadapter/FedilabProfilePageAdapter.java | 6 +- .../pageadapter/FedilabProfileTLPageAdapter.java | 4 +- .../java/app/fedilab/android/sqlite/Sqlite.java | 7 +- .../FragmentLoginPickInstanceMastodon.java | 4 +- 30 files changed, 295 insertions(+), 108 deletions(-) (limited to 'app') diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index ff07e4b1e..8c321234c 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -662,7 +662,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intentAccount = new Intent(activity, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(activity).insertBundle(args, bundleId -> { + new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { Bundle bundleCached = new Bundle(); bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId); intentAccount.putExtras(bundleCached); @@ -673,7 +673,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intentContext = new Intent(activity, ContextActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_STATUS, status); - new CachedBundle(activity).insertBundle(args, bundleId -> { + new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { Bundle bundleCached = new Bundle(); bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId); intentContext.putExtras(bundleCached); @@ -1048,7 +1048,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intent = new Intent(activity, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(activity).insertBundle(args, bundleId -> { + new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1435,7 +1435,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, currentAccount.mastodon_account); - new CachedBundle(BaseMainActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(BaseMainActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java index ee6862df3..fe57ba51e 100644 --- a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -122,7 +124,7 @@ public class AboutActivity extends BaseBarActivity { Intent intent = new Intent(AboutActivity.this, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(AboutActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(AboutActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java index 46c3e9d3a..72bd611bd 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.app.Activity; import android.graphics.PorterDuff; import android.os.Bundle; @@ -66,7 +68,7 @@ public class AccountReportActivity extends BaseBarActivity { Bundle args = getIntent().getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(AccountReportActivity.this).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(AccountReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(null); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index 36b9082e3..5c52063d3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -488,7 +488,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana if(b != null) { long bundleId = b.getLong(Helper.ARG_INTENT_ID, -1); if(bundleId != -1 ) { - new CachedBundle(ComposeActivity.this).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(b); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java index c0b895510..77fa5ce5f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java @@ -263,7 +263,7 @@ public class EditProfileActivity extends BaseBarActivity { Bundle args = new Bundle(); args.putBoolean(Helper.RECEIVE_REDRAW_PROFILE, true); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(EditProfileActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(EditProfileActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); Intent intentBD = new Intent(Helper.BROADCAST_DATA); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java index 53905ab8c..7c1e9037b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -81,7 +83,7 @@ public class PartnerShipActivity extends BaseBarActivity { Intent intent = new Intent(PartnerShipActivity.this, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(PartnerShipActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(PartnerShipActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java index b0b10452f..1106067de 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java @@ -137,7 +137,7 @@ public class ProfileActivity extends BaseActivity { if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); if(bundleId != -1 ) { - new CachedBundle(ProfileActivity.this).getBundle(bundleId, bundle -> { + new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, bundle -> { Account accountReceived = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); if (bundle.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) { if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) { @@ -190,7 +190,7 @@ public class ProfileActivity extends BaseActivity { homeMuted = false; if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(ProfileActivity.this).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(null); } @@ -468,7 +468,7 @@ public class ProfileActivity extends BaseActivity { Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); args.putSerializable(Helper.ARG_CHECK_REMOTELY, true); - new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(ProfileActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -655,7 +655,7 @@ public class ProfileActivity extends BaseActivity { Intent intent = new Intent(ProfileActivity.this, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(ProfileActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1055,7 +1055,7 @@ public class ProfileActivity extends BaseActivity { Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT_MENTION, account); args.putString(Helper.ARG_VISIBILITY, "direct"); - new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(ProfileActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1146,7 +1146,7 @@ public class ProfileActivity extends BaseActivity { intent = new Intent(ProfileActivity.this, ComposeActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT_MENTION, account); - new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(ProfileActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java index 0f3c3e55b..4107a5724 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.activities; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.os.Bundle; import android.view.MenuItem; import android.view.View; @@ -75,7 +77,7 @@ public class ReportActivity extends BaseBarActivity { if(args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); if(bundleId != -1 ) { - new CachedBundle(ReportActivity.this).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(ReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(args); } @@ -241,7 +243,7 @@ public class ReportActivity extends BaseBarActivity { status.isChecked = true; args.putSerializable(Helper.ARG_STATUS_REPORT, status); } - new CachedBundle(ReportActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(ReportActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); fragment.setArguments(bundle); @@ -271,7 +273,7 @@ public class ReportActivity extends BaseBarActivity { status.isChecked = true; args.putSerializable(Helper.ARG_STATUS_REPORT, status); } - new CachedBundle(ReportActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(ReportActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); fragment.setArguments(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java index 8fc81746e..cb2e11097 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/TimelineActivity.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.activities; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.os.Bundle; import android.view.MenuItem; @@ -65,7 +67,7 @@ public class TimelineActivity extends BaseBarActivity { if (status != null) { args.putSerializable(Helper.ARG_STATUS, status); } - new CachedBundle(TimelineActivity.this).insertBundle(args, bundleId -> { + new CachedBundle(TimelineActivity.this).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); fragmentMastodonTimeline.setArguments(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java index 7f0794c34..a78191e5c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities.admin; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.ClipData; import android.content.ClipboardManager; import android.content.Intent; @@ -99,7 +101,7 @@ public class AdminAccountActivity extends BaseActivity { if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(AdminAccountActivity.this).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(AdminAccountActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(null); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java index cc11c694f..fb170a487 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities.admin; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.ClipData; import android.content.ClipboardManager; import android.content.Intent; @@ -105,7 +107,7 @@ public class AdminReportActivity extends BaseBarActivity { if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(AdminReportActivity.this).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(AdminReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(null); } 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 87e7163ce..718023b93 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 @@ -24,6 +24,8 @@ import android.os.Looper; import android.os.Parcel; import android.util.Base64; +import com.google.gson.annotations.SerializedName; + import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -32,6 +34,7 @@ import java.util.Date; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.sqlite.Sqlite; @@ -43,6 +46,10 @@ public class CachedBundle { public String id; public Bundle bundle; + public CacheType cacheType; + public String instance; + public String user_id; + public String target_id; public Date created_at; private SQLiteDatabase db; @@ -64,14 +71,46 @@ public class CachedBundle { * @return long - db id * @throws DBException exception with database */ - private long insertIntent(Bundle bundle) throws DBException { + private long insertIntent(Bundle bundle, BaseAccount currentUser) throws DBException { if (db == null) { throw new DBException("db is null. Wrong initialization."); } ContentValues values = new ContentValues(); values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle)); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); - //Inserts token + values.put(Sqlite.COL_TYPE, CacheType.ARGS.getValue()); + if( bundle.containsKey(Helper.ARG_ACCOUNT) && currentUser != null) { + ContentValues valuesAccount = new ContentValues(); + Bundle bundleAccount = new Bundle(); + Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); + if(account != null) { + bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account); + valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount)); + valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); + valuesAccount.put(Sqlite.COL_TARGET_ID, account.user_id); + valuesAccount.put(Sqlite.COL_USER_ID, currentUser.user_id); + valuesAccount.put(Sqlite.COL_INSTANCE, currentUser.instance); + valuesAccount.put(Sqlite.COL_TYPE, CacheType.ACCOUNT.getValue()); + removeIntent(currentUser, account.user_id); + db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount); + } + } + if( bundle.containsKey(Helper.ARG_STATUS) && currentUser != null) { + ContentValues valuesAccount = new ContentValues(); + Bundle bundleStatus = new Bundle(); + Status status = (Status) bundle.getSerializable(Helper.ARG_STATUS); + if(status != null) { + bundleStatus.putSerializable(Helper.ARG_STATUS, status); + valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleStatus)); + valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); + valuesAccount.put(Sqlite.COL_TARGET_ID, status.id); + valuesAccount.put(Sqlite.COL_USER_ID, currentUser.user_id); + valuesAccount.put(Sqlite.COL_INSTANCE, currentUser.instance); + valuesAccount.put(Sqlite.COL_TYPE, CacheType.STATUS.getValue()); + removeIntent(currentUser, status.id); + db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount); + } + } try { return db.insertOrThrow(Sqlite.TABLE_INTENT, null, values); } catch (Exception e) { @@ -81,20 +120,32 @@ public class CachedBundle { } public interface BundleCallback{ - public void get(Bundle bundle); + void get(Bundle bundle); } public interface BundleInsertCallback{ - public void inserted(long bundleId); + void inserted(long bundleId); } - public void getBundle(long id, BundleCallback callback) { + public void getBundle(long id, BaseAccount Account, BundleCallback callback) { new Thread(()->{ Bundle bundle = null; try { CachedBundle cachedBundle = getCachedBundle(String.valueOf(id)); if (cachedBundle != null) { bundle = cachedBundle.bundle; + if(bundle != null && bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { + Account cachedAccount = getCachedAccount(Account, bundle.getString(Helper.ARG_CACHED_ACCOUNT_ID)); + if(cachedAccount != null) { + bundle.putSerializable(Helper.ARG_ACCOUNT, cachedAccount); + } + } + if(bundle != null && bundle.containsKey(Helper.ARG_CACHED_STATUS_ID)) { + Status cachedStatus = getCachedStatus(Account, bundle.getString(Helper.ARG_CACHED_STATUS_ID)); + if(cachedStatus != null) { + bundle.putSerializable(Helper.ARG_STATUS, cachedStatus); + } + } } removeIntent(String.valueOf(id)); } catch (DBException ignored) {} @@ -105,11 +156,11 @@ public class CachedBundle { }).start(); } - public void insertBundle(Bundle bundle, BundleInsertCallback callback) { + public void insertBundle(Bundle bundle, BaseAccount Account, BundleInsertCallback callback) { new Thread(()->{ long dbBundleId = -1; try { - dbBundleId = insertIntent(bundle); + dbBundleId = insertIntent(bundle, Account); } catch (DBException ignored) {} Handler mainHandler = new Handler(Looper.getMainLooper()); long finalDbBundleId = dbBundleId; @@ -118,6 +169,66 @@ public class CachedBundle { }).start(); } + + + /** + * Returns a bundle by targeted account id + * + * @param target_id String + * @return Account {@link Account} + */ + private Account getCachedAccount(BaseAccount account, String target_id) throws DBException { + if (db == null) { + throw new DBException("db is null. Wrong initialization."); + } + if(account == null || target_id == null) { + return null; + } + try { + Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " + + Sqlite.COL_INSTANCE + " = '" + account.instance+ "' AND " + + Sqlite.COL_TYPE + " = '" + CacheType.ACCOUNT.getValue() + "' AND " + + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); + CachedBundle cachedBundle = cursorToCachedBundle(c); + if(cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT) ) { + return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT); + } + } catch (Exception e) { + return null; + } + return null; + } + + + /** + * Returns a bundle by targeted status id + * + * @param target_id String + * @return Status {@link Status} + */ + private Status getCachedStatus(BaseAccount account, String target_id) throws DBException { + if (db == null) { + throw new DBException("db is null. Wrong initialization."); + } + if(account == null || target_id == null) { + return null; + } + try { + Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " + + Sqlite.COL_INSTANCE + " = '" + account.instance+ "' AND " + + Sqlite.COL_TYPE + " = '" + CacheType.STATUS.getValue() + "' AND " + + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); + CachedBundle cachedBundle = cursorToCachedBundle(c); + if(cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_STATUS) ) { + return (Status) cachedBundle.bundle.getSerializable(Helper.ARG_STATUS); + } + } catch (Exception e) { + return null; + } + return null; + } + + /** * Returns a bundle by its ID * @@ -149,6 +260,22 @@ public class CachedBundle { } + /** + * Remove a bundle from db + * + */ + private void removeIntent(BaseAccount account, String target_id) throws DBException { + if (db == null) { + throw new DBException("db is null. Wrong initialization."); + } + if(account == null || target_id == null) { + return; + } + db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " + + Sqlite.COL_INSTANCE + " = '" + account.instance+ "' AND " + + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null); + } + /*** * Method to hydrate an CachedBundle from database @@ -174,12 +301,16 @@ public class CachedBundle { * Read cursor and hydrate without closing it * * @param c - Cursor - * @return BaseAccount + * @return Account */ private CachedBundle convertCursorToCachedBundle(Cursor c) { CachedBundle cachedBundle = new CachedBundle(); cachedBundle.id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ID)); cachedBundle.bundle = deserializeBundle(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_BUNDLE))); + cachedBundle.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID)); + cachedBundle.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE)); + cachedBundle.target_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_TARGET_ID)); + cachedBundle.cacheType = CacheType.valueOf(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_TYPE))); cachedBundle.created_at = Helper.stringToDate(context, c.getString(c.getColumnIndexOrThrow(Sqlite.COL_CREATED_AT))); return cachedBundle; } @@ -225,4 +356,23 @@ public class CachedBundle { return bundle; } + + public enum CacheType { + @SerializedName("ARGS") + ARGS("ARGS"), + @SerializedName("ACCOUNT") + ACCOUNT("ACCOUNT"), + @SerializedName("STATUS") + STATUS("STATUS"); + + private final String value; + + CacheType(String value) { + this.value = value; + } + public String getValue() { + return value; + } + } + } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/CrossActionHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/CrossActionHelper.java index 61a873bc6..35a236acc 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/CrossActionHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/CrossActionHelper.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.helper; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -249,7 +251,7 @@ public class CrossActionHelper { Bundle args = new Bundle(); args.putSerializable(Helper.ARG_STATUS_REPLY, targetedStatus); args.putSerializable(Helper.ARG_ACCOUNT, ownerAccount); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -260,7 +262,7 @@ public class CrossActionHelper { Intent intentCompose = new Intent(context, ComposeActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, ownerAccount); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intentCompose.putExtras(bundle); @@ -443,7 +445,7 @@ public class CrossActionHelper { final BaseAccount account = accountArray[which]; Intent intentToot = new Intent(context, ComposeActivity.class); bundle.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(context).insertBundle(bundle, bundleId -> { + new CachedBundle(context).insertBundle(bundle, currentAccount, bundleId -> { Bundle bundleCached = new Bundle(); bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId); intentToot.putExtras(bundleCached); diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index ca23f9b30..c686d2cf3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -244,6 +244,8 @@ public class Helper { public static final String ARG_STATUS_REPLY_ID = "ARG_STATUS_REPLY_ID"; public static final String ARG_ACCOUNT = "ARG_ACCOUNT"; public static final String ARG_ACCOUNT_ID = "ARG_ACCOUNT_ID"; + public static final String ARG_CACHED_ACCOUNT_ID = "ARG_CACHED_ACCOUNT_ID"; + public static final String ARG_CACHED_STATUS_ID = "ARG_CACHED_STATUS_ID"; public static final String ARG_ADMIN_DOMAINBLOCK = "ARG_ADMIN_DOMAINBLOCK"; public static final String ARG_ADMIN_DOMAINBLOCK_DELETE = "ARG_ADMIN_DOMAINBLOCK_DELETE"; public static final String FEDILAB_MUTED_HASHTAGS = "Fedilab muted hashtags"; @@ -1557,49 +1559,50 @@ public class Helper { String channelTitle; switch (notifType) { - case FAV: + case FAV -> { channelId = "channel_favourite"; channelTitle = context.getString(R.string.channel_notif_fav); - break; - case FOLLLOW: + } + case FOLLLOW -> { channelId = "channel_follow"; channelTitle = context.getString(R.string.channel_notif_follow); - break; - case MENTION: + } + case MENTION -> { channelId = "channel_mention"; channelTitle = context.getString(R.string.channel_notif_mention); - break; - case POLL: + } + case POLL -> { channelId = "channel_poll"; channelTitle = context.getString(R.string.channel_notif_poll); - break; - case BACKUP: + } + case BACKUP -> { channelId = "channel_backup"; channelTitle = context.getString(R.string.channel_notif_backup); - break; - case STORE: + } + case STORE -> { channelId = "channel_media"; channelTitle = context.getString(R.string.channel_notif_media); - break; - case TOOT: + } + case TOOT -> { channelId = "channel_status"; channelTitle = context.getString(R.string.channel_notif_status); - break; - case UPDATE: + } + case UPDATE -> { channelId = "channel_update"; channelTitle = context.getString(R.string.channel_notif_update); - break; - case SIGN_UP: + } + case SIGN_UP -> { channelId = "channel_signup"; channelTitle = context.getString(R.string.channel_notif_signup); - break; - case REPORT: + } + case REPORT -> { channelId = "channel_report"; channelTitle = context.getString(R.string.channel_notif_report); - break; - default: + } + default -> { channelId = "channel_boost"; channelTitle = context.getString(R.string.channel_notif_boost); + } } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) .setSmallIcon(getNotificationIcon(context)).setTicker(message); @@ -1615,24 +1618,18 @@ public class Helper { int prefColor; prefColor = Integer.parseInt(sharedpreferences.getString(context.getString(R.string.SET_LED_COLOUR_VAL_N), String.valueOf(LED_COLOUR))); switch (prefColor) { - case 1: // CYAN - ledColour = Color.CYAN; - break; - case 2: // MAGENTA - ledColour = Color.MAGENTA; - break; - case 3: // GREEN - ledColour = Color.GREEN; - break; - case 4: // RED - ledColour = Color.RED; - break; - case 5: // YELLOW - ledColour = Color.YELLOW; - break; - case 6: // WHITE - ledColour = Color.WHITE; - break; + case 1 -> // CYAN + ledColour = Color.CYAN; + case 2 -> // MAGENTA + ledColour = Color.MAGENTA; + case 3 -> // GREEN + ledColour = Color.GREEN; + case 4 -> // RED + ledColour = Color.RED; + case 5 -> // YELLOW + ledColour = Color.YELLOW; + case 6 -> // WHITE + ledColour = Color.WHITE; } @@ -1927,7 +1924,7 @@ public class Helper { Intent intent = new Intent(activity, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(activity).insertBundle(args, bundleId -> { + new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java index 9acc762e4..41326050e 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java @@ -647,7 +647,7 @@ public class SpannableHelper { Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -683,7 +683,7 @@ public class SpannableHelper { Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -719,7 +719,7 @@ public class SpannableHelper { Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -905,7 +905,7 @@ public class SpannableHelper { Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, account.moved); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java index 4a31c2a1b..7d086aac0 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.ui.drawer; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -95,9 +97,9 @@ public class AccountAdapter extends RecyclerView.Adapter { if (muted) { - accountsVM.unmuteHome(MainActivity.currentAccount, account).observe((LifecycleOwner) context, account1 -> adapter.notifyItemChanged(accountViewHolder.getLayoutPosition())); + accountsVM.unmuteHome(currentAccount, account).observe((LifecycleOwner) context, account1 -> adapter.notifyItemChanged(accountViewHolder.getLayoutPosition())); } else { - accountsVM.muteHome(MainActivity.currentAccount, account).observe((LifecycleOwner) context, account1 -> adapter.notifyItemChanged(accountViewHolder.getLayoutPosition())); + accountsVM.muteHome(currentAccount, account).observe((LifecycleOwner) context, account1 -> adapter.notifyItemChanged(accountViewHolder.getLayoutPosition())); } }); } else { @@ -114,7 +116,7 @@ public class AccountAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -130,7 +132,7 @@ public class AccountAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java index 6f493c40d..239c263c0 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.drawer; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -106,7 +108,7 @@ public class AccountFollowRequestAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchTopBarAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchTopBarAdapter.java index 56be2fca4..18f144d6a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchTopBarAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountsSearchTopBarAdapter.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.drawer; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -65,7 +67,7 @@ public class AccountsSearchTopBarAdapter extends SimpleCursorAdapter { Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, accountList.get(position)); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java index 9021635fa..9e8805f29 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.drawer; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentNightMode; import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.statusManagement; @@ -275,7 +276,7 @@ public class NotificationAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -388,7 +389,7 @@ public class NotificationAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -438,7 +439,7 @@ public class NotificationAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -455,7 +456,7 @@ public class NotificationAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -466,7 +467,7 @@ public class NotificationAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index ce637c6bf..474e7afaa 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -935,7 +935,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount,bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -949,7 +949,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, status.reblog != null ? status.reblog.account : status.account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -967,7 +967,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -981,7 +981,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, status.account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -3159,7 +3159,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, status.account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -3215,7 +3215,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); args.putSerializable(Helper.ARG_ACCOUNT, statusToDeal.account); - new CachedBundle(context).insertBundle(args, bundleId -> { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java index 9e7e8db45..0d86ae396 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.ui.drawer; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -90,7 +92,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/admin/AdminAccountAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/admin/AdminAccountAdapter.java index 16e864fc4..29bff7558 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/admin/AdminAccountAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/admin/AdminAccountAdapter.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.ui.drawer.admin; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -80,7 +82,7 @@ public class AdminAccountAdapter extends RecyclerView.Adapter { + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { Bundle bundle = new Bundle(); bundle.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java index 22c32faf7..875e2f12a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.fragment.media; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; @@ -72,7 +74,7 @@ public class FragmentMediaProfile extends Fragment { if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(requireActivity()).getBundle(bundleId, bundle -> { + new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { if(bundle != null) { accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java index 10457fb4c..d4d96276b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.fragment.timeline; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.currentToken; import static app.fedilab.android.mastodon.helper.MastodonHelper.ACCOUNTS_PER_CALL; @@ -83,7 +84,7 @@ public class FragmentMastodonAccount extends Fragment { token = currentToken; if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(requireActivity()).getBundle(bundleId, this::initializeAfterBundle); + new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(null); } @@ -217,7 +218,7 @@ public class FragmentMastodonAccount extends Fragment { } } else if (timelineType == Timeline.TimeLineEnum.MUTED_TIMELINE_HOME) { if (firstLoad) { - accountsVM.getMutedHome(MainActivity.currentAccount) + accountsVM.getMutedHome(currentAccount) .observe(getViewLifecycleOwner(), this::initializeAccountCommonView); } } else if (timelineType == Timeline.TimeLineEnum.BLOCKED_TIMELINE) { 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 f57c64464..83351c851 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 @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.fragment.timeline; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.networkAvailable; @@ -385,7 +386,7 @@ public class Fragmen