Notifications

pull/984/head
Thomas 1 year ago
parent 86dc5d2f13
commit d7d5f286f5

@ -650,6 +650,24 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
* @param intent - Intent intent that will be cancelled * @param intent - Intent intent that will be cancelled
*/ */
private static void openNotifications(Activity activity, Intent intent) { private static void openNotifications(Activity activity, Intent intent) {
if (intent != null && intent.getExtras() != null) {
Bundle bundle = intent.getExtras();
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 b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, account);
intentAccount.putExtras(b);
intentAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intentAccount);
} else if (status != null) {
Intent intentContext = new Intent(activity, ContextActivity.class);
intentContext.putExtra(Helper.ARG_STATUS, status);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intentContext);
}
}
final Handler handler = new Handler(); final Handler handler = new Handler();
handler.postDelayed(() -> { handler.postDelayed(() -> {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
@ -682,6 +700,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
intent.removeExtra(Helper.INTENT_ACTION); intent.removeExtra(Helper.INTENT_ACTION);
} }
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
public static void mamageNewIntent(Activity activity, Intent intent) { public static void mamageNewIntent(Activity activity, Intent intent) {
if (intent == null) if (intent == null)

@ -327,6 +327,7 @@ public class Helper {
public static final int OPEN_NOTIFICATION = 2; public static final int OPEN_NOTIFICATION = 2;
public static final int OPEN_WITH_ANOTHER_ACCOUNT = 3; public static final int OPEN_WITH_ANOTHER_ACCOUNT = 3;
public static final String INTENT_TARGETED_ACCOUNT = "INTENT_TARGETED_ACCOUNT"; public static final String INTENT_TARGETED_ACCOUNT = "INTENT_TARGETED_ACCOUNT";
public static final String INTENT_TARGETED_STATUS = "INTENT_TARGETED_STATUS";
public static final String INTENT_SEND_MODIFIED_IMAGE = "INTENT_SEND_MODIFIED_IMAGE"; public static final String INTENT_SEND_MODIFIED_IMAGE = "INTENT_SEND_MODIFIED_IMAGE";
public static final String INTENT_COMPOSE_ERROR_MESSAGE = "INTENT_COMPOSE_ERROR_MESSAGE"; public static final String INTENT_COMPOSE_ERROR_MESSAGE = "INTENT_COMPOSE_ERROR_MESSAGE";
public static final String TEMP_MEDIA_DIRECTORY = "TEMP_MEDIA_DIRECTORY"; public static final String TEMP_MEDIA_DIRECTORY = "TEMP_MEDIA_DIRECTORY";

@ -24,6 +24,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.Html; import android.text.Html;
@ -50,6 +51,7 @@ import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.mastodon.client.endpoints.MastodonNotificationsService; import app.fedilab.android.mastodon.client.endpoints.MastodonNotificationsService;
import app.fedilab.android.mastodon.client.entities.api.Notification; import app.fedilab.android.mastodon.client.entities.api.Notification;
import app.fedilab.android.mastodon.client.entities.api.Notifications; 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.Account;
import app.fedilab.android.mastodon.client.entities.app.BaseAccount; import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
@ -211,7 +213,8 @@ public class NotificationsHelper {
String notificationUrl; String notificationUrl;
String title = null; String title = null;
String message = null; String message = null;
String targeted_account = null; app.fedilab.android.mastodon.client.entities.api.Account targeted_account = null;
Status targeted_status = null;
Helper.NotifType notifType = Helper.NotifType.MENTION; Helper.NotifType notifType = Helper.NotifType.MENTION;
switch (notification.type) { switch (notification.type) {
case "mention": case "mention":
@ -232,6 +235,7 @@ public class NotificationsHelper {
else else
message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
} }
targeted_status = notification.status;
} }
} }
break; break;
@ -254,6 +258,7 @@ public class NotificationsHelper {
else else
message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
} }
targeted_status = notification.status;
} }
} }
break; break;
@ -309,7 +314,7 @@ public class NotificationsHelper {
message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_follow_request)); message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_follow_request));
else else
message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow_request)); message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow_request));
targeted_account = notification.account.id; targeted_account = notification.account;
} }
break; break;
case "follow": case "follow":
@ -320,7 +325,7 @@ public class NotificationsHelper {
message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_follow)); message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_follow));
else else
message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow)); message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow));
targeted_account = notification.account.id; targeted_account = notification.account;
} }
break; break;
case "poll": case "poll":
@ -361,6 +366,7 @@ public class NotificationsHelper {
else else
message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
} }
targeted_status = notification.status;
} }
} }
break; break;
@ -372,7 +378,7 @@ public class NotificationsHelper {
message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_signed_up)); message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_signed_up));
else else
message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_signed_up)); message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_signed_up));
targeted_account = notification.account.id; targeted_account = notification.account;
} }
break; break;
case "admin.report": case "admin.report":
@ -383,7 +389,7 @@ public class NotificationsHelper {
message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reported)); message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reported));
else else
message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reported)); message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reported));
targeted_account = notification.account.id; targeted_account = notification.account;
} }
break; break;
default: default:
@ -394,8 +400,15 @@ public class NotificationsHelper {
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
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) {
intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); Bundle bundle = new Bundle();
bundle.putSerializable(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
intent.putExtras(bundle);
} else if (targeted_status != null) {
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.INTENT_TARGETED_STATUS, targeted_status);
intent.putExtras(bundle);
}
intent.putExtra(Helper.PREF_USER_INSTANCE, account.instance); intent.putExtra(Helper.PREF_USER_INSTANCE, account.instance);
notificationUrl = notification.account.avatar; notificationUrl = notification.account.avatar;
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());

Loading…
Cancel
Save