mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix potential crashes when clicking on notifications
This commit is contained in:
parent
886b74c171
commit
a1a6005ca0
5 changed files with 89 additions and 68 deletions
|
@ -675,32 +675,35 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
*/
|
*/
|
||||||
private static void openNotifications(Activity activity, Intent intent) {
|
private static void openNotifications(Activity activity, Intent intent) {
|
||||||
if (intent != null && intent.getExtras() != null) {
|
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);
|
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);
|
Status status = (Status) bundle.getSerializable(Helper.INTENT_TARGETED_STATUS);
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
Intent intentAccount = new Intent(activity, ProfileActivity.class);
|
Intent intentAccount = new Intent(activity, ProfileActivity.class);
|
||||||
Bundle args = new Bundle();
|
Bundle args2 = new Bundle();
|
||||||
args.putSerializable(Helper.ARG_ACCOUNT, account);
|
args2.putSerializable(Helper.ARG_ACCOUNT, account);
|
||||||
new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
|
new CachedBundle(activity).insertBundle(args2, currentAccount, bundleId2 -> {
|
||||||
Bundle bundleCached = new Bundle();
|
Bundle bundleCached = new Bundle();
|
||||||
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId);
|
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId2);
|
||||||
intentAccount.putExtras(bundleCached);
|
intentAccount.putExtras(bundleCached);
|
||||||
intentAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intentAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
activity.startActivity(intentAccount);
|
activity.startActivity(intentAccount);
|
||||||
});
|
});
|
||||||
} else if (status != null) {
|
} else if (status != null) {
|
||||||
Intent intentContext = new Intent(activity, ContextActivity.class);
|
Intent intentContext = new Intent(activity, ContextActivity.class);
|
||||||
Bundle args = new Bundle();
|
Bundle args2 = new Bundle();
|
||||||
args.putSerializable(Helper.ARG_STATUS, status);
|
args2.putSerializable(Helper.ARG_STATUS, status);
|
||||||
new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
|
new CachedBundle(activity).insertBundle(args2, currentAccount, bundleId2 -> {
|
||||||
Bundle bundleCached = new Bundle();
|
Bundle bundleCached = new Bundle();
|
||||||
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId);
|
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId2);
|
||||||
intentContext.putExtras(bundleCached);
|
intentContext.putExtras(bundleCached);
|
||||||
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
activity.startActivity(intentContext);
|
activity.startActivity(intentContext);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
handler.postDelayed(() -> {
|
handler.postDelayed(() -> {
|
||||||
|
|
|
@ -171,10 +171,16 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
|
||||||
if (attachments.get(mediaPosition - 1).status != null) {
|
if (attachments.get(mediaPosition - 1).status != null) {
|
||||||
binding.originalMessage.setOnClickListener(v -> {
|
binding.originalMessage.setOnClickListener(v -> {
|
||||||
Intent intentContext = new Intent(MediaActivity.this, ContextActivity.class);
|
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);
|
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startActivity(intentContext);
|
startActivity(intentContext);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.mediaDescription.setMovementMethod(LinkMovementMethod.getInstance());
|
binding.mediaDescription.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
|
@ -82,7 +82,6 @@ public class SearchResultTabActivity extends BaseBarActivity {
|
||||||
Bundle b = getIntent().getExtras();
|
Bundle b = getIntent().getExtras();
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
search = b.getString(Helper.ARG_SEARCH_KEYWORD, null);
|
search = b.getString(Helper.ARG_SEARCH_KEYWORD, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (search == null) {
|
if (search == null) {
|
||||||
Toasty.error(SearchResultTabActivity.this, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
|
Toasty.error(SearchResultTabActivity.this, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
|
||||||
|
|
|
@ -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.api.Status;
|
||||||
import app.fedilab.android.mastodon.client.entities.app.Account;
|
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.BaseAccount;
|
||||||
|
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
|
||||||
import app.fedilab.android.mastodon.exception.DBException;
|
import app.fedilab.android.mastodon.exception.DBException;
|
||||||
import app.fedilab.android.mastodon.ui.drawer.StatusAdapter;
|
import app.fedilab.android.mastodon.ui.drawer.StatusAdapter;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
@ -398,24 +399,24 @@ public class NotificationsHelper {
|
||||||
//Some others notification
|
//Some others notification
|
||||||
final Intent intent = new Intent(context, MainActivity.class);
|
final Intent intent = new Intent(context, MainActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
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.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
|
||||||
intent.putExtra(Helper.PREF_USER_ID, account.user_id);
|
intent.putExtra(Helper.PREF_USER_ID, account.user_id);
|
||||||
if (targeted_account != null) {
|
if (targeted_account != null) {
|
||||||
Bundle bundle = new Bundle();
|
args.putSerializable(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
|
||||||
bundle.putSerializable(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
|
|
||||||
intent.putExtras(bundle);
|
|
||||||
} else if (targeted_status != null) {
|
} else if (targeted_status != null) {
|
||||||
Bundle bundle = new Bundle();
|
args.putSerializable(Helper.INTENT_TARGETED_STATUS, targeted_status);
|
||||||
bundle.putSerializable(Helper.INTENT_TARGETED_STATUS, targeted_status);
|
|
||||||
intent.putExtras(bundle);
|
|
||||||
}
|
}
|
||||||
|
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);
|
intent.putExtra(Helper.PREF_USER_INSTANCE, account.instance);
|
||||||
notificationUrl = notification.account.avatar;
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
final String finalNotificationUrl = notificationUrl;
|
final String finalNotificationUrl = notification.account.avatar;
|
||||||
Helper.NotifType finalNotifType = notifType;
|
|
||||||
String finalMessage = message;
|
|
||||||
String finalTitle = title;
|
|
||||||
StatusAdapter.sendAction(context, Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION, null, null);
|
StatusAdapter.sendAction(context, Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION, null, null);
|
||||||
Runnable myRunnable = () -> Glide.with(context)
|
Runnable myRunnable = () -> Glide.with(context)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
|
@ -423,14 +424,14 @@ public class NotificationsHelper {
|
||||||
.into(new CustomTarget<Bitmap>() {
|
.into(new CustomTarget<Bitmap>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
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
|
@Override
|
||||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||||
super.onLoadFailed(errorDrawable);
|
super.onLoadFailed(errorDrawable);
|
||||||
Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||||
getMainLogo(context)), finalNotifType, finalTitle, finalMessage);
|
getMainLogo(context)), finalNotifType1, finalTitle1, finalMessage1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -439,7 +440,7 @@ public class NotificationsHelper {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2225,8 +2225,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
MastodonHelper.scheduleBoost(context, MastodonHelper.ScheduleType.BOOST, statusToDeal, null, null);
|
MastodonHelper.scheduleBoost(context, MastodonHelper.ScheduleType.BOOST, statusToDeal, null, null);
|
||||||
} else if (itemId == R.id.action_admin) {
|
} else if (itemId == R.id.action_admin) {
|
||||||
Intent intent = new Intent(context, AdminAccountActivity.class);
|
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);
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
} else if (itemId == R.id.action_open_browser) {
|
} else if (itemId == R.id.action_open_browser) {
|
||||||
Helper.openBrowser(context, statusToDeal.url);
|
Helper.openBrowser(context, statusToDeal.url);
|
||||||
} else if (itemId == R.id.action_remove) {
|
} else if (itemId == R.id.action_remove) {
|
||||||
|
@ -2487,9 +2493,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
});
|
});
|
||||||
holder.binding.actionButtonQuote.setOnClickListener(v -> {
|
holder.binding.actionButtonQuote.setOnClickListener(v -> {
|
||||||
Intent intent = new Intent(context, ComposeActivity.class);
|
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);
|
context.startActivity(intent);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
holder.binding.actionButtonReply.setOnClickListener(v -> {
|
holder.binding.actionButtonReply.setOnClickListener(v -> {
|
||||||
if (remote) {
|
if (remote) {
|
||||||
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
|
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
|
||||||
|
|
Loading…
Reference in a new issue