Fix potential crashes when clicking on notifications

This commit is contained in:
Thomas 2024-01-17 14:12:56 +01:00
parent 886b74c171
commit a1a6005ca0
5 changed files with 89 additions and 68 deletions

View file

@ -675,32 +675,35 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
*/
private static void openNotifications(Activity activity, Intent intent) {
if (intent != null && intent.getExtras() != null) {
Bundle bundle = intent.getExtras();
Bundle args = intent.getExtras();
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(activity).getBundle(bundleId, currentAccount, bundle -> {
app.fedilab.android.mastodon.client.entities.api.Account account = (app.fedilab.android.mastodon.client.entities.api.Account) bundle.getSerializable(Helper.INTENT_TARGETED_ACCOUNT);
Status status = (Status) bundle.getSerializable(Helper.INTENT_TARGETED_STATUS);
if (account != null) {
Intent intentAccount = new Intent(activity, ProfileActivity.class);
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_ACCOUNT, account);
new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
Bundle args2 = new Bundle();
args2.putSerializable(Helper.ARG_ACCOUNT, account);
new CachedBundle(activity).insertBundle(args2, currentAccount, bundleId2 -> {
Bundle bundleCached = new Bundle();
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId);
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId2);
intentAccount.putExtras(bundleCached);
intentAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intentAccount);
});
} else if (status != null) {
Intent intentContext = new Intent(activity, ContextActivity.class);
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_STATUS, status);
new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
Bundle args2 = new Bundle();
args2.putSerializable(Helper.ARG_STATUS, status);
new CachedBundle(activity).insertBundle(args2, currentAccount, bundleId2 -> {
Bundle bundleCached = new Bundle();
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId);
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId2);
intentContext.putExtras(bundleCached);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intentContext);
});
}
});
}
final Handler handler = new Handler();
handler.postDelayed(() -> {

View file

@ -171,10 +171,16 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
if (attachments.get(mediaPosition - 1).status != null) {
binding.originalMessage.setOnClickListener(v -> {
Intent intentContext = new Intent(MediaActivity.this, ContextActivity.class);
intentContext.putExtra(Helper.ARG_STATUS, attachments.get(mediaPosition - 1).status);
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_STATUS, attachments.get(mediaPosition - 1).status);
new CachedBundle(MediaActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundleCached = new Bundle();
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId);
intentContext.putExtras(bundleCached);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);
});
});
}
binding.mediaDescription.setMovementMethod(LinkMovementMethod.getInstance());

View file

@ -82,7 +82,6 @@ public class SearchResultTabActivity extends BaseBarActivity {
Bundle b = getIntent().getExtras();
if (b != null) {
search = b.getString(Helper.ARG_SEARCH_KEYWORD, null);
}
if (search == null) {
Toasty.error(SearchResultTabActivity.this, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();

View file

@ -54,6 +54,7 @@ import app.fedilab.android.mastodon.client.entities.api.Notifications;
import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.Account;
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.ui.drawer.StatusAdapter;
import okhttp3.OkHttpClient;
@ -398,24 +399,24 @@ public class NotificationsHelper {
//Some others notification
final Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle args = new Bundle();
intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
intent.putExtra(Helper.PREF_USER_ID, account.user_id);
if (targeted_account != null) {
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
intent.putExtras(bundle);
args.putSerializable(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
} else if (targeted_status != null) {
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.INTENT_TARGETED_STATUS, targeted_status);
intent.putExtras(bundle);
args.putSerializable(Helper.INTENT_TARGETED_STATUS, targeted_status);
}
String finalMessage1 = message;
String finalTitle1 = title;
Helper.NotifType finalNotifType1 = notifType;
new CachedBundle(context).insertBundle(args, account, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.putExtra(Helper.PREF_USER_INSTANCE, account.instance);
notificationUrl = notification.account.avatar;
Handler mainHandler = new Handler(Looper.getMainLooper());
final String finalNotificationUrl = notificationUrl;
Helper.NotifType finalNotifType = notifType;
String finalMessage = message;
String finalTitle = title;
final String finalNotificationUrl = notification.account.avatar;
StatusAdapter.sendAction(context, Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION, null, null);
Runnable myRunnable = () -> Glide.with(context)
.asBitmap()
@ -423,14 +424,14 @@ public class NotificationsHelper {
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
Helper.notify_user(context, account, intent, resource, finalNotifType, finalTitle, finalMessage);
Helper.notify_user(context, account, intent, resource, finalNotifType1, finalTitle1, finalMessage1);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
getMainLogo(context)), finalNotifType, finalTitle, finalMessage);
getMainLogo(context)), finalNotifType1, finalTitle1, finalMessage1);
}
@Override
@ -439,7 +440,7 @@ public class NotificationsHelper {
}
});
mainHandler.post(myRunnable);
});
}
}

View file

@ -2225,8 +2225,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
MastodonHelper.scheduleBoost(context, MastodonHelper.ScheduleType.BOOST, statusToDeal, null, null);
} else if (itemId == R.id.action_admin) {
Intent intent = new Intent(context, AdminAccountActivity.class);
intent.putExtra(Helper.ARG_ACCOUNT_ID, statusToDeal.account.id);
Bundle args = new Bundle();
args.putString(Helper.ARG_ACCOUNT_ID, statusToDeal.account.id);
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_open_browser) {
Helper.openBrowser(context, statusToDeal.url);
} else if (itemId == R.id.action_remove) {
@ -2487,9 +2493,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
});
holder.binding.actionButtonQuote.setOnClickListener(v -> {
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_QUOTED_MESSAGE, statusToDeal);
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_QUOTED_MESSAGE, 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);
});
});
holder.binding.actionButtonReply.setOnClickListener(v -> {
if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();