Browse Source

Some refactoring

pull/61/merge
Ezerous 6 years ago
parent
commit
131bd0736a
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java
  3. 9
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java
  4. 0
      app/src/main/res/layout/fragment_bookmarks_row.xml
  5. 50
      app/src/main/res/layout/fragment_bookmarks_topic_row.xml

2
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java

@ -90,7 +90,7 @@ public class BoardBookmarksFragment extends Fragment {
for (final Bookmark bookmarkedBoard : boardBookmarks) { for (final Bookmark bookmarkedBoard : boardBookmarks) {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) { if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate( final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.fragment_bookmarks_board_row, bookmarksLinearView, false); R.layout.fragment_bookmarks_row, bookmarksLinearView, false);
row.setOnClickListener(view -> { row.setOnClickListener(view -> {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity instanceof BookmarkActivity){ if (activity instanceof BookmarkActivity){

2
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java

@ -85,7 +85,7 @@ public class TopicBookmarksFragment extends Fragment {
for (final Bookmark bookmarkedTopic : topicBookmarks) { for (final Bookmark bookmarkedTopic : topicBookmarks) {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) { if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate( final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.fragment_bookmarks_topic_row, bookmarksLinearView, false); R.layout.fragment_bookmarks_row, bookmarksLinearView, false);
row.setOnClickListener(view -> { row.setOnClickListener(view -> {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity instanceof BookmarkActivity) { if (activity instanceof BookmarkActivity) {

9
app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java

@ -50,19 +50,20 @@ public class NotificationService extends FirebaseMessagingService {
int userId = BaseApplication.getInstance().getSessionManager().getUserId(); int userId = BaseApplication.getInstance().getSessionManager().getUserId();
//Don't notify me if the sender is me! //Don't notify me if the sender is me!
if (Integer.parseInt(json.getString("posterId")) != userId) { if (Integer.parseInt(json.getString("posterId")) != userId) {
int topicId = Integer.parseInt(json.getString("topicId"));
int postId = Integer.parseInt(json.getString("postId"));
String topicTitle = json.getString("topicTitle");
String poster = json.getString("poster");
int boardId = -1; int boardId = -1;
String boardTitle = null; String boardTitle = null;
if(remoteMessage.getFrom().contains("b")){ if(remoteMessage.getFrom().contains("b")){
Timber.i("FCM BOARD type message detected."); Timber.i("FCM BOARD type message detected.");
//TODO: return early and don't create notification if the user is also subscribed to this topicId
boardId = Integer.parseInt(json.getString("boardId")); boardId = Integer.parseInt(json.getString("boardId"));
boardTitle = json.getString("boardTitle"); boardTitle = json.getString("boardTitle");
} }
else else
Timber.i("FCM TOPIC type message detected."); Timber.i("FCM TOPIC type message detected.");
int topicId = Integer.parseInt(json.getString("topicId"));
int postId = Integer.parseInt(json.getString("postId"));
String topicTitle = json.getString("topicTitle");
String poster = json.getString("poster");
sendNotification(new PostNotification(postId, topicId, topicTitle, poster, boardId, boardTitle)); sendNotification(new PostNotification(postId, topicId, topicTitle, poster, boardId, boardTitle));
} else } else

0
app/src/main/res/layout/fragment_bookmarks_board_row.xml → app/src/main/res/layout/fragment_bookmarks_row.xml

50
app/src/main/res/layout/fragment_bookmarks_topic_row.xml

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bookmark_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/bookmark_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="8dp"
android:paddingTop="6dp"
android:paddingStart="16dp"
android:paddingEnd="0dp"
android:textColor="@color/primary_text"
android:textSize="18sp"/>
<ImageButton
android:id="@+id/toggle_notification"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:background="@android:color/transparent"
android:contentDescription="@string/toggle_notification"
app:srcCompat="@drawable/ic_notification_on"/>
<ImageButton
android:id="@+id/remove_bookmark"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:layout_marginEnd="12dp"
android:background="@android:color/transparent"
android:contentDescription="@string/remove_bookmark"
app:srcCompat="@drawable/ic_delete_accent_24dp"/>
</LinearLayout>
Loading…
Cancel
Save