diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 850de4de..ff07e4b1 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -163,6 +163,7 @@ import app.fedilab.android.mastodon.client.entities.api.Tag; import app.fedilab.android.mastodon.client.entities.app.Account; import app.fedilab.android.mastodon.client.entities.app.BaseAccount; import app.fedilab.android.mastodon.client.entities.app.BottomMenu; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.MutedAccounts; import app.fedilab.android.mastodon.client.entities.app.Pinned; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; @@ -659,16 +660,26 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Status status = (Status) bundle.getSerializable(Helper.INTENT_TARGETED_STATUS); if (account != null) { Intent intentAccount = new Intent(activity, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intentAccount.putExtras(b); - intentAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - activity.startActivity(intentAccount); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(activity).insertBundle(args, bundleId -> { + Bundle bundleCached = new Bundle(); + bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId); + intentAccount.putExtras(bundleCached); + intentAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intentAccount); + }); } else if (status != null) { Intent intentContext = new Intent(activity, ContextActivity.class); - intentContext.putExtra(Helper.ARG_STATUS, status); - intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - activity.startActivity(intentContext); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(activity).insertBundle(args, bundleId -> { + Bundle bundleCached = new Bundle(); + bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId); + intentContext.putExtras(bundleCached); + intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intentContext); + }); } } final Handler handler = new Handler(); @@ -1035,11 +1046,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt public void federatedAccount(app.fedilab.android.mastodon.client.entities.api.Account account) { if (account != null) { Intent intent = new Intent(activity, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - activity.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(activity).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intent); + }); } else { Toasty.error(activity, activity.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); } @@ -1418,10 +1433,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.instanceInfo.setOnClickListener(v -> (new InstanceHealthActivity()).show(getSupportFragmentManager(), null)); headerMainBinding.accountProfilePicture.setOnClickListener(v -> { Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, currentAccount.mastodon_account); - intent.putExtras(b); - startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, currentAccount.mastodon_account); + new CachedBundle(BaseMainActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + }); + }); headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick()); 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 209351fc..ee6862df 100644 --- a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java @@ -40,6 +40,7 @@ import app.fedilab.android.mastodon.activities.BaseBarActivity; import app.fedilab.android.mastodon.activities.ProfileActivity; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Status; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.CrossActionHelper; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -119,10 +120,14 @@ public class AboutActivity extends BaseBarActivity { binding.accountUn.setText(account.acct); binding.accountPp.setOnClickListener(v -> { Intent intent = new Intent(AboutActivity.this, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(AboutActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + }); }); AccountsVM accountsVM = new ViewModelProvider(AboutActivity.this).get(AccountsVM.class); List ids = new ArrayList<>(); 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 8a1b2b08..46c3e9d3 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 @@ -35,6 +35,7 @@ import app.fedilab.android.databinding.ActivityAdminReportBinding; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.admin.AdminAccount; import app.fedilab.android.mastodon.client.entities.api.admin.AdminReport; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.ui.drawer.StatusReportAdapter; @@ -48,7 +49,7 @@ public class AccountReportActivity extends BaseBarActivity { private AdminReport report; private ActivityAdminReportBinding binding; private AdminVM adminVM; - + private AdminAccount targeted_account; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -61,12 +62,21 @@ public class AccountReportActivity extends BaseBarActivity { } report = null; - AdminAccount targeted_account = null; - Bundle b = getIntent().getExtras(); - if (b != null) { - account_id = b.getString(Helper.ARG_ACCOUNT_ID, null); - targeted_account = (AdminAccount) b.getSerializable(Helper.ARG_ACCOUNT); - report = (AdminReport) b.getSerializable(Helper.ARG_REPORT); + targeted_account = null; + Bundle args = getIntent().getExtras(); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(AccountReportActivity.this).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + } + private void initializeAfterBundle(Bundle bundle) { + + if(bundle != null) { + account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null); + targeted_account = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); + report = (AdminReport) bundle.getSerializable(Helper.ARG_REPORT); } binding.allow.getBackground().setColorFilter(ThemeHelper.getAttColor(this, R.attr.colorPrimary), PorterDuff.Mode.MULTIPLY); @@ -103,7 +113,6 @@ public class AccountReportActivity extends BaseBarActivity { account_id = targeted_account.username; } - } private void fillReport(AdminAccount accountAdmin, actionType type) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ActionActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ActionActivity.java index a943e6dd..d3c89017 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ActionActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ActionActivity.java @@ -100,24 +100,12 @@ public class ActionActivity extends BaseBarActivity { } switch (type) { - case MUTED_TIMELINE: - setTitle(R.string.muted_menu); - break; - case FAVOURITE_TIMELINE: - setTitle(R.string.favourite); - break; - case BLOCKED_TIMELINE: - setTitle(R.string.blocked_menu); - break; - case BOOKMARK_TIMELINE: - setTitle(R.string.bookmarks); - break; - case BLOCKED_DOMAIN_TIMELINE: - setTitle(R.string.blocked_domains); - break; - case MUTED_TIMELINE_HOME: - setTitle(R.string.muted_menu_home); - break; + case MUTED_TIMELINE -> setTitle(R.string.muted_menu); + case FAVOURITE_TIMELINE -> setTitle(R.string.favourite); + case BLOCKED_TIMELINE -> setTitle(R.string.blocked_menu); + case BOOKMARK_TIMELINE -> setTitle(R.string.bookmarks); + case BLOCKED_DOMAIN_TIMELINE -> setTitle(R.string.blocked_domains); + case MUTED_TIMELINE_HOME -> setTitle(R.string.muted_menu_home); } } 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 6d9c24d5..36b9082e 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 @@ -88,6 +88,7 @@ import app.fedilab.android.mastodon.client.entities.api.Mention; import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.BaseAccount; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.StatusDraft; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.DividerDecorationSimple; @@ -484,260 +485,274 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); statusList = new ArrayList<>(); Bundle b = getIntent().getExtras(); - if (b != null) { - statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY); - statusQuoted = (Status) b.getSerializable(Helper.ARG_QUOTED_MESSAGE); - statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT); - scheduledStatus = (ScheduledStatus) b.getSerializable(Helper.ARG_STATUS_SCHEDULED); - statusReplyId = b.getString(Helper.ARG_STATUS_REPLY_ID); - statusMention = (Status) b.getSerializable(Helper.ARG_STATUS_MENTION); - account = (BaseAccount) b.getSerializable(Helper.ARG_ACCOUNT); - if (account == null) { - account = currentAccount; - } - editMessageId = b.getString(Helper.ARG_EDIT_STATUS_ID, null); - instance = b.getString(Helper.ARG_INSTANCE, null); - token = b.getString(Helper.ARG_TOKEN, null); - visibility = b.getString(Helper.ARG_VISIBILITY, null); - if (visibility == null && statusReply != null) { - visibility = getVisibility(account, statusReply.visibility); - } else if (visibility == null && currentAccount != null && currentAccount.mastodon_account != null && currentAccount.mastodon_account.source != null) { - visibility = currentAccount.mastodon_account.source.privacy; + if(b != null) { + long bundleId = b.getLong(Helper.ARG_INTENT_ID, -1); + if(bundleId != -1 ) { + new CachedBundle(ComposeActivity.this).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(b); } - mentionBooster = (Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER); - accountMention = (Account) b.getSerializable(Helper.ARG_ACCOUNT_MENTION); - //Shared elements - sharedAttachments = (ArrayList) b.getSerializable(Helper.ARG_MEDIA_ATTACHMENTS); - sharedUrlMedia = b.getString(Helper.ARG_SHARE_URL_MEDIA); - sharedSubject = b.getString(Helper.ARG_SHARE_SUBJECT, null); - sharedContent = b.getString(Helper.ARG_SHARE_CONTENT, null); - sharedTitle = b.getString(Helper.ARG_SHARE_TITLE, null); - sharedDescription = b.getString(Helper.ARG_SHARE_DESCRIPTION, null); - shareURL = b.getString(Helper.ARG_SHARE_URL, null); } + } - if (sharedContent != null && shareURL != null && sharedContent.compareTo(shareURL) == 0) { - sharedContent = ""; - } - if (sharedTitle != null && sharedSubject != null && sharedSubject.length() > sharedTitle.length()) { - sharedTitle = sharedSubject; - } - //Edit a scheduled status from server - if (scheduledStatus != null) { - statusDraft = new StatusDraft(); - List statuses = new ArrayList<>(); - Status status = new Status(); - status.id = Helper.generateIdString(); - status.text = scheduledStatus.params.text; - status.in_reply_to_id = scheduledStatus.params.in_reply_to_id; - status.poll = scheduledStatus.params.poll; - - if (scheduledStatus.params.media_ids != null && scheduledStatus.params.media_ids.size() > 0) { - status.media_attachments = new ArrayList<>(); - new Thread(() -> { - StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class); - for (String attachmentId : scheduledStatus.params.media_ids) { - statusesVM.getAttachment(instance, token, attachmentId) - .observe(ComposeActivity.this, attachment -> status.media_attachments.add(attachment)); - } - }).start(); - } - status.sensitive = scheduledStatus.params.sensitive; - status.spoiler_text = scheduledStatus.params.spoiler_text; - status.visibility = scheduledStatus.params.visibility; - statusDraft.statusDraftList = statuses; - } - if (account == null) { - account = currentAccount; - } - if (account == null) { - Toasty.error(ComposeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); - finish(); - return; - } - if (instance == null) { - instance = account.instance; - } - if (token == null) { - token = account.token; - } - if (emojis == null || !emojis.containsKey(instance)) { - new Thread(() -> { - try { - emojis.put(instance, new EmojiInstance(ComposeActivity.this).getEmojiList(instance)); - } catch (DBException e) { - e.printStackTrace(); + private void initializeAfterBundle(Bundle b) { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + new Thread(()->{ + if (b != null) { + statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY); + statusQuoted = (Status) b.getSerializable(Helper.ARG_QUOTED_MESSAGE); + statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT); + scheduledStatus = (ScheduledStatus) b.getSerializable(Helper.ARG_STATUS_SCHEDULED); + statusReplyId = b.getString(Helper.ARG_STATUS_REPLY_ID); + statusMention = (Status) b.getSerializable(Helper.ARG_STATUS_MENTION); + account = (BaseAccount) b.getSerializable(Helper.ARG_ACCOUNT); + if (account == null) { + account = currentAccount; } - }).start(); - } - if (MainActivity.instanceInfo == null) { - String instanceInfo = sharedpreferences.getString(getString(R.string.INSTANCE_INFO) + instance, null); - if (instanceInfo != null) { - MainActivity.instanceInfo = Instance.restore(instanceInfo); - } - } - - StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class); - //Empty compose - List statusDraftList = new ArrayList<>(); - Status status = new Status(); - status.id = Helper.generateIdString(); - if (statusQuoted != null) { - status.quote_id = statusQuoted.id; - } - statusDraftList.add(status); - - if (statusReplyId != null && statusDraft != null) {//Delete and redraft - statusesVM.getStatus(currentInstance, BaseMainActivity.currentToken, statusReplyId) - .observe(ComposeActivity.this, status1 -> { - if (status1 != null) { - statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReplyId) - .observe(ComposeActivity.this, statusContext -> { - if (statusContext != null) { - initializeContextRedraftView(statusContext, status1); - } else { - Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); - } - }); - } else { - Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); - } - }); - } else if (statusDraft != null) {//Restore a draft with all messages - restoredDraft = true; - if (statusDraft.statusReplyList != null) { - statusList.addAll(statusDraft.statusReplyList); - binding.recyclerView.addItemDecoration(new DividerDecorationSimple(ComposeActivity.this, statusList)); - } - int statusCount = statusList.size(); - statusList.addAll(statusDraft.statusDraftList); - composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); - composeAdapter.mediaDescriptionCallBack = this; - composeAdapter.manageDrafts = this; - composeAdapter.promptDraftListener = this; - LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); - binding.recyclerView.setLayoutManager(mLayoutManager); - binding.recyclerView.setAdapter(composeAdapter); - binding.recyclerView.scrollToPosition(composeAdapter.getItemCount() - 1); - - } else if (statusReply != null) { - statusList.add(statusReply); - int statusCount = statusList.size(); - statusDraftList.get(0).in_reply_to_id = statusReply.id; - //We change order for mentions - //At first place the account that has been mentioned if it's not our - statusDraftList.get(0).mentions = new ArrayList<>(); - if (statusReply.account.acct != null && account.mastodon_account != null && !statusReply.account.acct.equalsIgnoreCase(account.mastodon_account.acct)) { - Mention mention = new Mention(); - mention.acct = "@" + statusReply.account.acct; - mention.url = statusReply.account.url; - mention.username = statusReply.account.username; - statusDraftList.get(0).mentions.add(mention); - } - - - //There are other mentions to - if (statusReply.mentions != null && statusReply.mentions.size() > 0) { - for (Mention mentionTmp : statusReply.mentions) { - if (statusReply.account.acct != null && !mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && account.mastodon_account != null && !mentionTmp.acct.equalsIgnoreCase(account.mastodon_account.acct)) { - statusDraftList.get(0).mentions.add(mentionTmp); - } + editMessageId = b.getString(Helper.ARG_EDIT_STATUS_ID, null); + instance = b.getString(Helper.ARG_INSTANCE, null); + token = b.getString(Helper.ARG_TOKEN, null); + visibility = b.getString(Helper.ARG_VISIBILITY, null); + if (visibility == null && statusReply != null) { + visibility = getVisibility(account, statusReply.visibility); + } else if (visibility == null && currentAccount != null && currentAccount.mastodon_account != null && currentAccount.mastodon_account.source != null) { + visibility = currentAccount.mastodon_account.source.privacy; } + mentionBooster = (Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER); + accountMention = (Account) b.getSerializable(Helper.ARG_ACCOUNT_MENTION); + //Shared elements + sharedAttachments = (ArrayList) b.getSerializable(Helper.ARG_MEDIA_ATTACHMENTS); + sharedUrlMedia = b.getString(Helper.ARG_SHARE_URL_MEDIA); + sharedSubject = b.getString(Helper.ARG_SHARE_SUBJECT, null); + sharedContent = b.getString(Helper.ARG_SHARE_CONTENT, null); + sharedTitle = b.getString(Helper.ARG_SHARE_TITLE, null); + sharedDescription = b.getString(Helper.ARG_SHARE_DESCRIPTION, null); + shareURL = b.getString(Helper.ARG_SHARE_URL, null); } - if (mentionBooster != null) { - Mention mention = new Mention(); - mention.acct = mentionBooster.acct; - mention.url = mentionBooster.url; - mention.username = mentionBooster.username; - boolean present = false; - for (Mention mentionTmp : statusDraftList.get(0).mentions) { - if (mentionTmp.acct.equalsIgnoreCase(mentionBooster.acct)) { - present = true; - break; + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + if (sharedContent != null && shareURL != null && sharedContent.compareTo(shareURL) == 0) { + sharedContent = ""; + } + if (sharedTitle != null && sharedSubject != null && sharedSubject.length() > sharedTitle.length()) { + sharedTitle = sharedSubject; + } + //Edit a scheduled status from server + if (scheduledStatus != null) { + statusDraft = new StatusDraft(); + List statuses = new ArrayList<>(); + Status status = new Status(); + status.id = Helper.generateIdString(); + status.text = scheduledStatus.params.text; + status.in_reply_to_id = scheduledStatus.params.in_reply_to_id; + status.poll = scheduledStatus.params.poll; + + if (scheduledStatus.params.media_ids != null && scheduledStatus.params.media_ids.size() > 0) { + status.media_attachments = new ArrayList<>(); + new Thread(() -> { + StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class); + for (String attachmentId : scheduledStatus.params.media_ids) { + statusesVM.getAttachment(instance, token, attachmentId) + .observe(ComposeActivity.this, attachment -> status.media_attachments.add(attachment)); + } + }).start(); } + status.sensitive = scheduledStatus.params.sensitive; + status.spoiler_text = scheduledStatus.params.spoiler_text; + status.visibility = scheduledStatus.params.visibility; + statusDraft.statusDraftList = statuses; } - if (!present) { - statusDraftList.get(0).mentions.add(mention); + if (account == null) { + account = currentAccount; } - } - if (statusReply.spoiler_text != null) { - statusDraftList.get(0).spoiler_text = statusReply.spoiler_text; - if (statusReply.spoiler_text.trim().length() > 0) { - statusDraftList.get(0).spoilerChecked = true; + if (account == null) { + Toasty.error(ComposeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); + finish(); + return; } - } - if (statusReply.language != null && !statusReply.language.isEmpty()) { - Set storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null); - if (storedLanguages == null || storedLanguages.size() == 0) { - statusDraftList.get(0).language = statusReply.language; - } else { - if (storedLanguages.contains(statusReply.language)) { - statusDraftList.get(0).language = statusReply.language; - } else { - String currentCode = sharedpreferences.getString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, Locale.getDefault().getLanguage()); - if (currentCode.isEmpty()) { - currentCode = "EN"; + if (instance == null) { + instance = account.instance; + } + if (token == null) { + token = account.token; + } + if (emojis == null || !emojis.containsKey(instance)) { + new Thread(() -> { + try { + emojis.put(instance, new EmojiInstance(ComposeActivity.this).getEmojiList(instance)); + } catch (DBException e) { + e.printStackTrace(); } - statusDraftList.get(0).language = currentCode; + }).start(); + } + if (MainActivity.instanceInfo == null) { + String instanceInfo = sharedpreferences.getString(getString(R.string.INSTANCE_INFO) + instance, null); + if (instanceInfo != null) { + MainActivity.instanceInfo = Instance.restore(instanceInfo); } } - } - //StatusDraftList at this point should only have one element - statusList.addAll(statusDraftList); - composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); - composeAdapter.mediaDescriptionCallBack = this; - composeAdapter.manageDrafts = this; - composeAdapter.promptDraftListener = this; - LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); - binding.recyclerView.setLayoutManager(mLayoutManager); - binding.recyclerView.setAdapter(composeAdapter); - statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReply.id) - .observe(ComposeActivity.this, this::initializeContextView); - } else if (statusQuoted != null) { - statusList.add(statusQuoted); - int statusCount = statusList.size(); - statusDraftList.get(0).quote_id = statusQuoted.id; - //StatusDraftList at this point should only have one element - statusList.addAll(statusDraftList); - composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); - composeAdapter.mediaDescriptionCallBack = this; - composeAdapter.manageDrafts = this; - composeAdapter.promptDraftListener = this; - LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); - binding.recyclerView.setLayoutManager(mLayoutManager); - binding.recyclerView.setAdapter(composeAdapter); - } else { - //Compose without replying - statusList.addAll(statusDraftList); - composeAdapter = new ComposeAdapter(statusList, 0, account, accountMention, visibility, editMessageId); - composeAdapter.mediaDescriptionCallBack = this; - composeAdapter.manageDrafts = this; - composeAdapter.promptDraftListener = this; - LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); - binding.recyclerView.setLayoutManager(mLayoutManager); - binding.recyclerView.setAdapter(composeAdapter); - if (statusMention != null) { - composeAdapter.loadMentions(statusMention); - } - } - MastodonHelper.loadPPMastodon(binding.profilePicture, account.mastodon_account); - ContextCompat.registerReceiver(ComposeActivity.this, imageReceiver, new IntentFilter(Helper.INTENT_SEND_MODIFIED_IMAGE), ContextCompat.RECEIVER_NOT_EXPORTED); - if (timer != null) { - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - if (promptSaveDraft) { - storeDraft(false); + + StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class); + //Empty compose + List statusDraftList = new ArrayList<>(); + Status status = new Status(); + status.id = Helper.generateIdString(); + if (statusQuoted != null) { + status.quote_id = statusQuoted.id; + } + statusDraftList.add(status); + + if (statusReplyId != null && statusDraft != null) {//Delete and redraft + statusesVM.getStatus(currentInstance, BaseMainActivity.currentToken, statusReplyId) + .observe(ComposeActivity.this, status1 -> { + if (status1 != null) { + statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReplyId) + .observe(ComposeActivity.this, statusContext -> { + if (statusContext != null) { + initializeContextRedraftView(statusContext, status1); + } else { + Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); + } + }); + } else { + Helper.sendToastMessage(getApplication(), Helper.RECEIVE_TOAST_TYPE_ERROR, getString(R.string.toast_error)); + } + }); + } else if (statusDraft != null) {//Restore a draft with all messages + restoredDraft = true; + if (statusDraft.statusReplyList != null) { + statusList.addAll(statusDraft.statusReplyList); + binding.recyclerView.addItemDecoration(new DividerDecorationSimple(ComposeActivity.this, statusList)); + } + int statusCount = statusList.size(); + statusList.addAll(statusDraft.statusDraftList); + composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; + composeAdapter.manageDrafts = this; + composeAdapter.promptDraftListener = this; + LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); + binding.recyclerView.setLayoutManager(mLayoutManager); + binding.recyclerView.setAdapter(composeAdapter); + binding.recyclerView.scrollToPosition(composeAdapter.getItemCount() - 1); + + } else if (statusReply != null) { + statusList.add(statusReply); + int statusCount = statusList.size(); + statusDraftList.get(0).in_reply_to_id = statusReply.id; + //We change order for mentions + //At first place the account that has been mentioned if it's not our + statusDraftList.get(0).mentions = new ArrayList<>(); + if (statusReply.account.acct != null && account.mastodon_account != null && !statusReply.account.acct.equalsIgnoreCase(account.mastodon_account.acct)) { + Mention mention = new Mention(); + mention.acct = "@" + statusReply.account.acct; + mention.url = statusReply.account.url; + mention.username = statusReply.account.username; + statusDraftList.get(0).mentions.add(mention); + } + + + //There are other mentions to + if (statusReply.mentions != null && statusReply.mentions.size() > 0) { + for (Mention mentionTmp : statusReply.mentions) { + if (statusReply.account.acct != null && !mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && account.mastodon_account != null && !mentionTmp.acct.equalsIgnoreCase(account.mastodon_account.acct)) { + statusDraftList.get(0).mentions.add(mentionTmp); + } + } + } + if (mentionBooster != null) { + Mention mention = new Mention(); + mention.acct = mentionBooster.acct; + mention.url = mentionBooster.url; + mention.username = mentionBooster.username; + boolean present = false; + for (Mention mentionTmp : statusDraftList.get(0).mentions) { + if (mentionTmp.acct.equalsIgnoreCase(mentionBooster.acct)) { + present = true; + break; + } + } + if (!present) { + statusDraftList.get(0).mentions.add(mention); + } + } + if (statusReply.spoiler_text != null) { + statusDraftList.get(0).spoiler_text = statusReply.spoiler_text; + if (statusReply.spoiler_text.trim().length() > 0) { + statusDraftList.get(0).spoilerChecked = true; + } + } + if (statusReply.language != null && !statusReply.language.isEmpty()) { + Set storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null); + if (storedLanguages == null || storedLanguages.size() == 0) { + statusDraftList.get(0).language = statusReply.language; + } else { + if (storedLanguages.contains(statusReply.language)) { + statusDraftList.get(0).language = statusReply.language; + } else { + String currentCode = sharedpreferences.getString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, Locale.getDefault().getLanguage()); + if (currentCode.isEmpty()) { + currentCode = "EN"; + } + statusDraftList.get(0).language = currentCode; + } + } + } + //StatusDraftList at this point should only have one element + statusList.addAll(statusDraftList); + composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; + composeAdapter.manageDrafts = this; + composeAdapter.promptDraftListener = this; + LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); + binding.recyclerView.setLayoutManager(mLayoutManager); + binding.recyclerView.setAdapter(composeAdapter); + statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReply.id) + .observe(ComposeActivity.this, this::initializeContextView); + } else if (statusQuoted != null) { + statusList.add(statusQuoted); + int statusCount = statusList.size(); + statusDraftList.get(0).quote_id = statusQuoted.id; + //StatusDraftList at this point should only have one element + statusList.addAll(statusDraftList); + composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; + composeAdapter.manageDrafts = this; + composeAdapter.promptDraftListener = this; + LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); + binding.recyclerView.setLayoutManager(mLayoutManager); + binding.recyclerView.setAdapter(composeAdapter); + } else { + //Compose without replying + statusList.addAll(statusDraftList); + composeAdapter = new ComposeAdapter(statusList, 0, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; + composeAdapter.manageDrafts = this; + composeAdapter.promptDraftListener = this; + LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); + binding.recyclerView.setLayoutManager(mLayoutManager); + binding.recyclerView.setAdapter(composeAdapter); + if (statusMention != null) { + composeAdapter.loadMentions(statusMention); } } - }, 0, 10000); - } + MastodonHelper.loadPPMastodon(binding.profilePicture, account.mastodon_account); + ContextCompat.registerReceiver(ComposeActivity.this, imageReceiver, new IntentFilter(Helper.INTENT_SEND_MODIFIED_IMAGE), ContextCompat.RECEIVER_NOT_EXPORTED); + if (timer != null) { + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (promptSaveDraft) { + storeDraft(false); + } + } + }, 0, 10000); + } - if (sharedAttachments != null && sharedAttachments.size() > 0) { - for (Attachment attachment : sharedAttachments) { - composeAdapter.addAttachment(-1, attachment); - } - } /*else if (sharedUri != null && !sharedUri.toString().startsWith("http")) { + if (sharedAttachments != null && sharedAttachments.size() > 0) { + for (Attachment attachment : sharedAttachments) { + composeAdapter.addAttachment(-1, attachment); + } + } /*else if (sharedUri != null && !sharedUri.toString().startsWith("http")) { List uris = new ArrayList<>(); uris.add(sharedUri); Helper.createAttachmentFromUri(ComposeActivity.this, uris, attachments -> { @@ -747,35 +762,39 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana }); } */ else if (shareURL != null) { - Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() { - @Override - public void onDownloaded(String saveFilePath, String downloadUrl, Error error) { + Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() { + @Override + public void onDownloaded(String saveFilePath, String downloadUrl, Error error) { - composeAdapter.addSharing(shareURL, sharedTitle, sharedDescription, sharedSubject, sharedContent, saveFilePath); - } - - @Override - public void onUpdateProgress(int progress) { + composeAdapter.addSharing(shareURL, sharedTitle, sharedDescription, sharedSubject, sharedContent, saveFilePath); + } - } - }); + @Override + public void onUpdateProgress(int progress) { - } else { - if (composeAdapter != null) { - composeAdapter.addSharing(null, null, sharedDescription, null, sharedContent, null); - } - } + } + }); - getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) { - @Override - public void handleOnBackPressed() { - if (binding.recyclerView.getVisibility() == View.VISIBLE) { - storeDraftWarning(); + } else { + if (composeAdapter != null) { + composeAdapter.addSharing(null, null, sharedDescription, null, sharedContent, null); + } } - } - }); + + getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (binding.recyclerView.getVisibility() == View.VISIBLE) { + storeDraftWarning(); + } + } + }); + }; + mainHandler.post(myRunnable); + }).start(); } + @Override public void onItemDraftAdded(int position, String initialContent) { Status status = new Status(); 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 2b59df22..c0b89551 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 @@ -50,6 +50,7 @@ import app.fedilab.android.databinding.AccountFieldItemBinding; import app.fedilab.android.databinding.ActivityEditProfileBinding; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Field; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -259,13 +260,18 @@ public class EditProfileActivity extends BaseBarActivity { } private void sendBroadCast(Account account) { - Bundle b = new Bundle(); - b.putBoolean(Helper.RECEIVE_REDRAW_PROFILE, true); - b.putSerializable(Helper.ARG_ACCOUNT, account); - Intent intentBD = new Intent(Helper.BROADCAST_DATA); - intentBD.putExtras(b); - intentBD.setPackage(BuildConfig.APPLICATION_ID); - sendBroadcast(intentBD); + Bundle args = new Bundle(); + args.putBoolean(Helper.RECEIVE_REDRAW_PROFILE, true); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(EditProfileActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + Intent intentBD = new Intent(Helper.BROADCAST_DATA); + intentBD.putExtras(bundle); + intentBD.setPackage(BuildConfig.APPLICATION_ID); + sendBroadcast(intentBD); + }); + } private Intent prepareIntent() { 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 24b5a3ea..53905ab8 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 @@ -34,6 +34,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityPartnershipBinding; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Status; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.CrossActionHelper; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -78,10 +79,14 @@ public class PartnerShipActivity extends BaseBarActivity { binding.accountUn.setText(account.acct); binding.accountPp.setOnClickListener(v -> { Intent intent = new Intent(PartnerShipActivity.this, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(PartnerShipActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + }); }); AccountsVM accountsVM = new ViewModelProvider(PartnerShipActivity.this).get(AccountsVM.class); List ids = new ArrayList<>(); 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 336f47c5..b0b10452 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 @@ -51,7 +51,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityOptionsCompat; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; @@ -90,6 +89,7 @@ import app.fedilab.android.mastodon.client.entities.api.Field; import app.fedilab.android.mastodon.client.entities.api.IdentityProof; import app.fedilab.android.mastodon.client.entities.api.MastodonList; import app.fedilab.android.mastodon.client.entities.api.RelationShip; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.Languages; import app.fedilab.android.mastodon.client.entities.app.Pinned; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; @@ -133,12 +133,24 @@ public class ProfileActivity extends BaseActivity { private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - Bundle b = intent.getExtras(); - if (b != null) { - Account accountReceived = (Account) b.getSerializable(Helper.ARG_ACCOUNT); - if (b.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) { - if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) { - initializeView(accountReceived); + Bundle args = intent.getExtras(); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + if(bundleId != -1 ) { + new CachedBundle(ProfileActivity.this).getBundle(bundleId, 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)) { + initializeView(accountReceived); + } + } + }); + } else { + Account accountReceived = (Account) args.getSerializable(Helper.ARG_ACCOUNT); + if (args.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) { + if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) { + initializeView(accountReceived); + } } } } @@ -154,17 +166,11 @@ public class ProfileActivity extends BaseActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); ActionBar actionBar = getSupportActionBar(); - Bundle b = getIntent().getExtras(); + Bundle args = getIntent().getExtras(); binding.accountFollow.setEnabled(false); checkRemotely = false; SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); - homeMuted = false; - if (b != null) { - account = (Account) b.getSerializable(Helper.ARG_ACCOUNT); - account_id = b.getString(Helper.ARG_USER_ID, null); - mention_str = b.getString(Helper.ARG_MENTION, null); - checkRemotely = b.getBoolean(Helper.ARG_CHECK_REMOTELY, false); - } + if (!checkRemotely) { checkRemotely = sharedpreferences.getBoolean(getString(R.string.SET_PROFILE_REMOTELY), false); } @@ -181,6 +187,22 @@ public class ProfileActivity extends BaseActivity { float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); accountsVM = new ViewModelProvider(ProfileActivity.this).get(AccountsVM.class); + homeMuted = false; + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(ProfileActivity.this).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + } + + private void initializeAfterBundle(Bundle bundle) { + if (bundle != null) { + account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); + account_id = bundle.getString(Helper.ARG_USER_ID, null); + mention_str = bundle.getString(Helper.ARG_MENTION, null); + checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); + } if (account != null) { initializeView(account); } else if (account_id != null) { @@ -443,12 +465,16 @@ public class ProfileActivity extends BaseActivity { } binding.openRemoteProfile.setOnClickListener(v -> { Intent intent = new Intent(ProfileActivity.this, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - b.putSerializable(Helper.ARG_CHECK_REMOTELY, true); - intent.putExtras(b); - startActivity(intent); - finish(); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + args.putSerializable(Helper.ARG_CHECK_REMOTELY, true); + new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + finish(); + }); }); //Fields for profile List fields = account.fields; @@ -627,11 +653,15 @@ public class ProfileActivity extends BaseActivity { notificationsRelatedAccountsBinding.acc.setText(account.username); notificationsRelatedAccountsBinding.relatedAccountContainer.setOnClickListener(v -> { Intent intent = new Intent(ProfileActivity.this, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - // start the new activity - startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + }); + }); binding.relatedAccounts.addView(notificationsRelatedAccountsBinding.getRoot()); } @@ -1022,11 +1052,15 @@ public class ProfileActivity extends BaseActivity { return true; } else if (itemId == R.id.action_direct_message) { Intent intent = new Intent(ProfileActivity.this, ComposeActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT_MENTION, account); - b.putString(Helper.ARG_VISIBILITY, "direct"); - intent.putExtras(b); - startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT_MENTION, account); + args.putString(Helper.ARG_VISIBILITY, "direct"); + new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + }); return true; } else if (itemId == R.id.action_add_to_list) { TimelinesVM timelinesVM = new ViewModelProvider(ProfileActivity.this).get(TimelinesVM.class); @@ -1109,12 +1143,15 @@ public class ProfileActivity extends BaseActivity { return true; } else if (itemId == R.id.action_mention) { Intent intent; - Bundle b; intent = new Intent(ProfileActivity.this, ComposeActivity.class); - b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT_MENTION, account); - intent.putExtras(b); - startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT_MENTION, account); + new CachedBundle(ProfileActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + startActivity(intent); + }); return true; } else if (itemId == R.id.action_mute) { AlertDialog.Builder builderInner; 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 fb718c08..0f3c3e55 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 @@ -36,6 +36,7 @@ import app.fedilab.android.databinding.ActivityReportBinding; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.RelationShip; import app.fedilab.android.mastodon.client.entities.api.Status; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.ui.drawer.RulesAdapter; @@ -70,11 +71,21 @@ public class ReportActivity extends BaseBarActivity { if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } + Bundle args = getIntent().getExtras(); + if(args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + if(bundleId != -1 ) { + new CachedBundle(ReportActivity.this).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(args); + } + } + } - Bundle b = getIntent().getExtras(); - if (b != null) { - status = (Status) b.getSerializable(Helper.ARG_STATUS); - account = (Account) b.getSerializable(Helper.ARG_ACCOUNT); + private void initializeAfterBundle(Bundle bundle) { + if (bundle != null) { + status = (Status) bundle.getSerializable(Helper.ARG_STATUS); + account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); } if (account == null && status != null) { account = status.account; @@ -139,7 +150,6 @@ public class ReportActivity extends BaseBarActivity { }); } - @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { @@ -222,21 +232,25 @@ public class ReportActivity extends BaseBarActivity { private void switchToSpam() { fragment = new FragmentMastodonTimeline(); - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); - bundle.putSerializable(Helper.ARG_ACCOUNT, account); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); + args.putSerializable(Helper.ARG_ACCOUNT, account); //Set to display statuses with less options - bundle.putBoolean(Helper.ARG_MINIFIED, true); + args.putBoolean(Helper.ARG_MINIFIED, true); if (status != null) { status.isChecked = true; - bundle.putSerializable(Helper.ARG_STATUS_REPORT, status); + args.putSerializable(Helper.ARG_STATUS_REPORT, status); } - fragment.setArguments(bundle); - FragmentManager fragmentManager = getSupportFragmentManager(); - FragmentTransaction fragmentTransaction = - fragmentManager.beginTransaction(); - fragmentTransaction.replace(R.id.fram_spam_container, fragment); - fragmentTransaction.commit(); + new CachedBundle(ReportActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + fragment.setArguments(bundle); + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = + fragmentManager.beginTransaction(); + fragmentTransaction.replace(R.id.fram_spam_container, fragment); + fragmentTransaction.commit(); + }); binding.actionButton.setText(R.string.next); binding.actionButton.setOnClickListener(v -> { @@ -248,22 +262,25 @@ public class ReportActivity extends BaseBarActivity { private void switchToSomethingElse() { fragment = new FragmentMastodonTimeline(); - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); - bundle.putSerializable(Helper.ARG_ACCOUNT, account); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); + args.putSerializable(Helper.ARG_ACCOUNT, account); //Set to display statuses with less options - bundle.putBoolean(Helper.ARG_MINIFIED, true); + args.putBoolean(Helper.ARG_MINIFIED, true); if (status != null) { status.isChecked = true; - bundle.putSerializable(Helper.ARG_STATUS_REPORT, status); + args.putSerializable(Helper.ARG_STATUS_REPORT, status); } - fragment.setArguments(bundle); - FragmentManager fragmentManager = getSupportFragmentManager(); - FragmentTransaction fragmentTransaction = - fragmentManager.beginTransaction(); - fragmentTransaction.replace(R.id.fram_se_container, fragment); - fragmentTransaction.commit(); - + new CachedBundle(ReportActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + fragment.setArguments(bundle); + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = + fragmentManager.beginTransaction(); + fragmentTransaction.replace(R.id.fram_se_container, fragment); + fragmentTransaction.commit(); + }); binding.actionButton.setText(R.string.next); binding.actionButton.setOnClickListener(v -> { if (category == null) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java index 06be2592..c57b6d38 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java @@ -302,27 +302,32 @@ public class SearchResultTabActivity extends BaseBarActivity { @Override public Fragment getItem(int position) { Bundle bundle = new Bundle(); + FragmentMastodonTimeline fragmentMastodonTimeline; switch (position) { - case 0: + case 0 -> { FragmentMastodonTag fragmentMastodonTag = new FragmentMastodonTag(); bundle.putString(Helper.ARG_SEARCH_KEYWORD, search); fragmentMastodonTag.setArguments(bundle); return fragmentMastodonTag; - case 1: + } + case 1 -> { FragmentMastodonAccount fragmentMastodonAccount = new FragmentMastodonAccount(); bundle.putString(Helper.ARG_SEARCH_KEYWORD, search); fragmentMastodonAccount.setArguments(bundle); return fragmentMastodonAccount; - case 2: - FragmentMastodonTimeline fragmentMastodonTimeline = new FragmentMastodonTimeline(); + } + case 2 -> { + fragmentMastodonTimeline = new FragmentMastodonTimeline(); bundle.putString(Helper.ARG_SEARCH_KEYWORD, search); fragmentMastodonTimeline.setArguments(bundle); return fragmentMastodonTimeline; - default: + } + default -> { fragmentMastodonTimeline = new FragmentMastodonTimeline(); bundle.putString(Helper.ARG_SEARCH_KEYWORD_CACHE, search); fragmentMastodonTimeline.setArguments(bundle); return fragmentMastodonTimeline; + } } } 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 6686f207..8fc81746 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 @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityTimelineBinding; import app.fedilab.android.mastodon.client.entities.api.Status; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; @@ -57,17 +58,21 @@ public class TimelineActivity extends BaseBarActivity { setTitle(pinnedTimeline.remoteInstance.host); } FragmentMastodonTimeline fragmentMastodonTimeline = new FragmentMastodonTimeline(); - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, timelineType); - bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinnedTimeline); - bundle.putSerializable(Helper.ARG_LEMMY_POST_ID, lemmy_post_id); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_TIMELINE_TYPE, timelineType); + args.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinnedTimeline); + args.putSerializable(Helper.ARG_LEMMY_POST_ID, lemmy_post_id); if (status != null) { - bundle.putSerializable(Helper.ARG_STATUS, status); + args.putSerializable(Helper.ARG_STATUS, status); } - fragmentMastodonTimeline.setArguments(bundle); + new CachedBundle(TimelineActivity.this).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + fragmentMastodonTimeline.setArguments(bundle); + getSupportFragmentManager().beginTransaction() + .add(R.id.fragment_container_view, fragmentMastodonTimeline).commit(); + }); - getSupportFragmentManager().beginTransaction() - .add(R.id.fragment_container_view, fragmentMastodonTimeline).commit(); } 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 f78e0af6..7f0794c3 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 @@ -61,6 +61,7 @@ import app.fedilab.android.mastodon.activities.MediaActivity; import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.admin.AdminAccount; import app.fedilab.android.mastodon.client.entities.api.admin.AdminIp; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.SpannableHelper; @@ -87,18 +88,32 @@ public class AdminAccountActivity extends BaseActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); ActionBar actionBar = getSupportActionBar(); - Bundle b = getIntent().getExtras(); + Bundle args = getIntent().getExtras(); adminAccount = null; - if (b != null) { - adminAccount = (AdminAccount) b.getSerializable(Helper.ARG_ACCOUNT); - account_id = b.getString(Helper.ARG_ACCOUNT_ID, null); - } postponeEnterTransition(); //Remove title if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(false); } + + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(AdminAccountActivity.this).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + + + } + + + private void initializeAfterBundle(Bundle bundle) { + + if(bundle !=null) { + adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); + account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null); + } SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); @@ -175,8 +190,6 @@ public class AdminAccountActivity extends BaseActivity { initializeView(adminAccount); } }); - - } private void initializeView(AdminAccount adminAccount) { 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 2680275a..cc11c694 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 @@ -62,6 +62,7 @@ import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.admin.AdminAccount; import app.fedilab.android.mastodon.client.entities.api.admin.AdminIp; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.SpannableHelper; @@ -87,19 +88,8 @@ public class AdminReportActivity extends BaseBarActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); ActionBar actionBar = getSupportActionBar(); - Bundle b = getIntent().getExtras(); - if (b != null) { - adminAccount = (AdminAccount) b.getSerializable(Helper.ARG_ACCOUNT); - if (adminAccount != null) { - account = adminAccount.account; - } - } + Bundle args = getIntent().getExtras(); postponeEnterTransition(); - - //Remove title - if (actionBar != null) { - actionBar.setDisplayShowTitleEnabled(false); - } SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); @@ -107,6 +97,28 @@ public class AdminReportActivity extends BaseBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } + + //Remove title + if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(false); + } + + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(AdminReportActivity.this).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + } + + + private void initializeAfterBundle(Bundle bundle) { + if(bundle != null) { + adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); + if (adminAccount != null) { + account = adminAccount.account; + } + } if (account != null) { initializeView(account); } else { 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 49b525c4..61a873bc 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 @@ -44,6 +44,7 @@ import app.fedilab.android.mastodon.client.entities.api.Results; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.Account; import app.fedilab.android.mastodon.client.entities.app.BaseAccount; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.ui.drawer.AccountsSearchAdapter; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; @@ -183,77 +184,89 @@ public class CrossActionHelper { statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get("crossactions", StatusesVM.class); } switch (actionType) { - case MUTE_ACTION: + case MUTE_ACTION -> { assert accountsVM != null; accountsVM.mute(ownerAccount.instance, ownerAccount.token, targetedAccount.id, true, 0) .observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_mute), Toasty.LENGTH_SHORT).show()); - break; - case UNMUTE_ACTION: + } + case UNMUTE_ACTION -> { assert accountsVM != null; accountsVM.unmute(ownerAccount.instance, ownerAccount.token, targetedAccount.id) .observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_unmute), Toasty.LENGTH_SHORT).show()); - break; - case BLOCK_ACTION: + } + case BLOCK_ACTION -> { assert accountsVM != null; accountsVM.block(ownerAccount.instance, ownerAccount.token, targetedAccount.id) .observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_block), Toasty.LENGTH_SHORT).show()); - break; - case UNBLOCK_ACTION: + } + case UNBLOCK_ACTION -> { assert accountsVM != null; accountsVM.unblock(ownerAccount.instance, ownerAccount.token, targetedAccount.id) .observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_unblock), Toasty.LENGTH_SHORT).show()); - break; - case FOLLOW_ACTION: + } + case FOLLOW_ACTION -> { assert accountsVM != null; accountsVM.follow(ownerAccount.instance, ownerAccount.token, targetedAccount.id, true, false, null) .observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_follow), Toasty.LENGTH_SHORT).show()); - break; - case UNFOLLOW_ACTION: + } + case UNFOLLOW_ACTION -> { assert accountsVM != null; accountsVM.unfollow(ownerAccount.instance, ownerAccount.token, targetedAccount.id) .observe((LifecycleOwner) context, relationShip -> Toasty.info(context, context.getString(R.string.toast_unfollow), Toasty.LENGTH_SHORT).show()); - break; - case FAVOURITE_ACTION: + } + case FAVOURITE_ACTION -> { assert statusesVM != null; statusesVM.favourite(ownerAccount.instance, ownerAccount.token, targetedStatus.id) .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_favourite), Toasty.LENGTH_SHORT).show()); - break; - case UNFAVOURITE_ACTION: + } + case UNFAVOURITE_ACTION -> { assert statusesVM != null; statusesVM.unFavourite(ownerAccount.instance, ownerAccount.token, targetedStatus.id) .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unfavourite), Toasty.LENGTH_SHORT).show()); - break; - case BOOKMARK_ACTION: + } + case BOOKMARK_ACTION -> { assert statusesVM != null; statusesVM.bookmark(ownerAccount.instance, ownerAccount.token, targetedStatus.id) .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_bookmark), Toasty.LENGTH_SHORT).show()); - break; - case UNBOOKMARK_ACTION: + } + case UNBOOKMARK_ACTION -> { assert statusesVM != null; statusesVM.unBookmark(ownerAccount.instance, ownerAccount.token, targetedStatus.id) .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unbookmark), Toasty.LENGTH_SHORT).show()); - break; - case REBLOG_ACTION: + } + case REBLOG_ACTION -> { assert statusesVM != null; statusesVM.reblog(ownerAccount.instance, ownerAccount.token, targetedStatus.id, null) .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_reblog), Toasty.LENGTH_SHORT).show()); - break; - case UNREBLOG_ACTION: + } + case UNREBLOG_ACTION -> { assert statusesVM != null; statusesVM.unReblog(ownerAccount.instance, ownerAccount.token, targetedStatus.id) .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unreblog), Toasty.LENGTH_SHORT).show()); - break; - case REPLY_ACTION: + } + case REPLY_ACTION -> { Intent intent = new Intent(context, ComposeActivity.class); - intent.putExtra(Helper.ARG_STATUS_REPLY, targetedStatus); - intent.putExtra(Helper.ARG_ACCOUNT, ownerAccount); - context.startActivity(intent); - break; - case COMPOSE: + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS_REPLY, targetedStatus); + args.putSerializable(Helper.ARG_ACCOUNT, ownerAccount); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); + } + case COMPOSE -> { Intent intentCompose = new Intent(context, ComposeActivity.class); - intentCompose.putExtra(Helper.ARG_ACCOUNT, ownerAccount); - context.startActivity(intentCompose); - break; + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, ownerAccount); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intentCompose.putExtras(bundle); + context.startActivity(intentCompose); + }); + } } } @@ -430,10 +443,15 @@ public class CrossActionHelper { final BaseAccount account = accountArray[which]; Intent intentToot = new Intent(context, ComposeActivity.class); bundle.putSerializable(Helper.ARG_ACCOUNT, account); - intentToot.putExtras(bundle); - context.startActivity(intentToot); - ((BaseActivity) context).finish(); - dialog.dismiss(); + new CachedBundle(context).insertBundle(bundle, bundleId -> { + Bundle bundleCached = new Bundle(); + bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId); + intentToot.putExtras(bundleCached); + context.startActivity(intentToot); + ((BaseActivity) context).finish(); + dialog.dismiss(); + }); + }); builderSingle.show(); } 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 e2e7a122..ca23f9b3 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 @@ -157,6 +157,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.Account; import app.fedilab.android.mastodon.client.entities.app.BaseAccount; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.ReleaseNote; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.exception.DBException; @@ -1924,10 +1925,14 @@ public class Helper { binding.accountUn.setText(account.acct); binding.accountPp.setOnClickListener(v -> { Intent intent = new Intent(activity, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - activity.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(activity).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + activity.startActivity(intent); + }); }); AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) activity).get(AccountsVM.class); 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 de58d977..9acc762e 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 @@ -86,6 +86,7 @@ import app.fedilab.android.mastodon.client.entities.api.Emoji; import app.fedilab.android.mastodon.client.entities.api.Filter; import app.fedilab.android.mastodon.client.entities.api.Mention; import app.fedilab.android.mastodon.client.entities.api.Status; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.MarkdownConverter; import app.fedilab.android.mastodon.ui.drawer.StatusAdapter; import app.fedilab.android.mastodon.viewmodel.mastodon.FiltersVM; @@ -644,11 +645,15 @@ public class SpannableHelper { @Override public void federatedAccount(Account account) { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + }); } }); } @@ -676,11 +681,15 @@ public class SpannableHelper { @Override public void federatedAccount(Account account) { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + }); } }); } @@ -708,11 +717,15 @@ public class SpannableHelper { @Override public void federatedAccount(Account account) { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + }); } }); } @@ -890,10 +903,14 @@ public class SpannableHelper { @Override public void onClick(@NonNull View textView) { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account.moved); - intent.putExtras(b); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account.moved); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } @Override 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 428048fa..4a31c2a1 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 @@ -48,6 +48,7 @@ import app.fedilab.android.activities.MainActivity; import app.fedilab.android.databinding.DrawerAccountBinding; import app.fedilab.android.mastodon.activities.ProfileActivity; import app.fedilab.android.mastodon.client.entities.api.Account; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.ThemeHelper; @@ -111,11 +112,14 @@ public class AccountAdapter extends RecyclerView.Adapter { if (remoteInstance == null) { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } else { Toasty.info(context, context.getString(R.string.retrieve_remote_account), Toasty.LENGTH_SHORT).show(); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); @@ -124,11 +128,14 @@ public class AccountAdapter extends RecyclerView.Adapter 0) { Account accountSearch = results.accounts.get(0); Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, accountSearch); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, accountSearch); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); } 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 a765d851..6f493c40 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 @@ -38,6 +38,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.DrawerFollowBinding; import app.fedilab.android.mastodon.activities.ProfileActivity; import app.fedilab.android.mastodon.client.entities.api.Account; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; @@ -103,11 +104,14 @@ public class AccountFollowRequestAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); } 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 60eb910c..56be2fca 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,7 +14,6 @@ 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 android.app.Activity; import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -22,10 +21,8 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import androidx.appcompat.widget.LinearLayoutCompat; -import androidx.core.app.ActivityOptionsCompat; import androidx.cursoradapter.widget.SimpleCursorAdapter; import java.util.List; @@ -33,6 +30,7 @@ import java.util.List; import app.fedilab.android.R; import app.fedilab.android.mastodon.activities.ProfileActivity; import app.fedilab.android.mastodon.client.entities.api.Account; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; @@ -61,16 +59,18 @@ public class AccountsSearchTopBarAdapter extends SimpleCursorAdapter { LinearLayoutCompat container = view.findViewById(R.id.account_container); container.setTag(cursor.getPosition()); - ImageView account_pp = view.findViewById(R.id.account_pp); container.setOnClickListener(v -> { int position = (int) v.getTag(); if (accountList != null && accountList.size() > position) { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, accountList.get(position)); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, accountList.get(position)); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } }); } 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 d4f63e7e..9021635f 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 @@ -50,6 +50,7 @@ import app.fedilab.android.databinding.DrawerStatusNotificationBinding; import app.fedilab.android.databinding.NotificationsRelatedAccountsBinding; import app.fedilab.android.mastodon.activities.ProfileActivity; import app.fedilab.android.mastodon.client.entities.api.Notification; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -272,11 +273,14 @@ public class NotificationAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, notification.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, notification.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); if (notification.isFetchMore && fetchMoreCallBack != null) { holderFollow.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); @@ -382,11 +386,14 @@ public class NotificationAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, notification.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, notification.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holderStatus.bindingNotification.status.mainContainer.setAlpha(.8f); } @@ -429,11 +436,14 @@ public class NotificationAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, relativeNotif.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, relativeNotif.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holderStatus.bindingNotification.relatedAccounts.addView(notificationsRelatedAccountsBinding.getRoot()); } @@ -443,21 +453,26 @@ public class NotificationAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, notification.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, notification.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holderStatus.bindingNotification.status.statusUserInfo.setOnClickListener(v -> { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, notification.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, notification.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); - holderStatus.bindingNotification.status.displayName.setText( notification.account.getSpanDisplayNameTitle(context, new WeakReference<>(holderStatus.bindingNotification.status.displayName), title), 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 b417ff6b..ce637c6b 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 @@ -153,6 +153,7 @@ import app.fedilab.android.mastodon.client.entities.api.Reaction; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.Account; import app.fedilab.android.mastodon.client.entities.app.BaseAccount; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; import app.fedilab.android.mastodon.client.entities.app.RemoteInstance; import app.fedilab.android.mastodon.client.entities.app.StatusCache; @@ -932,22 +933,28 @@ public class StatusAdapter extends RecyclerView.Adapter if (results != null && results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); } }); } else { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, status.reblog != null ? status.reblog.account : status.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, status.reblog != null ? status.reblog.account : status.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } }); holder.binding.statusBoosterInfo.setOnClickListener(v -> { @@ -958,22 +965,28 @@ public class StatusAdapter extends RecyclerView.Adapter if (results != null && results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); } }); } else { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, status.account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, status.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } }); //---> REBLOG/UNREBLOG @@ -3144,10 +3157,14 @@ public class StatusAdapter extends RecyclerView.Adapter holder.bindingArt.artAcct.setText(String.format(Locale.getDefault(), "@%s", status.account.acct)); holder.bindingArt.artPp.setOnClickListener(v -> { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, status.account); - intent.putExtras(b); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, status.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holder.bindingArt.artMedia.setOnClickListener(v -> { if (status.art_attachment != null) { @@ -3196,10 +3213,14 @@ public class StatusAdapter extends RecyclerView.Adapter holder.bindingPixelfed.artAcct.setText(String.format(Locale.getDefault(), "@%s", statusToDeal.account.acct)); holder.bindingPixelfed.artPp.setOnClickListener(v -> { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, statusToDeal.account); - intent.putExtras(b); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, statusToDeal.account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holder.bindingPixelfed.bottomBanner.setOnClickListener(v -> { Intent intent = new Intent(context, ContextActivity.class); 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 55bbc985..9e7e8db4 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 @@ -41,6 +41,7 @@ import app.fedilab.android.databinding.DrawerSuggestionBinding; import app.fedilab.android.mastodon.activities.ProfileActivity; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Suggestion; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; @@ -87,11 +88,14 @@ public class SuggestionAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, account); - intent.putExtras(b); - // start the new activity - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, account); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_add_24); if (account == null) { 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 98967224..16e864fc 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 @@ -34,6 +34,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.DrawerAdminAccountBinding; import app.fedilab.android.mastodon.activities.admin.AdminAccountActivity; import app.fedilab.android.mastodon.client.entities.api.admin.AdminAccount; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -77,11 +78,15 @@ public class AdminAccountAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, AdminAccountActivity.class); - Bundle b = new Bundle(); - b.putSerializable(Helper.ARG_ACCOUNT, adminAccount); - intent.putExtras(b); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_ACCOUNT, adminAccount); + new CachedBundle(context).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + }); }); holder.binding.username.setText(adminAccount.account.display_name); holder.binding.acct.setText(String.format(Locale.getDefault(), "@%s", adminAccount.account.acct)); 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 8d8daca7..22c32faf 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 @@ -38,6 +38,7 @@ import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Statuses; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.CrossActionHelper; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -68,10 +69,15 @@ public class FragmentMediaProfile extends Fragment { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); - Bundle bundle = this.getArguments(); - if (bundle != null) { - accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); - checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false); + + if (getArguments() != null) { + long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(requireActivity()).getBundle(bundleId, bundle -> { + if(bundle != null) { + accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); + checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); + } + }); } return binding.getRoot(); } 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 4e26ec8e..10457fb4 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 @@ -45,6 +45,7 @@ import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Accounts; import app.fedilab.android.mastodon.client.entities.api.Pagination; import app.fedilab.android.mastodon.client.entities.api.RelationShip; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; @@ -77,19 +78,35 @@ public class FragmentMastodonAccount extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (getArguments() != null) { - search = getArguments().getString(Helper.ARG_SEARCH_KEYWORD, null); - accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); - followType = (FedilabProfileTLPageAdapter.follow_type) getArguments().getSerializable(Helper.ARG_FOLLOW_TYPE); - viewModelKey = getArguments().getString(Helper.ARG_VIEW_MODEL_KEY, ""); - timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE); - order = getArguments().getString(Helper.ARG_DIRECTORY_ORDER, "active"); - local = getArguments().getBoolean(Helper.ARG_DIRECTORY_LOCAL, false); - checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false); - } + instance = currentInstance; token = currentToken; + if (getArguments() != null) { + long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(requireActivity()).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + flagLoading = false; + binding = FragmentPaginationBinding.inflate(inflater, container, false); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); + binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); + return binding.getRoot(); + } + + private void initializeAfterBundle(Bundle bundle) { + if(bundle != null) { + search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null); + accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); + followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE); + viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, ""); + timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); + order = bundle.getString(Helper.ARG_DIRECTORY_ORDER, "active"); + local = bundle.getBoolean(Helper.ARG_DIRECTORY_LOCAL, false); + checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); + } if (checkRemotely) { String[] acctArray = accountTimeline.acct.split("@"); if (acctArray.length > 1) { @@ -103,12 +120,6 @@ public class FragmentMastodonAccount extends Fragment { } } - flagLoading = false; - binding = FragmentPaginationBinding.inflate(inflater, container, false); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); - boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); - binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); - return binding.getRoot(); } @Override 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 90e1166a..f57c6446 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 @@ -384,7 +384,11 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. flagLoading = false; if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); - new CachedBundle(requireActivity()).getBundle(bundleId, this::initializeAfterBundle); + if(bundleId != -1 ) { + new CachedBundle(requireActivity()).getBundle(bundleId, this::initializeAfterBundle); + } else { + initializeAfterBundle(getArguments()); + } } boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java index 52d8394b..a450ee1a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java @@ -33,6 +33,7 @@ import com.google.android.material.tabs.TabLayout; import app.fedilab.android.R; import app.fedilab.android.databinding.FragmentProfileTimelinesBinding; import app.fedilab.android.mastodon.client.entities.api.Account; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.ui.pageadapter.FedilabProfilePageAdapter; @@ -46,12 +47,20 @@ public class FragmentProfileTimeline extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - + binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false); if (getArguments() != null) { - account = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); - checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false); + long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + if(bundleId != -1 ) { + new CachedBundle(requireActivity()).getBundle(bundleId, bundle -> { + account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); + checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); + }); + } else { + account = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); + checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false); + } } - binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false); + return binding.getRoot(); } @@ -111,18 +120,22 @@ public class FragmentProfileTimeline extends Fragment { .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()); FragmentTransaction fragTransaction = getChildFragmentManager().beginTransaction(); fragTransaction.detach(fragmentMastodonTimeline).commit(); - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); - bundle.putSerializable(Helper.ARG_ACCOUNT, account); - bundle.putBoolean(Helper.ARG_SHOW_PINNED, true); - bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); - bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, show_boosts); - bundle.putBoolean(Helper.ARG_SHOW_REPLIES, show_replies); - fragmentMastodonTimeline.setArguments(bundle); - FragmentTransaction fragTransaction2 = getChildFragmentManager().beginTransaction(); - fragTransaction2.attach(fragmentMastodonTimeline); - fragTransaction2.commit(); - fragmentMastodonTimeline.recreate(); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); + args.putSerializable(Helper.ARG_ACCOUNT, account); + args.putBoolean(Helper.ARG_SHOW_PINNED, true); + args.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); + args.putBoolean(Helper.ARG_SHOW_REBLOGS, show_boosts); + args.putBoolean(Helper.ARG_SHOW_REPLIES, show_replies); + new CachedBundle(requireActivity()).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + fragmentMastodonTimeline.setArguments(bundle); + FragmentTransaction fragTransaction2 = getChildFragmentManager().beginTransaction(); + fragTransaction2.attach(fragmentMastodonTimeline); + fragTransaction2.commit(); + fragmentMastodonTimeline.recreate(); + }); } }); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfilePageAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfilePageAdapter.java index dc1c747d..618d04c2 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfilePageAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfilePageAdapter.java @@ -56,9 +56,10 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter { public Fragment getItem(int position) { Bundle bundle = new Bundle(); bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position); + FragmentMastodonTimeline fragmentProfileTimeline; switch (position) { - case 0: - FragmentMastodonTimeline fragmentProfileTimeline = new FragmentMastodonTimeline(); + case 0 -> { + fragmentProfileTimeline = new FragmentMastodonTimeline(); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); bundle.putSerializable(Helper.ARG_ACCOUNT, account); bundle.putBoolean(Helper.ARG_SHOW_PINNED, true); @@ -67,7 +68,8 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter { bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); fragmentProfileTimeline.setArguments(bundle); return fragmentProfileTimeline; - case 1: + } + case 1 -> { fragmentProfileTimeline = new FragmentMastodonTimeline(); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); bundle.putSerializable(Helper.ARG_ACCOUNT, account); @@ -77,14 +79,17 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter { bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); fragmentProfileTimeline.setArguments(bundle); return fragmentProfileTimeline; - case 2: + } + case 2 -> { FragmentMediaProfile fragmentMediaProfile = new FragmentMediaProfile(); bundle.putSerializable(Helper.ARG_ACCOUNT, account); bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); fragmentMediaProfile.setArguments(bundle); return fragmentMediaProfile; - default: + } + default -> { return new FragmentMastodonTimeline(); + } } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfileTLPageAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfileTLPageAdapter.java index 748b01ae..3d1ed9ca 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfileTLPageAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfileTLPageAdapter.java @@ -54,16 +54,17 @@ public class FedilabProfileTLPageAdapter extends FragmentStatePagerAdapter { @NonNull @Override public Fragment getItem(int position) { + Bundle bundle; switch (position) { - case 0: + case 0 -> { FragmentProfileTimeline fragmentProfileTimeline = new FragmentProfileTimeline(); - Bundle bundle = new Bundle(); + bundle = new Bundle(); bundle.putSerializable(Helper.ARG_ACCOUNT, account); bundle.putSerializable(Helper.ARG_CHECK_REMOTELY, checkRemotely); fragmentProfileTimeline.setArguments(bundle); return fragmentProfileTimeline; - case 1: - case 2: + } + case 1, 2 -> { FragmentMastodonAccount fragmentMastodonAccount = new FragmentMastodonAccount(); bundle = new Bundle(); bundle.putSerializable(Helper.ARG_ACCOUNT, account); @@ -72,8 +73,10 @@ public class FedilabProfileTLPageAdapter extends FragmentStatePagerAdapter { bundle.putSerializable(Helper.ARG_FOLLOW_TYPE, position == 1 ? follow_type.FOLLOWING : follow_type.FOLLOWERS); fragmentMastodonAccount.setArguments(bundle); return fragmentMastodonAccount; - default: + } + default -> { return new FragmentMastodonTimeline(); + } } } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/FragmentLoginPickInstanceMastodon.java b/app/src/main/java/app/fedilab/android/ui/fragment/FragmentLoginPickInstanceMastodon.java index 8f59d29e..b7ff463f 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/FragmentLoginPickInstanceMastodon.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/FragmentLoginPickInstanceMastodon.java @@ -32,6 +32,7 @@ import java.util.List; import app.fedilab.android.R; import app.fedilab.android.databinding.FragmentLoginPickInstanceMastodonBinding; import app.fedilab.android.mastodon.client.entities.api.JoinMastodonInstance; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.ui.drawer.InstanceRegAdapter; @@ -145,10 +146,13 @@ public class FragmentLoginPickInstanceMastodon extends Fragment implements Insta Bundle args = new Bundle(); args.putSerializable(Helper.ARG_REMOTE_INSTANCE_STRING, clickedInstance.domain); args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC); - - Helper.addFragment( - getParentFragmentManager(), android.R.id.content, new FragmentMastodonTimeline(), - args, null, FragmentLoginRegisterMastodon.class.getName()); + new CachedBundle(requireActivity()).insertBundle(args, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + Helper.addFragment( + getParentFragmentManager(), android.R.id.content, new FragmentMastodonTimeline(), + bundle, null, FragmentLoginRegisterMastodon.class.getName()); + }); } } } \ No newline at end of file