diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index ec60e99a..c16fccb0 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -304,9 +304,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG) .setAction(getString(R.string.display), view -> { Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class); - intentContext.putExtra(Helper.ARG_STATUS, statusSent); - intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intentContext); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusSent); + new CachedBundle(BaseMainActivity.this).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intentContext.putExtras(bundle); + intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intentContext); + }); }) .show(); //The message was edited, we need to update the timeline @@ -782,9 +788,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt public void federatedStatus(Status status) { if (status != null) { Intent intent = new Intent(activity, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, status); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - activity.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(activity).insertBundle(args, currentAccount, 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); + }); } } @@ -1021,9 +1033,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt public void federatedStatus(Status status) { if (status != null) { Intent intent = new Intent(activity, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, status); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - activity.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(activity).insertBundle(args, currentAccount, 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(); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java index a166587f..61d62ddc 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ContextActivity.java @@ -44,6 +44,7 @@ import app.fedilab.android.R; import app.fedilab.android.activities.MainActivity; import app.fedilab.android.databinding.ActivityConversationBinding; 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.StatusCache; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; @@ -86,14 +87,24 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } - Bundle b = getIntent().getExtras(); displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false); focusedStatus = null; // or other values - if (b != null) { - focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS); - remote_instance = b.getString(Helper.ARG_REMOTE_INSTANCE, null); - focusedStatusURI = b.getString(Helper.ARG_FOCUSED_STATUS_URI, null); + MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); + + Bundle args = getIntent().getExtras(); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(ContextActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + } + private void initializeAfterBundle(Bundle bundle) { + if (bundle != null) { + focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS); + remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null); + focusedStatusURI = bundle.getString(Helper.ARG_FOCUSED_STATUS_URI, null); } if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) { finish(); @@ -102,7 +113,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon if (focusedStatusURI == null && remote_instance == null) { focusedStatusURI = focusedStatus.uri; } - MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); checkRemotely = sharedpreferences.getBoolean(getString(R.string.SET_CONVERSATION_REMOTELY), false); if (!checkRemotely) { @@ -113,6 +124,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon } } + @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); @@ -120,37 +132,41 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon } private void loadLocalConversation() { - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_STATUS, focusedStatus); - bundle.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); - FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); - fragmentMastodonContext.firstMessage = this; - currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null); - //Update the status - if (remote_instance == null) { - StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class); - timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> { - if (status != null) { - StatusCache statusCache = new StatusCache(); - statusCache.instance = BaseMainActivity.currentInstance; - statusCache.user_id = BaseMainActivity.currentUserID; - statusCache.status = status; - statusCache.status_id = status.id; - //Update cache - new Thread(() -> { - try { - new StatusCache(getApplication()).updateIfExists(statusCache); - Handler mainHandler = new Handler(Looper.getMainLooper()); - //Update UI - Runnable myRunnable = () -> StatusAdapter.sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null); - mainHandler.post(myRunnable); - } catch (DBException e) { - e.printStackTrace(); - } - }).start(); - } - }); - } + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, focusedStatus); + args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); + new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); + fragmentMastodonContext.firstMessage = this; + currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null); + //Update the status + if (remote_instance == null) { + StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class); + timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> { + if (status != null) { + StatusCache statusCache = new StatusCache(); + statusCache.instance = BaseMainActivity.currentInstance; + statusCache.user_id = BaseMainActivity.currentUserID; + statusCache.status = status; + statusCache.status_id = status.id; + //Update cache + new Thread(() -> { + try { + new StatusCache(getApplication()).updateIfExists(statusCache); + Handler mainHandler = new Handler(Looper.getMainLooper()); + //Update UI + Runnable myRunnable = () -> StatusAdapter.sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null); + mainHandler.post(myRunnable); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } + }); + } + }); } @Override @@ -245,13 +261,17 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon String finalInstance = instance; statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> { if (status != null) { - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_STATUS, status); - bundle.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance); - bundle.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); - FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); - fragmentMastodonContext.firstMessage = ContextActivity.this; - currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance); + args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); + new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); + fragmentMastodonContext.firstMessage = ContextActivity.this; + currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null); + }); } else { loadLocalConversation(); } @@ -293,11 +313,17 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> { if (status != null) { Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class); - intentContext.putExtra(Helper.ARG_STATUS, status); - intentContext.putExtra(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); - intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, finalInstance); - intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intentContext); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); + args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance); + new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intentContext.putExtras(bundle); + intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intentContext); + }); } else { Toasty.warning(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java index ea3d11b1..ee3cf8b8 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/CustomSharingActivity.java @@ -37,6 +37,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Emoji; import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Tag; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.customsharing.CustomSharingAsyncTask; import app.fedilab.android.mastodon.helper.customsharing.CustomSharingResponse; @@ -65,23 +66,34 @@ public class CustomSharingActivity extends BaseBarActivity implements OnCustomSh protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this); + binding = ActivityCustomSharingBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } - Bundle b = getIntent().getExtras(); + Bundle args = getIntent().getExtras(); status = null; - if (b != null) { - status = (Status) b.getSerializable(Helper.ARG_STATUS); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(CustomSharingActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + + } + + private void initializeAfterBundle(Bundle bundle) { + + if (bundle != null) { + status = (Status) bundle.getSerializable(Helper.ARG_STATUS); } if (status == null) { finish(); return; } - + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this); bundle_creator = status.account.acct; bundle_url = status.url; bundle_id = status.uri; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java index 7d63ccb7..8994618f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/DirectMessageActivity.java @@ -39,6 +39,7 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityDirectMessageBinding; 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.StatusCache; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; @@ -71,53 +72,71 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto 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); - + MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } - Bundle b = getIntent().getExtras(); + Bundle args = getIntent().getExtras(); displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false); + + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(DirectMessageActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + + + } + + private void initializeAfterBundle(Bundle bundle) { Status focusedStatus = null; // or other values - if (b != null) { - focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS); - remote_instance = b.getString(Helper.ARG_REMOTE_INSTANCE, null); + if (bundle != null) { + focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS); + remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null); } + if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) { finish(); return; } - MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_STATUS, focusedStatus); - bundle.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); - FragmentMastodonDirectMessage FragmentMastodonDirectMessage = new FragmentMastodonDirectMessage(); - FragmentMastodonDirectMessage.firstMessage = this; - currentFragment = (FragmentMastodonDirectMessage) Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, FragmentMastodonDirectMessage, bundle, null, null); - StatusesVM timelinesVM = new ViewModelProvider(DirectMessageActivity.this).get(StatusesVM.class); - timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(DirectMessageActivity.this, status -> { - if (status != null) { - StatusCache statusCache = new StatusCache(); - statusCache.instance = BaseMainActivity.currentInstance; - statusCache.user_id = BaseMainActivity.currentUserID; - statusCache.status = status; - statusCache.status_id = status.id; - //Update cache - new Thread(() -> { - try { - new StatusCache(getApplication()).updateIfExists(statusCache); - Handler mainHandler = new Handler(Looper.getMainLooper()); - //Update UI - Runnable myRunnable = () -> StatusAdapter.sendAction(DirectMessageActivity.this, Helper.ARG_STATUS_ACTION, status, null); - mainHandler.post(myRunnable); - } catch (DBException e) { - e.printStackTrace(); - } - }).start(); - } + + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, focusedStatus); + args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); + Status finalFocusedStatus = focusedStatus; + new CachedBundle(DirectMessageActivity.this).insertBundle(args, currentAccount, bundleId -> { + Bundle args2 = new Bundle(); + args2.putLong(Helper.ARG_INTENT_ID, bundleId); + FragmentMastodonDirectMessage FragmentMastodonDirectMessage = new FragmentMastodonDirectMessage(); + FragmentMastodonDirectMessage.firstMessage = this; + currentFragment = (FragmentMastodonDirectMessage) Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, FragmentMastodonDirectMessage, args2, null, null); + StatusesVM timelinesVM = new ViewModelProvider(DirectMessageActivity.this).get(StatusesVM.class); + timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, finalFocusedStatus.id).observe(DirectMessageActivity.this, status -> { + if (status != null) { + StatusCache statusCache = new StatusCache(); + statusCache.instance = BaseMainActivity.currentInstance; + statusCache.user_id = BaseMainActivity.currentUserID; + statusCache.status = status; + statusCache.status_id = status.id; + //Update cache + new Thread(() -> { + try { + new StatusCache(getApplication()).updateIfExists(statusCache); + Handler mainHandler = new Handler(Looper.getMainLooper()); + //Update UI + Runnable myRunnable = () -> StatusAdapter.sendAction(DirectMessageActivity.this, Helper.ARG_STATUS_ACTION, status, null); + mainHandler.post(myRunnable); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } + }); }); - } + } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java index 04f4641a..718081ab 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.activities; * see . */ import static android.util.Patterns.WEB_URL; +import static app.fedilab.android.BaseMainActivity.currentAccount; import android.Manifest; import android.app.DownloadManager; @@ -63,6 +64,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityMediaPagerBinding; 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.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.MediaHelper; import app.fedilab.android.mastodon.helper.TranslateHelper; @@ -124,13 +126,26 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload fullscreen = false; flags = getWindow().getDecorView().getSystemUiVisibility(); - Bundle b = getIntent().getExtras(); - if (b != null) { - mediaPosition = b.getInt(Helper.ARG_MEDIA_POSITION, 1); - attachments = (ArrayList) b.getSerializable(Helper.ARG_MEDIA_ARRAY); - mediaFromProfile = b.getBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, false); - status = (Status) b.getSerializable(Helper.ARG_STATUS); + Bundle args = getIntent().getExtras(); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(MediaActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + + + } + + private void initializeAfterBundle(Bundle bundle) { + + if (bundle != null) { + mediaPosition = bundle.getInt(Helper.ARG_MEDIA_POSITION, 1); + attachments = (ArrayList) bundle.getSerializable(Helper.ARG_MEDIA_ARRAY); + mediaFromProfile = bundle.getBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, false); + status = (Status) bundle.getSerializable(Helper.ARG_STATUS); } + if (mediaFromProfile && FragmentMediaProfile.mediaAttachmentProfile != null) { attachments = new ArrayList<>(); attachments.addAll(FragmentMediaProfile.mediaAttachmentProfile); @@ -146,7 +161,6 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload } setTitle(""); - ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); binding.mediaViewpager.setAdapter(mPagerAdapter); binding.mediaViewpager.setSaveEnabled(false); @@ -239,6 +253,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload setFullscreen(true); } + private Spannable linkify(Context context, String content) { if (content == null) { return new SpannableString(""); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/StatusInfoActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/StatusInfoActivity.java index 7d81d5ab..6f952a93 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/StatusInfoActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/StatusInfoActivity.java @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.currentToken; @@ -38,6 +39,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.RelationShip; import app.fedilab.android.mastodon.client.entities.api.Status; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.ui.drawer.AccountAdapter; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; @@ -70,12 +72,23 @@ public class StatusInfoActivity extends BaseActivity { } accountList = new ArrayList<>(); checkRemotely = false; - Bundle b = getIntent().getExtras(); - if (b != null) { - type = (typeOfInfo) b.getSerializable(Helper.ARG_TYPE_OF_INFO); - status = (Status) b.getSerializable(Helper.ARG_STATUS); - checkRemotely = b.getBoolean(Helper.ARG_CHECK_REMOTELY, false); + Bundle args = getIntent().getExtras(); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(StatusInfoActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); } + } + + private void initializeAfterBundle(Bundle bundle) { + + if (bundle != null) { + type = (typeOfInfo) bundle.getSerializable(Helper.ARG_TYPE_OF_INFO); + status = (Status) bundle.getSerializable(Helper.ARG_STATUS); + checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); + } + if (type == null || status == null) { finish(); return; @@ -138,6 +151,7 @@ public class StatusInfoActivity extends BaseActivity { } } + private void manageView(Accounts accounts) { binding.loadingNextAccounts.setVisibility(View.GONE); if (accountList != null && accounts != null && accounts.accounts != null) { 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 cb2e1109..3b67773f 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 @@ -45,16 +45,25 @@ public class TimelineActivity extends BaseBarActivity { if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } - Bundle b = getIntent().getExtras(); + Bundle args = getIntent().getExtras(); + if (args != null) { + long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(TimelineActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + } + + private void initializeAfterBundle(Bundle bundle) { Timeline.TimeLineEnum timelineType = null; String lemmy_post_id = null; PinnedTimeline pinnedTimeline = null; Status status = null; - if (b != null) { - timelineType = (Timeline.TimeLineEnum) b.get(Helper.ARG_TIMELINE_TYPE); - lemmy_post_id = b.getString(Helper.ARG_LEMMY_POST_ID, null); - pinnedTimeline = (PinnedTimeline) b.getSerializable(Helper.ARG_REMOTE_INSTANCE); - status = (Status) b.getSerializable(Helper.ARG_STATUS); + if (bundle != null) { + timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); + lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null); + pinnedTimeline = (PinnedTimeline) bundle.getSerializable(Helper.ARG_REMOTE_INSTANCE); + status = (Status) bundle.getSerializable(Helper.ARG_STATUS); } if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) { setTitle(pinnedTimeline.remoteInstance.host); @@ -68,13 +77,12 @@ public class TimelineActivity extends BaseBarActivity { args.putSerializable(Helper.ARG_STATUS, status); } new CachedBundle(TimelineActivity.this).insertBundle(args, currentAccount, bundleId -> { - Bundle bundle = new Bundle(); - bundle.putLong(Helper.ARG_INTENT_ID, bundleId); - fragmentMastodonTimeline.setArguments(bundle); + Bundle bundle1 = new Bundle(); + bundle1.putLong(Helper.ARG_INTENT_ID, bundleId); + fragmentMastodonTimeline.setArguments(bundle1); getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container_view, fragmentMastodonTimeline).commit(); }); - } 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 4e69af01..a3b5bcc0 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 @@ -627,9 +627,15 @@ public class SpannableHelper { @Override public void federatedStatus(Status status) { Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, status); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(context).insertBundle(args, currentAccount, 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); + }); } @Override @@ -663,9 +669,15 @@ public class SpannableHelper { @Override public void federatedStatus(Status status) { Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, status); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(context).insertBundle(args, currentAccount, 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); + }); } @Override @@ -699,9 +711,15 @@ public class SpannableHelper { @Override public void federatedStatus(Status status) { Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, status); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(context).insertBundle(args, currentAccount, 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); + }); } @Override diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java index 08a2b11a..c352a903 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java @@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.drawer; * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentNightMode; import android.annotation.SuppressLint; @@ -22,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.view.LayoutInflater; @@ -49,13 +51,14 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.DrawerConversationBinding; import app.fedilab.android.databinding.ThumbnailBinding; import app.fedilab.android.mastodon.activities.ContextActivity; -import app.fedilab.android.mastodon.activities.DirectMessageActivity; 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.Conversation; import app.fedilab.android.mastodon.client.entities.api.Status; +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.activities.DirectMessageActivity; public class ConversationAdapter extends RecyclerView.Adapter { @@ -220,8 +223,14 @@ public class ConversationAdapter extends RecyclerView.Adapter { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holder.binding.attachmentsListContainer.setOnTouchListener((v, event) -> { @@ -232,8 +241,14 @@ public class ConversationAdapter extends RecyclerView.Adapter { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } return false; }); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ImageAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ImageAdapter.java index 9b4304ed..dba70134 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ImageAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ImageAdapter.java @@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.drawer; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -31,6 +33,7 @@ import app.fedilab.android.databinding.DrawerMediaBinding; import app.fedilab.android.mastodon.activities.ContextActivity; import app.fedilab.android.mastodon.activities.MediaActivity; import app.fedilab.android.mastodon.client.entities.api.Attachment; +import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.ui.fragment.media.FragmentMediaProfile; @@ -89,13 +92,19 @@ public class ImageAdapter extends RecyclerView.Adapter holder.binding.media.setOnLongClickListener(v -> { Intent intentContext = new Intent(context, ContextActivity.class); + Bundle args = new Bundle(); if (attachment != null) { - intentContext.putExtra(Helper.ARG_STATUS, attachment.status); + args.putSerializable(Helper.ARG_STATUS, attachment.status); } else { return false; } - intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intentContext); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intentContext.putExtras(bundle); + intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intentContext); + }); return false; }); } 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 8f89be84..87216663 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 @@ -503,8 +503,14 @@ public class StatusAdapter extends RecyclerView.Adapter return; } Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, statusToDeal.quote); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal.quote); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary)); holder.binding.quotedMessage.statusContent.setText( @@ -1773,20 +1779,32 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.reblogInfo.setOnClickListener(v -> { if (statusToDeal.reblogs_count > 0) { Intent intent = new Intent(context, StatusInfoActivity.class); - intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY); - intent.putExtra(Helper.ARG_STATUS, statusToDeal); - intent.putExtra(Helper.ARG_CHECK_REMOTELY, remote); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + args.putSerializable(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY); + args.putBoolean(Helper.ARG_CHECK_REMOTELY, remote); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } }); holder.binding.favouriteInfo.setOnClickListener(v -> { if (statusToDeal.favourites_count > 0) { Intent intent = new Intent(context, StatusInfoActivity.class); - intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY); - intent.putExtra(Helper.ARG_STATUS, statusToDeal); - intent.putExtra(Helper.ARG_CHECK_REMOTELY, remote); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + args.putSerializable(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY); + args.putBoolean(Helper.ARG_CHECK_REMOTELY, remote); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } }); @@ -2002,22 +2020,31 @@ public class StatusAdapter extends RecyclerView.Adapter return; } if (context instanceof ContextActivity && !remote) { - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_STATUS, statusToDeal); - Fragment fragment = Helper.addFragment(((AppCompatActivity) context).getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, FragmentMastodonContext.class.getName()); - ((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + Fragment fragment = Helper.addFragment(((AppCompatActivity) context).getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, FragmentMastodonContext.class.getName()); + ((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment); + }); } else { if (remote) { //Lemmy main post that should open Lemmy threads if (adapter instanceof StatusAdapter && ((StatusAdapter) adapter).type == RemoteInstance.InstanceType.LEMMY && status.lemmy_post_id != null) { - Bundle bundle = new Bundle(); - bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, ((StatusAdapter) adapter).pinnedTimeline); - bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE); - bundle.putString(Helper.ARG_LEMMY_POST_ID, status.lemmy_post_id); - bundle.putSerializable(Helper.ARG_STATUS, status); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_REMOTE_INSTANCE, ((StatusAdapter) adapter).pinnedTimeline); + args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE); + args.putString(Helper.ARG_LEMMY_POST_ID, status.lemmy_post_id); + args.putSerializable(Helper.ARG_STATUS, status); Intent intent = new Intent(context, TimelineActivity.class); - intent.putExtras(bundle); - context.startActivity(intent); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); + } //Classic other cases for remote instances that will search the remote context else if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); @@ -2026,8 +2053,14 @@ 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, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, fetchedStatus); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, fetchedStatus); + new CachedBundle(context).insertBundle(args, currentAccount, 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(); } @@ -2047,8 +2080,14 @@ public class StatusAdapter extends RecyclerView.Adapter } } else { Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, statusToDeal); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } } }); @@ -2262,8 +2301,14 @@ public class StatusAdapter extends RecyclerView.Adapter return true; } else if (itemId == R.id.action_report) { Intent intent = new Intent(context, ReportActivity.class); - intent.putExtra(Helper.ARG_STATUS, statusToDeal); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } else if (itemId == R.id.action_copy) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); String content; @@ -2317,8 +2362,14 @@ public class StatusAdapter extends RecyclerView.Adapter context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); } else if (itemId == R.id.action_custom_sharing) { Intent intent = new Intent(context, CustomSharingActivity.class); - intent.putExtra(Helper.ARG_STATUS, statusToDeal); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); } else if (itemId == R.id.action_mention) { Intent intent = new Intent(context, ComposeActivity.class); Bundle b = new Bundle(); @@ -3183,8 +3234,14 @@ public class StatusAdapter extends RecyclerView.Adapter }); holder.bindingArt.bottomBanner.setOnClickListener(v -> { Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, status); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, status); + new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> { + Bundle bundle = new Bundle(); + bundle.putLong(Helper.ARG_INTENT_ID, bundleId); + intent.putExtras(bundle); + context.startActivity(intent); + }); }); } else if (viewHolder.getItemViewType() == STATUS_PIXELFED) { Status statusToDeal = status.reblog != null ? status.reblog : status; @@ -3223,8 +3280,14 @@ public class StatusAdapter extends RecyclerView.Adapter }); holder.bindingPixelfed.bottomBanner.setOnClickListener(v -> { Intent intent = new Intent(context, ContextActivity.class); - intent.putExtra(Helper.ARG_STATUS, statusToDeal); - context.startActivity(intent); + Bundle args = new Bundle(); + args.putSerializable(Helper.ARG_STATUS, statusToDeal); + new CachedBundle(context).insertBundle(args, currentAccount, 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/fragment/timeline/FragmentMastodonContext.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java index b5d2d74f..31cc9f6a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java @@ -14,6 +14,7 @@ package app.fedilab.android.mastodon.ui.fragment.timeline; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.mastodon.activities.ContextActivity.displayCW; import static app.fedilab.android.mastodon.activities.ContextActivity.expand; @@ -42,6 +43,7 @@ import app.fedilab.android.databinding.FragmentPaginationBinding; import app.fedilab.android.mastodon.activities.ContextActivity; import app.fedilab.android.mastodon.client.entities.api.Context; 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.DividerDecoration; import app.fedilab.android.mastodon.helper.Helper; @@ -158,10 +160,21 @@ public class FragmentMastodonContext extends Fragment { pullToRefresh = false; focusedStatusURI = null; refresh = true; + binding = FragmentPaginationBinding.inflate(inflater, container, false); if (getArguments() != null) { - focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS); - remote_instance = getArguments().getString(Helper.ARG_REMOTE_INSTANCE, null); - focusedStatusURI = getArguments().getString(Helper.ARG_FOCUSED_STATUS_URI, null); + long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + return binding.getRoot(); + } + + private void initializeAfterBundle(Bundle bundle) { + if (bundle != null) { + focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS); + remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null); + focusedStatusURI = bundle.getString(Helper.ARG_FOCUSED_STATUS_URI, null); } if (remote_instance != null) { user_instance = remote_instance; @@ -174,7 +187,7 @@ public class FragmentMastodonContext extends Fragment { getChildFragmentManager().beginTransaction().remove(this).commit(); } - 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); @@ -202,9 +215,9 @@ public class FragmentMastodonContext extends Fragment { } ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED); - return binding.getRoot(); } + public void refresh() { if (statuses != null) { for (Status status : statuses) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java index caa441cd..36eeeacf 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java @@ -82,6 +82,7 @@ import app.fedilab.android.mastodon.client.entities.api.Context; import app.fedilab.android.mastodon.client.entities.api.Mention; import app.fedilab.android.mastodon.client.entities.api.Poll; 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.StatusDraft; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; @@ -131,8 +132,21 @@ public class FragmentMastodonDirectMessage extends Fragment { focusedStatus = null; pullToRefresh = false; + binding = FragmentDirectMessageBinding.inflate(inflater, container, false); if (getArguments() != null) { - focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS); + long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + initializeAfterBundle(null); + } + return binding.getRoot(); + } + + + private void initializeAfterBundle(Bundle bundle) { + + if (bundle != null) { + focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS); } user_instance = MainActivity.currentInstance; user_token = MainActivity.currentToken; @@ -140,7 +154,7 @@ public class FragmentMastodonDirectMessage extends Fragment { if (focusedStatus == null) { getChildFragmentManager().beginTransaction().remove(this).commit(); } - binding = FragmentDirectMessageBinding.inflate(inflater, container, false); + statusesVM = new ViewModelProvider(FragmentMastodonDirectMessage.this).get(StatusesVM.class); binding.recyclerView.setNestedScrollingEnabled(true); this.statuses = new ArrayList<>(); @@ -216,10 +230,8 @@ public class FragmentMastodonDirectMessage extends Fragment { } }); - return binding.getRoot(); } - private void onSubmit(StatusDraft statusDraft) { new Thread(() -> { if (statusDraft.instance == null) { diff --git a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java index 769ac6d1..049509a1 100644 --- a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java @@ -43,7 +43,6 @@ import org.json.JSONObject; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.net.IDN; import java.net.URL; import java.net.URLDecoder;