Browse Source

Add Main-to-Topic redirect (for notification opened topics)

develop
Ezerous 3 years ago
parent
commit
bd8baf283f
  1. 11
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java

11
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) { private void redirectToActivityFromIntent(Intent intent) {
if (intent != null) { if (intent != null) {
Uri uri = intent.getData(); Uri uri = intent.getData();
Bundle extras = intent.getExtras();
if (uri != null) { if (uri != null) {
ThmmyPage.PageCategory page = ThmmyPage.resolvePageCategory(uri); ThmmyPage.PageCategory page = ThmmyPage.resolvePageCategory(uri);
if (!page.is(ThmmyPage.PageCategory.NOT_THMMY)) { 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(); 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);
}
}
} }
} }
} }

4
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 java.util.regex.Pattern;
import gr.thmmy.mthmmy.R; 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.base.BaseApplication;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.PostNotification; import gr.thmmy.mthmmy.model.PostNotification;
@ -172,7 +172,7 @@ public class NotificationService extends FirebaseMessagingService {
//Builds notification //Builds notification
String topicUrl = "https://www.thmmy.gr/smf/index.php?topic=" + postNotification.getTopicId() + "." + postNotification.getPostId(); 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(); Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, topicUrl); extras.putString(BUNDLE_TOPIC_URL, topicUrl);
extras.putString(BUNDLE_TOPIC_TITLE, postNotification.getTopicTitle()); extras.putString(BUNDLE_TOPIC_TITLE, postNotification.getTopicTitle());

Loading…
Cancel
Save