diff options
author | Thomas <tschneider.ac@gmail.com> | 2024-01-10 15:58:27 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2024-01-10 15:58:27 +0100 |
commit | 85e462e276f27697c2bc4831d5f2d949ee40378a (patch) | |
tree | c2eb3c6b4560d7da6e87f343068fc21d6e01717f | |
parent | 1ff15b0f939285b69c230fdf93c88cbe7f2617c2 (diff) |
Apply for status
14 files changed, 420 insertions, 179 deletions
diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index ec60e99a4..c16fccb0d 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 a166587f6..61d62ddcd 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 ea3d11b19..ee3cf8b85 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 7d63ccb72..8994618f0 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 04f4641a5..718081abc 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 <http://www.gnu.org/licenses>. */ 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<Attachment>) 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<Attachment>) 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 7d81d5ab0..6f952a937 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 <http://www.gnu.org/licenses>. */ +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 cb2e11097..3b67773f7 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 4e69af014..a3b5bcc07 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); |