diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java index 45220494..4c4614ef 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java @@ -2,12 +2,16 @@ package gr.thmmy.mthmmy.activities; import android.content.Intent; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.graphics.drawable.VectorDrawableCompat; import android.view.LayoutInflater; import android.view.View; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.board.BoardActivity; @@ -27,6 +31,9 @@ public class BookmarkActivity extends BaseActivity { private TextView boardsTitle; private TextView topicsTitle; + private static Drawable notificationsEnabledButtonImage; + private static Drawable notificationsDisabledButtonImage; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -44,6 +51,18 @@ public class BookmarkActivity extends BaseActivity { createDrawer(); drawer.setSelection(BOOKMARKS_ID); + 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); + } + LinearLayout bookmarksLinearView = findViewById(R.id.bookmarks_container); LayoutInflater layoutInflater = getLayoutInflater(); @@ -131,10 +150,21 @@ public class BookmarkActivity extends BaseActivity { } }); ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle()); - (row.findViewById(R.id.toggle_notification)).setOnClickListener(new View.OnClickListener() { + + final ImageButton notificationsEnabledButton = row.findViewById(R.id.toggle_notification); + if (!bookmarkedTopic.isNotificationsEnabled()){ + notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); + } + + notificationsEnabledButton.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View view) { - //TODO + if(toggleNotification(bookmarkedTopic)){ + notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage); + } else { + notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); + } } }); (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() { @@ -142,6 +172,7 @@ public class BookmarkActivity extends BaseActivity { public void onClick(View view) { removeBookmark(bookmarkedTopic); row.setVisibility(View.GONE); + Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); updateTitles(); } }); 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 742a73b3..1733986f 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 @@ -89,7 +89,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo getSupportActionBar().setDisplayShowHomeEnabled(true); } - thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl)); + thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl), false); setBoardBookmark((ImageButton) findViewById(R.id.bookmark)); createDrawer(); @@ -304,7 +304,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo || !Objects.equals(boardTitle, parsedTitle)) { boardTitle = parsedTitle; toolbar.setTitle(boardTitle); - thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl)); + thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl), false); } //Parse was successful 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 25cab734..936335be 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 @@ -204,7 +204,7 @@ public class TopicActivity extends BaseActivity { finish(); } - thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl)); + thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl), true); //Initializes graphics toolbar = findViewById(R.id.toolbar); @@ -631,7 +631,7 @@ public class TopicActivity extends BaseActivity { || !Objects.equals(topicTitle, parsedTitle)) { toolbarTitle.setText(parsedTitle); topicTitle = parsedTitle; - thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl)); + thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl), true); invalidateOptionsMenu(); } 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 559b297a..8d41f026 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -514,7 +514,7 @@ public abstract class BaseActivity extends AppCompatActivity { if (boardsBookmarked == null) return; if (bookmark.matchExists(boardsBookmarked)) { boardsBookmarked.remove(bookmark.findIndex(boardsBookmarked)); - } else boardsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId())); + } else boardsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId(), false)); updateBoardBookmarks(); } @@ -523,7 +523,7 @@ public abstract class BaseActivity extends AppCompatActivity { if (bookmark.matchExists(topicsBookmarked)) { topicsBookmarked.remove(bookmark.findIndex(topicsBookmarked)); } else { - topicsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId())); + topicsBookmarked.add(new Bookmark(bookmark.getTitle(), bookmark.getId(), true)); } updateTopicBookmarks(); } @@ -546,6 +546,18 @@ public abstract class BaseActivity extends AppCompatActivity { if (bookmark.matchExists(boardsBookmarked)) toggleBoardToBookmarks(bookmark); else if (bookmark.matchExists(topicsBookmarked)) toggleTopicToBookmarks(bookmark); } + + protected boolean toggleNotification(Bookmark bookmark){ + if (bookmark.matchExists(topicsBookmarked)){ + topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).toggleNotificationsEnabled(); + updateTopicBookmarks(); + + //TODO toggle firebase here! + + return topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled(); + } + return false; + } //-------------------------------------------BOOKMARKS END------------------------------------------ //-------PERMS--------- diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java index e9753046..9e2aae95 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java @@ -8,10 +8,12 @@ import java.util.Objects; public class Bookmark implements java.io.Serializable { private final String title, id; + private boolean isNotificationsEnabled; - public Bookmark(String title, String id) { + public Bookmark(String title, String id, boolean isNotificationsEnabled) { this.title = title; this.id = id; + this.isNotificationsEnabled = isNotificationsEnabled; } public String getTitle() { @@ -22,6 +24,14 @@ public class Bookmark implements java.io.Serializable { return id; } + public boolean isNotificationsEnabled() { + return isNotificationsEnabled; + } + + public void toggleNotificationsEnabled(){ + this.isNotificationsEnabled = !this.isNotificationsEnabled; + } + public boolean matchExists(ArrayList array) { if (array != null && !array.isEmpty()) { for (Bookmark bookmark : array) { @@ -52,7 +62,8 @@ public class Bookmark implements java.io.Serializable { for (Bookmark bookmark : arrayList) { if (bookmark != null) { returnString += (bookmark.getId() + "\t"); - returnString += (bookmark.getTitle() + "\n"); + returnString += (bookmark.getTitle() + "\t"); + returnString += (bookmark.isNotificationsEnabled() + "\n"); } } if (!Objects.equals(returnString, "")) return returnString; @@ -65,8 +76,8 @@ public class Bookmark implements java.io.Serializable { for (String line : lines) { if (line == null || line.isEmpty() || Objects.equals(line, "")) break; String[] parameters = line.split("\t"); - if (parameters.length != 2) break; - returnArray.add(new Bookmark(parameters[1], parameters[0])); + if (parameters.length != 3) break; + returnArray.add(new Bookmark(parameters[1], parameters[0], Boolean.parseBoolean(parameters[2]))); } return returnArray; } diff --git a/app/src/main/res/layout/activity_bookmark_topic_row.xml b/app/src/main/res/layout/activity_bookmark_topic_row.xml index 240268e6..c5b54d6f 100644 --- a/app/src/main/res/layout/activity_bookmark_topic_row.xml +++ b/app/src/main/res/layout/activity_bookmark_topic_row.xml @@ -30,7 +30,7 @@ android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:contentDescription="@string/toggle_notification" - app:srcCompat="@drawable/ic_notification_off"/> + app:srcCompat="@drawable/ic_notification_on"/>