Browse Source

Minor BookmarksFragment improvement

pull/70/head
Ezerous 5 years ago
parent
commit
8f355097d2
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 38
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  3. 15
      app/src/main/res/layout/fragment_bookmarks.xml
  4. 1
      app/src/main/res/layout/fragment_unread.xml
  5. 3
      app/src/main/res/values/strings.xml

38
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java

@ -1,7 +1,6 @@
package gr.thmmy.mthmmy.activities.bookmarks; package gr.thmmy.mthmmy.activities.bookmarks;
import android.app.Activity; import android.app.Activity;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; 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_TOGGLE_BOARD_NOTIFICATION = "TOGGLE_BOARD_NOTIFICATION";
static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK"; static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK";
private TextView nothingBookmarkedTextView;
private ArrayList<Bookmark> bookmarks = null; private ArrayList<Bookmark> bookmarks = null;
private Type type; private Type type;
private String interactionClick, interactionToggle, interactionRemove; 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); final View rootView = layoutInflater.inflate(R.layout.fragment_bookmarks, container, false);
//bookmarks container //bookmarks container
final LinearLayout bookmarksLinearView = rootView.findViewById(R.id.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()) { if(this.bookmarks != null && !this.bookmarks.isEmpty()) {
hideNothingBookmarked();
for (final Bookmark bookmark : bookmarks) { for (final Bookmark bookmark : bookmarks) {
if (bookmark != null && bookmark.getTitle() != null) { if (bookmark != null && bookmark.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate( final LinearLayout row = (LinearLayout) layoutInflater.inflate(
@ -137,38 +140,27 @@ public class BookmarksFragment extends Fragment {
row.setVisibility(View.GONE); row.setVisibility(View.GONE);
if (bookmarks.isEmpty()){ if (bookmarks.isEmpty()){
bookmarksLinearView.addView(bookmarksListEmptyMessage()); showNothingBookmarked();
} }
}); });
bookmarksLinearView.addView(row); bookmarksLinearView.addView(row);
} }
} }
} else } else
bookmarksLinearView.addView(bookmarksListEmptyMessage()); showNothingBookmarked();
return rootView; return rootView;
} }
private TextView bookmarksListEmptyMessage() {
TextView emptyBookmarksCategory = new TextView(this.getContext()); private void showNothingBookmarked() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( if(nothingBookmarkedTextView!=null)
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); nothingBookmarkedTextView.setVisibility(View.VISIBLE);
params.setMargins(0, 12, 0, 0); }
emptyBookmarksCategory.setLayoutParams(params);
if(type==Type.TOPIC) private void hideNothingBookmarked(){
emptyBookmarksCategory.setText(getString(R.string.empty_topic_bookmarks)); if(nothingBookmarkedTextView!=null)
else if(type==Type.BOARD) nothingBookmarkedTextView.setVisibility(View.INVISIBLE);
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;
} }
} }

4
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -188,9 +188,9 @@ public class SessionManager {
* fragments' data are retrieved). * fragments' data are retrieved).
*/ */
void validateSession() { void validateSession() {
Timber.e("Validating session..."); Timber.i("Validating session...");
if (isLoggedIn()) { if (isLoggedIn()) {
Timber.e("Refreshing session..."); Timber.i("Refreshing session...");
int loginResult = login(); int loginResult = login();
if (loginResult != FAILURE) if (loginResult != FAILURE)
return; return;

15
app/src/main/res/layout/fragment_bookmarks.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_width="match_parent" android:layout_height="match_parent">
@ -22,4 +22,15 @@
android:divider="?android:listDivider" android:divider="?android:listDivider"
android:dividerPadding="16dp"/> android:dividerPadding="16dp"/>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
</RelativeLayout> <TextView
android:id="@+id/nothing_bookmarked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"
android:textIsSelectable="false"
android:text="@string/nothing_bookmarked_here"
android:textColor="@color/accent"
android:textSize="@dimen/medium_text"
/>
</FrameLayout>

1
app/src/main/res/layout/fragment_unread.xml

@ -39,6 +39,7 @@
android:text="@string/no_unread_topics" android:text="@string/no_unread_topics"
android:textColor="@color/accent" android:textColor="@color/accent"
android:textSize="@dimen/medium_text" android:textSize="@dimen/medium_text"
android:textIsSelectable="false"
app:layout_anchor="@+id/relativeLayout" app:layout_anchor="@+id/relativeLayout"
app:layout_anchorGravity="center" /> app:layout_anchorGravity="center" />

3
app/src/main/res/values/strings.xml

@ -105,8 +105,7 @@
<!--Bookmarks--> <!--Bookmarks-->
<string name="remove_bookmark">Remove</string> <string name="remove_bookmark">Remove</string>
<string name="empty_board_bookmarks">You have no bookmarked boards</string> <string name="nothing_bookmarked_here">Nothing bookmarked here!</string>
<string name="empty_topic_bookmarks">You have no bookmarked topics</string>
<string name="toggle_notification">Toggle Notification</string> <string name="toggle_notification">Toggle Notification</string>
<!--FontAwesome--> <!--FontAwesome-->

Loading…
Cancel
Save