Commit e85df5b3 authored by Varun Patil's avatar Varun Patil

Show placeholder in NotificationsFragment if none present

parent 823396a3
...@@ -3,6 +3,7 @@ package app.insti.fragment; ...@@ -3,6 +3,7 @@ package app.insti.fragment;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment; import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
...@@ -11,6 +12,7 @@ import android.support.v7.widget.helper.ItemTouchHelper; ...@@ -11,6 +12,7 @@ import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List; import java.util.List;
...@@ -73,13 +75,22 @@ public class NotificationsFragment extends BottomSheetDialogFragment { ...@@ -73,13 +75,22 @@ public class NotificationsFragment extends BottomSheetDialogFragment {
}); });
} }
private void showNotifications(final List<Notification> notifications) { private void showNotifications(@Nullable final List<Notification> notifications) {
/* Check if activity is done with */ /* Check if activity is done with */
if (getActivity() == null || getView() == null) return; if (getActivity() == null || getView() == null) return;
/* Hide loader */ /* Hide loader */
getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE); getView().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
/* Check if there's nothing to show */
TextView noNotifs = getView().findViewById(R.id.no_notifs);
if (notifications == null || notifications.size() == 0) {
noNotifs.setVisibility(View.VISIBLE);
return;
} else {
noNotifs.setVisibility(View.GONE);
}
/* Initialize */ /* Initialize */
if (notificationsAdapter == null) { if (notificationsAdapter == null) {
notificationsAdapter = new NotificationsAdapter(notifications, this); notificationsAdapter = new NotificationsAdapter(notifications, this);
...@@ -114,6 +125,7 @@ public class NotificationsFragment extends BottomSheetDialogFragment { ...@@ -114,6 +125,7 @@ public class NotificationsFragment extends BottomSheetDialogFragment {
Utils.getRetrofitInterface().markNotificationDeleted(Utils.getSessionIDHeader(), id).enqueue(new EmptyCallback<Void>()); Utils.getRetrofitInterface().markNotificationDeleted(Utils.getSessionIDHeader(), id).enqueue(new EmptyCallback<Void>());
NotificationId.setCurrentCount(Utils.notificationCache.size()); NotificationId.setCurrentCount(Utils.notificationCache.size());
ShortcutBadger.applyCount(getContext().getApplicationContext(), NotificationId.getCurrentCount()); ShortcutBadger.applyCount(getContext().getApplicationContext(), NotificationId.getCurrentCount());
if (Utils.notificationCache.size() == 0) showNotifications(null);
} }
}; };
......
...@@ -5,6 +5,15 @@ ...@@ -5,6 +5,15 @@
tools:context="app.insti.fragment.NotificationsFragment" tools:context="app.insti.fragment.NotificationsFragment"
android:background="?attr/themeColor"> android:background="?attr/themeColor">
<TextView
android:id="@+id/no_notifs"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:textSize="16sp"
android:visibility="gone"
android:text="No notifications for now!" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/notifications_recycler_view" android:id="@+id/notifications_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment