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;
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<Bookmark> 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);
}
}

4
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;

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

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
@ -22,4 +22,15 @@
android:divider="?android:listDivider"
android:dividerPadding="16dp"/>
</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:textColor="@color/accent"
android:textSize="@dimen/medium_text"
android:textIsSelectable="false"
app:layout_anchor="@+id/relativeLayout"
app:layout_anchorGravity="center" />

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

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

Loading…
Cancel
Save