Browse Source

Clear notification when manually opening topic's last page

pull/24/head
Ezerous 7 years ago
parent
commit
e066d6a7d2
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 10
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java

16
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:

10
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();
}
}

3
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";

Loading…
Cancel
Save