From bd8baf283fe65a21c4822b94fd064d2a58148ccb Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 16 Sep 2021 15:58:26 +0300 Subject: [PATCH] Add Main-to-Topic redirect (for notification opened topics) --- .../gr/thmmy/mthmmy/activities/main/MainActivity.java | 11 +++++++++++ .../gr/thmmy/mthmmy/services/NotificationService.java | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index ae01b700..34ddfc59 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -254,6 +254,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF private void redirectToActivityFromIntent(Intent intent) { if (intent != null) { Uri uri = intent.getData(); + Bundle extras = intent.getExtras(); if (uri != null) { ThmmyPage.PageCategory page = ThmmyPage.resolvePageCategory(uri); if (!page.is(ThmmyPage.PageCategory.NOT_THMMY)) { @@ -290,6 +291,16 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "This is not thmmy.", Toast.LENGTH_LONG).show(); } } + else if(extras!=null){ + String topicTitle = extras.getString(BUNDLE_TOPIC_TITLE); + String topicPageUrl = extras.getString(BUNDLE_TOPIC_URL); + if(topicTitle!=null && topicPageUrl!=null){ + Intent redirectIntent = new Intent(MainActivity.this, TopicActivity.class); + redirectIntent.putExtra(BUNDLE_TOPIC_URL, topicPageUrl); + redirectIntent.putExtra(BUNDLE_TOPIC_TITLE, topicTitle); + startActivity(redirectIntent); + } + } } } } \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java index 0ea4527f..b271e39f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -28,7 +28,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import gr.thmmy.mthmmy.R; -import gr.thmmy.mthmmy.activities.topic.TopicActivity; +import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.PostNotification; @@ -172,7 +172,7 @@ public class NotificationService extends FirebaseMessagingService { //Builds notification String topicUrl = "https://www.thmmy.gr/smf/index.php?topic=" + postNotification.getTopicId() + "." + postNotification.getPostId(); - Intent intent = new Intent(this, TopicActivity.class); + Intent intent = new Intent(this, MainActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_TOPIC_URL, topicUrl); extras.putString(BUNDLE_TOPIC_TITLE, postNotification.getTopicTitle());