From e804ce30ebd86ae19f7c7265ad7a5c3ed444be6b Mon Sep 17 00:00:00 2001 From: Apostolof Date: Mon, 14 May 2018 14:44:17 +0300 Subject: [PATCH] Add connection to notifications system backend --- app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 8d41f026..ca50672c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -19,6 +19,7 @@ import android.view.View; import android.widget.ImageButton; import android.widget.Toast; +import com.google.firebase.messaging.FirebaseMessaging; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.google_material_typeface_library.GoogleMaterial; import com.mikepenz.iconics.IconicsDrawable; @@ -522,8 +523,10 @@ public abstract class BaseActivity extends AppCompatActivity { if (topicsBookmarked == null) return; if (bookmark.matchExists(topicsBookmarked)) { topicsBookmarked.remove(bookmark.findIndex(topicsBookmarked)); + FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId()); } else { topicsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId(), true)); + FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId()); } updateTopicBookmarks(); } @@ -552,7 +555,11 @@ public abstract class BaseActivity extends AppCompatActivity { topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).toggleNotificationsEnabled(); updateTopicBookmarks(); - //TODO toggle firebase here! + if (topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled()){ + FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId()); + } else { + FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId()); + } return topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled(); }