diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index e18dc2e7..e1789a12 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.activities.topic; import android.annotation.SuppressLint; +import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.graphics.Rect; @@ -64,6 +65,7 @@ import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_ import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; +import static gr.thmmy.mthmmy.services.NotificationService.NEW_POST_TAG; /** * Activity for parsing and rendering topics. When creating an Intent of this activity you need to @@ -110,6 +112,10 @@ public class TopicActivity extends BaseActivity { * Holds the url of this page */ private String loadedPageUrl = ""; + /** + * Holds the topicId of this page + */ + private int loadedPageTopicId = -1; /** * Becomes true after user has posted in this topic and the page is being reloaded and false * when topic's reloading is done @@ -612,6 +618,8 @@ public class TopicActivity extends BaseActivity { document = Jsoup.parse(response.body().string()); localPostsList = parse(document); + loadedPageTopicId = Integer.parseInt(ThmmyPage.getTopicId(loadedPageUrl)); + //Finds the position of the focused message if present for (int i = 0; i < localPostsList.size(); ++i) { if (localPostsList.get(i).getPostIndex() == postFocus) { @@ -641,7 +649,7 @@ public class TopicActivity extends BaseActivity { || !Objects.equals(topicTitle, parsedTitle)) { toolbarTitle.setText(parsedTitle); topicTitle = parsedTitle; - thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl), true); + thisPageBookmark = new Bookmark(parsedTitle, Integer.toString(loadedPageTopicId), true); invalidateOptionsMenu(); } @@ -665,6 +673,12 @@ public class TopicActivity extends BaseActivity { pageIndicator.setText(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); pageRequestValue = thisPage; + if(thisPage==numberOfPages){ + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + if(notificationManager!=null) + notificationManager.cancel(NEW_POST_TAG, loadedPageTopicId); + } + paginationEnabled(true); break; case NETWORK_ERROR: diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index d5cb13ec..5a98d618 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -465,11 +465,11 @@ public abstract class BaseActivity extends AppCompatActivity { if (thisPageBookmark.matchExists(topicsBookmarked)) { thisPageBookmarkMenuButton.setIcon(notBookmarked); toggleTopicToBookmarks(thisPageBookmark); - Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); } else { thisPageBookmarkMenuButton.setIcon(bookmarked); toggleTopicToBookmarks(thisPageBookmark); - Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show(); + Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); } } @@ -484,10 +484,10 @@ public abstract class BaseActivity extends AppCompatActivity { public void onClick(View view) { if (thisPageBookmark.matchExists(boardsBookmarked)) { thisPageBookmarkImageButton.setImageDrawable(notBookmarked); - Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show(); } else { thisPageBookmarkImageButton.setImageDrawable(bookmarked); - Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show(); + Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show(); } toggleBoardToBookmarks(thisPageBookmark); } @@ -670,7 +670,7 @@ public abstract class BaseActivity extends AppCompatActivity { BaseActivity.this.startActivity(intent); }catch (Exception e){ Timber.e(e,"Couldn't open downloaded file..."); - Toast.makeText(BaseActivity.this, "Couldn't open file...", Toast.LENGTH_SHORT).show(); + Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); } } 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 6e4419c0..ae439dd9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java @@ -35,6 +35,7 @@ public class NotificationService extends FirebaseMessagingService { public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); if (remoteMessage.getData().size() > 0) { + Timber.i("FCM data message received."); JSONObject json = new JSONObject(remoteMessage.getData()); try { int userId = BaseApplication.getInstance().getSessionManager().getUserId(); @@ -61,7 +62,7 @@ public class NotificationService extends FirebaseMessagingService { private static int requestCode = 0; private static final String NEW_POSTS_COUNT = "newPostsCount"; - private static final String NEW_POST_TAG = "NEW_POST"; + public static final String NEW_POST_TAG = "NEW_POST"; private static final String SUMMARY_TAG = "SUMMARY"; private static final String DELETED_MESSAGES_TAG = "DELETED_MESSAGES";