From 8f355097d29b03ff1f6a7c9d31ec6ec859925446 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 30 May 2020 17:54:05 +0300 Subject: [PATCH] Minor BookmarksFragment improvement --- .../bookmarks/BookmarksFragment.java | 38 ++++++++----------- .../thmmy/mthmmy/session/SessionManager.java | 4 +- .../main/res/layout/fragment_bookmarks.xml | 15 +++++++- app/src/main/res/layout/fragment_unread.xml | 1 + app/src/main/res/values/strings.xml | 3 +- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java index 67de4c2e..23562e0d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java @@ -1,7 +1,6 @@ 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; @@ -34,6 +33,8 @@ public class BookmarksFragment extends Fragment { static final String INTERACTION_TOGGLE_BOARD_NOTIFICATION = "TOGGLE_BOARD_NOTIFICATION"; static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK"; + private TextView nothingBookmarkedTextView; + private ArrayList bookmarks = null; private Type type; private String interactionClick, interactionToggle, interactionRemove; @@ -100,8 +101,10 @@ public class BookmarksFragment extends Fragment { final View rootView = layoutInflater.inflate(R.layout.fragment_bookmarks, container, false); //bookmarks container final LinearLayout bookmarksLinearView = rootView.findViewById(R.id.bookmarks_container); + nothingBookmarkedTextView = rootView.findViewById(R.id.nothing_bookmarked); if(this.bookmarks != null && !this.bookmarks.isEmpty()) { + hideNothingBookmarked(); for (final Bookmark bookmark : bookmarks) { if (bookmark != null && bookmark.getTitle() != null) { final LinearLayout row = (LinearLayout) layoutInflater.inflate( @@ -137,38 +140,27 @@ public class BookmarksFragment extends Fragment { row.setVisibility(View.GONE); if (bookmarks.isEmpty()){ - bookmarksLinearView.addView(bookmarksListEmptyMessage()); + showNothingBookmarked(); } }); bookmarksLinearView.addView(row); } } } else - bookmarksLinearView.addView(bookmarksListEmptyMessage()); + showNothingBookmarked(); return rootView; } - private TextView bookmarksListEmptyMessage() { - TextView emptyBookmarksCategory = new TextView(this.getContext()); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - params.setMargins(0, 12, 0, 0); - emptyBookmarksCategory.setLayoutParams(params); - if(type==Type.TOPIC) - emptyBookmarksCategory.setText(getString(R.string.empty_topic_bookmarks)); - else if(type==Type.BOARD) - emptyBookmarksCategory.setText(getString(R.string.empty_board_bookmarks)); - - emptyBookmarksCategory.setTypeface(emptyBookmarksCategory.getTypeface(), Typeface.BOLD); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - emptyBookmarksCategory.setTextColor(this.getContext().getColor(R.color.primary_text)); - else { - //noinspection deprecation - emptyBookmarksCategory.setTextColor(this.getContext().getResources().getColor(R.color.primary_text)); - } - emptyBookmarksCategory.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - return emptyBookmarksCategory; + + private void showNothingBookmarked() { + if(nothingBookmarkedTextView!=null) + nothingBookmarkedTextView.setVisibility(View.VISIBLE); + } + + private void hideNothingBookmarked(){ + if(nothingBookmarkedTextView!=null) + nothingBookmarkedTextView.setVisibility(View.INVISIBLE); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java index 2dab5489..36490d56 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -188,9 +188,9 @@ public class SessionManager { * fragments' data are retrieved). */ void validateSession() { - Timber.e("Validating session..."); + Timber.i("Validating session..."); if (isLoggedIn()) { - Timber.e("Refreshing session..."); + Timber.i("Refreshing session..."); int loginResult = login(); if (loginResult != FAILURE) return; diff --git a/app/src/main/res/layout/fragment_bookmarks.xml b/app/src/main/res/layout/fragment_bookmarks.xml index 9e4c7ca2..8d1372c0 100644 --- a/app/src/main/res/layout/fragment_bookmarks.xml +++ b/app/src/main/res/layout/fragment_bookmarks.xml @@ -1,5 +1,5 @@ - @@ -22,4 +22,15 @@ android:divider="?android:listDivider" android:dividerPadding="16dp"/> - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_unread.xml b/app/src/main/res/layout/fragment_unread.xml index 3a89ebc8..4d1d5506 100644 --- a/app/src/main/res/layout/fragment_unread.xml +++ b/app/src/main/res/layout/fragment_unread.xml @@ -39,6 +39,7 @@ android:text="@string/no_unread_topics" android:textColor="@color/accent" android:textSize="@dimen/medium_text" + android:textIsSelectable="false" app:layout_anchor="@+id/relativeLayout" app:layout_anchorGravity="center" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 88e8899f..d1c69acb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -105,8 +105,7 @@ Remove - You have no bookmarked boards - You have no bookmarked topics + Nothing bookmarked here! Toggle Notification