Commit d7d5f286 authored by Thomas's avatar Thomas
Browse files

Notifications

parent 86dc5d2f
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -650,6 +650,24 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
     * @param intent - Intent intent that will be cancelled
     */
    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();
        handler.postDelayed(() -> {
            SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
@@ -682,6 +700,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        intent.removeExtra(Helper.INTENT_ACTION);
    }


    @SuppressLint("ApplySharedPref")
    public static void mamageNewIntent(Activity activity, Intent intent) {
        if (intent == null)
+1 −0
Original line number Diff line number Diff line
@@ -327,6 +327,7 @@ public class Helper {
    public static final int OPEN_NOTIFICATION = 2;
    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_STATUS = "INTENT_TARGETED_STATUS";
    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 TEMP_MEDIA_DIRECTORY = "TEMP_MEDIA_DIRECTORY";
+20 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
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.entities.api.Notification;
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.exception.DBException;
@@ -211,7 +213,8 @@ public class NotificationsHelper {
            String notificationUrl;
            String title = 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;
            switch (notification.type) {
                case "mention":
@@ -232,6 +235,7 @@ public class NotificationsHelper {
                                else
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                            targeted_status = notification.status;
                        }
                    }
                    break;
@@ -254,6 +258,7 @@ public class NotificationsHelper {
                                else
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                            targeted_status = notification.status;
                        }
                    }
                    break;
@@ -309,7 +314,7 @@ public class NotificationsHelper {
                            message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_follow_request));
                        else
                            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;
                case "follow":
@@ -320,7 +325,7 @@ public class NotificationsHelper {
                            message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_follow));
                        else
                            message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_follow));
                        targeted_account = notification.account.id;
                        targeted_account = notification.account;
                    }
                    break;
                case "poll":
@@ -361,6 +366,7 @@ public class NotificationsHelper {
                                else
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                            targeted_status = notification.status;
                        }
                    }
                    break;
@@ -372,7 +378,7 @@ public class NotificationsHelper {
                            message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_signed_up));
                        else
                            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;
                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));
                        else
                            message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reported));
                        targeted_account = notification.account.id;
                        targeted_account = notification.account;
                    }
                    break;
                default:
@@ -394,8 +400,15 @@ public class NotificationsHelper {
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
                intent.putExtra(Helper.PREF_USER_ID, account.user_id);
                if (targeted_account != null)
                    intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
                if (targeted_account != null) {
                    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);
                notificationUrl = notification.account.avatar;
                Handler mainHandler = new Handler(Looper.getMainLooper());