From 2e20e78b7f40a1010348c03bffc2f1c68c48783e Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 9 Jan 2024 11:39:09 +0100 Subject: Apply changes when serializing accounts --- .../java/app/fedilab/android/BaseMainActivity.java | 54 ++- .../fedilab/android/activities/AboutActivity.java | 13 +- .../mastodon/activities/AccountReportActivity.java | 25 +- .../mastodon/activities/ActionActivity.java | 24 +- .../mastodon/activities/ComposeActivity.java | 539 +++++++++++---------- .../mastodon/activities/EditProfileActivity.java | 20 +- .../mastodon/activities/PartnerShipActivity.java | 13 +- .../mastodon/activities/ProfileActivity.java | 109 +++-- .../mastodon/activities/ReportActivity.java | 73 +-- .../activities/SearchResultTabActivity.java | 15 +- .../mastodon/activities/TimelineActivity.java | 21 +- .../activities/admin/AdminAccountActivity.java | 27 +- .../activities/admin/AdminReportActivity.java | 36 +- .../android/mastodon/helper/CrossActionHelper.java | 92 ++-- .../fedilab/android/mastodon/helper/Helper.java | 13 +- .../android/mastodon/helper/SpannableHelper.java | 55 ++- .../android/mastodon/ui/drawer/AccountAdapter.java | 27 +- .../ui/drawer/AccountFollowRequestAdapter.java | 14 +- .../ui/drawer/AccountsSearchTopBarAdapter.java | 18 +- .../mastodon/ui/drawer/NotificationAdapter.java | 67 ++- .../android/mastodon/ui/drawer/StatusAdapter.java | 77 +-- .../mastodon/ui/drawer/SuggestionAdapter.java | 14 +- .../ui/drawer/admin/AdminAccountAdapter.java | 15 +- .../ui/fragment/media/FragmentMediaProfile.java | 14 +- .../fragment/timeline/FragmentMastodonAccount.java | 43 +- .../timeline/FragmentMastodonTimeline.java | 6 +- .../fragment/timeline/FragmentProfileTimeline.java | 45 +- .../ui/pageadapter/FedilabProfilePageAdapter.java | 15 +- .../pageadapter/FedilabProfileTLPageAdapter.java | 13 +- .../FragmentLoginPickInstanceMastodon.java | 12 +- 30 files changed, 896 insertions(+), 613 deletions(-) (limited to 'app') diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 850de4dec..ff07e4b1e 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 209351fc8..ee6862df3 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 8a1b2b083..46c3e9d3a 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 a943e6dd8..d3c89017e 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 6d9c24d59..36b9082e3 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 2b59df228..c0b895510 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 24b5a3ea1..53905ab8c 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 336f47c51..b0b10452f 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 fb718c08f..0f3c3e55b 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(Help