diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
index 7e96d6ce..7251a4f9 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
@@ -95,7 +95,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
}
thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl), false);
- setBoardBookmark((ImageButton) findViewById(R.id.bookmark));
+ setBoardBookmark(findViewById(R.id.bookmark));
createDrawer();
progressBar = findViewById(R.id.progressBar);
@@ -167,7 +167,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override
public void onResume() {
super.onResume();
- refreshBoardBookmark((ImageButton) findViewById(R.id.bookmark));
+ refreshBoardBookmark(findViewById(R.id.bookmark));
}
@Override
@@ -318,11 +318,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
|| !Objects.equals(boardTitle, parsedTitle)) {
boardTitle = parsedTitle;
toolbar.setTitle(boardTitle);
- thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl), false);
+ thisPageBookmark = new Bookmark(boardTitle, "b" + ThmmyPage.getBoardId(boardUrl), true);
}
- Timber.d("topix " + tempTopics);
-
parsedTopics.clear();
parsedSubBoards.clear();
parsedTopics.addAll(tempTopics);
diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java
index 6b7dee26..1912b1de 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java
@@ -2,13 +2,16 @@ package gr.thmmy.mthmmy.activities.bookmarks;
import android.app.Activity;
import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
+import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -27,10 +30,14 @@ public class BoardBookmarksFragment extends Fragment {
protected static final String ARG_BOARD_BOOKMARKS = "BOARD_BOOKMARKS";
public static final String INTERACTION_CLICK_BOARD_BOOKMARK = "CLICK_BOARD_BOOKMARK";
+ public static final String INTERACTION_TOGGLE_BOARD_NOTIFICATION = "TOGGLE_BOARD_NOTIFICATION";
public static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK";
ArrayList boardBookmarks = null;
+ private static Drawable notificationsEnabledButtonImage;
+ private static Drawable notificationsDisabledButtonImage;
+
// Required empty public constructor
public BoardBookmarksFragment() {
}
@@ -59,6 +66,16 @@ public class BoardBookmarksFragment extends Fragment {
boardBookmarks = Bookmark.arrayFromString(bundledBoardBookmarks);
}
}
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ notificationsEnabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_on, null);
+ else
+ notificationsEnabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_on, null);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ notificationsDisabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_off, null);
+ else
+ notificationsDisabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_off, null);
}
@Override
@@ -74,31 +91,42 @@ public class BoardBookmarksFragment extends Fragment {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.fragment_bookmarks_board_row, bookmarksLinearView, false);
- row.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Activity activity = getActivity();
- if (activity instanceof BookmarkActivity){
- ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_CLICK_BOARD_BOOKMARK, bookmarkedBoard);
- }
+ row.setOnClickListener(view -> {
+ Activity activity = getActivity();
+ if (activity instanceof BookmarkActivity){
+ ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_CLICK_BOARD_BOOKMARK, bookmarkedBoard);
}
});
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedBoard.getTitle());
- (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Activity activity = getActivity();
- if (activity instanceof BookmarkActivity){
- ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_REMOVE_BOARD_BOOKMARK, bookmarkedBoard);
- boardBookmarks.remove(bookmarkedBoard);
- }
- row.setVisibility(View.GONE);
- if (boardBookmarks.isEmpty()){
- bookmarksLinearView.addView(bookmarksListEmptyMessage());
+ final ImageButton notificationsEnabledButton = row.findViewById(R.id.toggle_notification);
+ if (!bookmarkedBoard.isNotificationsEnabled()) {
+ notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage);
+ }
+
+ notificationsEnabledButton.setOnClickListener(view -> {
+ Activity activity = getActivity();
+ if (activity instanceof BookmarkActivity) {
+ if (((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_TOGGLE_BOARD_NOTIFICATION, bookmarkedBoard)) {
+ notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage);
+ } else {
+ notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage);
}
}
});
+
+ (row.findViewById(R.id.remove_bookmark)).setOnClickListener(view -> {
+ Activity activity = getActivity();
+ if (activity instanceof BookmarkActivity){
+ ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_REMOVE_BOARD_BOOKMARK, bookmarkedBoard);
+ boardBookmarks.remove(bookmarkedBoard);
+ }
+ row.setVisibility(View.GONE);
+
+ if (boardBookmarks.isEmpty()){
+ bookmarksLinearView.addView(bookmarksListEmptyMessage());
+ }
+ });
bookmarksLinearView.addView(row);
}
}
diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java
index 5dce5ed0..164e8f3f 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java
@@ -84,20 +84,26 @@ public class BookmarkActivity extends BaseActivity {
return true;
}
- public void onBoardInteractionListener(String interactionType, Bookmark bookmarkedBoard) {
- if (interactionType.equals(BoardBookmarksFragment.INTERACTION_CLICK_BOARD_BOOKMARK)) {
- Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class);
- Bundle extras = new Bundle();
- extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board="
- + bookmarkedBoard.getId() + ".0");
- extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle());
- intent.putExtras(extras);
- startActivity(intent);
- finish();
- } else if (interactionType.equals(BoardBookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK)) {
- removeBookmark(bookmarkedBoard);
- Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
+ public boolean onBoardInteractionListener(String interactionType, Bookmark bookmarkedBoard) {
+ switch (interactionType) {
+ case BoardBookmarksFragment.INTERACTION_CLICK_BOARD_BOOKMARK:
+ Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class);
+ Bundle extras = new Bundle();
+ extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board="
+ + bookmarkedBoard.getId() + ".0");
+ extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle());
+ intent.putExtras(extras);
+ startActivity(intent);
+ finish();
+ break;
+ case BoardBookmarksFragment.INTERACTION_TOGGLE_BOARD_NOTIFICATION:
+ return toggleNotification(bookmarkedBoard);
+ case BoardBookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK:
+ removeBookmark(bookmarkedBoard);
+ Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
+ break;
}
+ return true;
}
/**
diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java
index 7679ad2f..7b8b5305 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java
@@ -62,17 +62,15 @@ public class TopicBookmarksFragment extends Fragment {
}
}
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
notificationsEnabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_on, null);
- } else {
+ else
notificationsEnabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_on, null);
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
notificationsDisabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_off, null);
- } else {
+ else
notificationsDisabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_off, null);
- }
}
@Override
@@ -88,13 +86,10 @@ public class TopicBookmarksFragment extends Fragment {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.fragment_bookmarks_topic_row, bookmarksLinearView, false);
- row.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Activity activity = getActivity();
- if (activity instanceof BookmarkActivity) {
- ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_CLICK_TOPIC_BOOKMARK, bookmarkedTopic);
- }
+ row.setOnClickListener(view -> {
+ Activity activity = getActivity();
+ if (activity instanceof BookmarkActivity) {
+ ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_CLICK_TOPIC_BOOKMARK, bookmarkedTopic);
}
});
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle());
@@ -104,32 +99,26 @@ public class TopicBookmarksFragment extends Fragment {
notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage);
}
- notificationsEnabledButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Activity activity = getActivity();
- if (activity instanceof BookmarkActivity) {
- if (((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_TOGGLE_TOPIC_NOTIFICATION, bookmarkedTopic)) {
- notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage);
- } else {
- notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage);
- }
+ notificationsEnabledButton.setOnClickListener(view -> {
+ Activity activity = getActivity();
+ if (activity instanceof BookmarkActivity) {
+ if (((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_TOGGLE_TOPIC_NOTIFICATION, bookmarkedTopic)) {
+ notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage);
+ } else {
+ notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage);
}
}
});
- (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Activity activity = getActivity();
- if (activity instanceof BookmarkActivity) {
- ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_REMOVE_TOPIC_BOOKMARK, bookmarkedTopic);
- topicBookmarks.remove(bookmarkedTopic);
- }
- row.setVisibility(View.GONE);
+ (row.findViewById(R.id.remove_bookmark)).setOnClickListener(view -> {
+ Activity activity = getActivity();
+ if (activity instanceof BookmarkActivity) {
+ ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_REMOVE_TOPIC_BOOKMARK, bookmarkedTopic);
+ topicBookmarks.remove(bookmarkedTopic);
+ }
+ row.setVisibility(View.GONE);
- if (topicBookmarks.isEmpty()){
- bookmarksLinearView.addView(bookmarksListEmptyMessage());
- }
+ if (topicBookmarks.isEmpty()){
+ bookmarksLinearView.addView(bookmarksListEmptyMessage());
}
});
bookmarksLinearView.addView(row);
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 b0d1c98e..46dbdba5 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
@@ -78,7 +78,7 @@ import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType;
import static gr.thmmy.mthmmy.utils.LaunchType.LAUNCH_TYPE.FIRST_LAUNCH_EVER;
import static gr.thmmy.mthmmy.utils.LaunchType.LAUNCH_TYPE.INDETERMINATE;
-public abstract class BaseActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener{
+public abstract class BaseActivity extends AppCompatActivity {
// Client & Cookies
protected static OkHttpClient client;
@@ -117,9 +117,7 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
}
BaseViewModel baseViewModel = ViewModelProviders.of(this).get(BaseViewModel.class);
- baseViewModel.getCurrentPageBookmark().observe(this, thisPageBookmark -> {
- setTopicBookmark(thisPageBookmarkMenuButton);
- });
+ baseViewModel.getCurrentPageBookmark().observe(this, thisPageBookmark -> setTopicBookmark(thisPageBookmarkMenuButton));
}
@Override
@@ -577,7 +575,11 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
if (boardsBookmarked == null) return;
if (bookmark.matchExists(boardsBookmarked)) {
boardsBookmarked.remove(bookmark.findIndex(boardsBookmarked));
- } else boardsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId(), false));
+ FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId());
+ } else {
+ boardsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId(), false));
+ FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId());
+ }
updateBoardBookmarks();
}
@@ -617,13 +619,22 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).toggleNotificationsEnabled();
updateTopicBookmarks();
- if (topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled()) {
+ if (topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled())
FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId());
- } else {
+ else
FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId());
- }
return topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled();
+ } else if (bookmark.matchExists(boardsBookmarked)) {
+ boardsBookmarked.get(bookmark.findIndex(boardsBookmarked)).toggleNotificationsEnabled();
+ updateBoardBookmarks();
+
+ if (boardsBookmarked.get(bookmark.findIndex(boardsBookmarked)).isNotificationsEnabled())
+ FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId());
+ else
+ FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId());
+
+ return boardsBookmarked.get(bookmark.findIndex(boardsBookmarked)).isNotificationsEnabled();
}
return false;
}
@@ -727,14 +738,6 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
}
//----------------------------PRIVACY POLICY------------------
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (key.equals(getString(R.string.pref_pp_accepted_key)))
- if(!sharedPreferences.getBoolean(key, false))
- showUserConsentDialog();
- }
-
private void showUserConsentDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("User Agreement");
@@ -785,8 +788,6 @@ public abstract class BaseActivity extends AppCompatActivity implements SharedPr
}
}
-
-
//----------------------------------MISC----------------------
protected void setMainActivity(MainActivity mainActivity) {
this.mainActivity = mainActivity;
diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/PostNotification.java b/app/src/main/java/gr/thmmy/mthmmy/model/PostNotification.java
index 42985352..838dc2d3 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/model/PostNotification.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/model/PostNotification.java
@@ -8,10 +8,12 @@ package gr.thmmy.mthmmy.model;
*
.
*/
public class PostNotification {
- final int postId;
- final int topicId;
- final String topicTitle;
- final String poster;
+ private final int postId;
+ private final int topicId;
+ private final String topicTitle;
+ private final String poster;
+ private final int boardId;
+ private final String boardTitle;
// Suppresses default constructor
@SuppressWarnings("unused")
@@ -20,6 +22,8 @@ public class PostNotification {
this.topicId = -1;
this.topicTitle = null;
this.poster = null;
+ this.boardId = -1;
+ this.boardTitle = null;
}
/**
@@ -30,12 +34,17 @@ public class PostNotification {
* @param topicId this post's topicId
* @param topicTitle this post's topicTitle
* @param poster username of this post's author
+ * @param boardId one of this post's boardIds (-1 if it is a topic notification)
+ * @param boardTitle one of this post's boardTitles (null if it is a topic notification)
*/
- public PostNotification(int postId, int topicId, String topicTitle, String poster) {
+ public PostNotification(int postId, int topicId, String topicTitle, String poster, int boardId, String boardTitle) {
this.postId = postId;
this.topicId = topicId;
this.topicTitle = topicTitle;
this.poster = poster;
+ this.boardId = boardId;
+ this.boardTitle = boardTitle;
+
}
/**
@@ -73,6 +82,24 @@ public class PostNotification {
public String getPoster() {
return poster;
}
+
+ /**
+ * Gets this post's boardId.
+ *
+ * @return this post's boardId
+ */
+ public int getBoardId() {
+ return boardId;
+ }
+
+ /**
+ * Gets this post's boardTitle.
+ *
+ * @return this post's boardTitle
+ */
+ public String getBoardTitle() {
+ return boardTitle;
+ }
}
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 a383e282..02319378 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java
@@ -54,9 +54,19 @@ public class NotificationService extends FirebaseMessagingService {
int postId = Integer.parseInt(json.getString("postId"));
String topicTitle = json.getString("topicTitle");
String poster = json.getString("poster");
- sendNotification(new PostNotification(postId, topicId, topicTitle, poster));
+ int boardId = -1;
+ String boardTitle = null;
+ if(remoteMessage.getFrom().contains("b")){
+ Timber.i("FCM BOARD type message detected.");
+ boardId = Integer.parseInt(json.getString("boardId"));
+ boardTitle = json.getString("boardTitle");
+ }
+ else
+ Timber.i("FCM TOPIC type message detected.");
+
+ sendNotification(new PostNotification(postId, topicId, topicTitle, poster, boardId, boardTitle));
} else
- Timber.v("Notification suppressed (own userID).");
+ Timber.i("Notification suppressed (own userID).");
} catch (JSONException e) {
Timber.e(e, "JSON Exception");
}
@@ -78,6 +88,8 @@ public class NotificationService extends FirebaseMessagingService {
private void sendNotification(PostNotification postNotification) {
Timber.i("Creating a notification...");
+ boolean isTopicNotification = postNotification.getBoardId() == -1;
+
//Reads notifications preferences
SharedPreferences settingsFile = getSharedPreferences(SETTINGS_SHARED_PREFS, Context.MODE_PRIVATE);
String notificationsSound = settingsFile.getString(SELECTED_RINGTONE, null);
@@ -118,15 +130,30 @@ public class NotificationService extends FirebaseMessagingService {
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode++, intent,
PendingIntent.FLAG_ONE_SHOT);
- final int topicId = postNotification.getTopicId();
- String contentText = "New post by " + postNotification.getPoster();
+ int notificationId;
+ String contentText;
+ if(isTopicNotification){
+ notificationId = postNotification.getTopicId();
+ contentText = "New post by " + postNotification.getPoster();
+ }
+ else{
+ // Using Cantor pairing function (plus the minus sign) for id uniqueness
+ int k1 = postNotification.getTopicId();
+ int k2 = postNotification.getBoardId();
+ notificationId = -(((k1+k2)*(k1+k2+1))/2+k2);
+ contentText = "New post in " + postNotification.getTopicTitle();
+ }
+
int newPostsCount = 1;
if (buildVersion >= Build.VERSION_CODES.M) {
- Notification existingNotification = getActiveNotification(topicId);
+ Notification existingNotification = getActiveNotification(notificationId);
if (existingNotification != null) {
newPostsCount = existingNotification.extras.getInt(NEW_POSTS_COUNT) + 1;
- contentText = newPostsCount + " new posts";
+ if(isTopicNotification)
+ contentText = newPostsCount + " new posts";
+ else
+ contentText = newPostsCount + " new posts in " + postNotification.getTopicTitle();
}
}
@@ -136,13 +163,18 @@ public class NotificationService extends FirebaseMessagingService {
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
- .setContentTitle(postNotification.getTopicTitle())
.setContentText(contentText)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setGroup(GROUP_KEY)
.addExtras(notificationExtras);
+ if(isTopicNotification)
+ notificationBuilder.setContentTitle(postNotification.getTopicTitle());
+
+ else
+ notificationBuilder.setContentTitle(postNotification.getBoardTitle());
+
//Applies user's notifications preferences
if (notificationDefaultValues != -1) {
notificationBuilder.setDefaults(notificationDefaultValues);
@@ -162,7 +194,7 @@ public class NotificationService extends FirebaseMessagingService {
boolean createSummaryNotification = false;
if (buildVersion >= Build.VERSION_CODES.M)
- createSummaryNotification = otherNotificationsExist(topicId);
+ createSummaryNotification = otherNotificationsExist(notificationId);
NotificationCompat.Builder summaryNotificationBuilder = null;
@@ -174,7 +206,7 @@ public class NotificationService extends FirebaseMessagingService {
.setGroup(GROUP_KEY)
.setAutoCancel(true)
.setStyle(new NotificationCompat.InboxStyle()
- .setSummaryText("New Posts"))
+ .setSummaryText("New Posts"))
.setDefaults(Notification.DEFAULT_ALL);
}
@@ -185,7 +217,7 @@ public class NotificationService extends FirebaseMessagingService {
if (buildVersion >= Build.VERSION_CODES.O)
notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH));
- notificationManager.notify(NEW_POST_TAG, topicId, notificationBuilder.build());
+ notificationManager.notify(NEW_POST_TAG, notificationId, notificationBuilder.build());
if (createSummaryNotification)
notificationManager.notify(SUMMARY_TAG, 0, summaryNotificationBuilder.build());
diff --git a/app/src/main/res/layout/fragment_bookmarks_board_row.xml b/app/src/main/res/layout/fragment_bookmarks_board_row.xml
index d59b6c45..b3e17ebe 100644
--- a/app/src/main/res/layout/fragment_bookmarks_board_row.xml
+++ b/app/src/main/res/layout/fragment_bookmarks_board_row.xml
@@ -23,6 +23,18 @@
android:textColor="@color/primary_text"
android:textSize="18sp"/>
+
+
Info
OK
Cancel
- pref_pp_accepted
"To use mTHMMY you have to agree to our Privacy Policy by choosing one of the buttons below. Choose \"Yes, I want to help\", if you consent to the collection of anonymized data that will help us improve the app. Otherwise, choose \"Nope, leave me alone\". You can change your preferences any time through the app's Settings.