use of app.insti.adapter.NotificationsAdapter in project IITB-App by wncc.
the class NotificationsFragment method showNotifications.
private void showNotifications(@Nullable final List<Notification> notifications) {
/* Check if activity is done with */
if (getActivity() == null || getView() == null)
return;
/* Hide loader */
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 */
if (notificationsAdapter == null) {
notificationsAdapter = new NotificationsAdapter(notifications, this);
notificationsRecyclerView = (RecyclerView) getView().findViewById(R.id.notifications_recycler_view);
notificationsRecyclerView.setAdapter(notificationsAdapter);
notificationsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
notificationsRecyclerView.setItemAnimator(null);
/* Handle swiping of notifications */
ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
// Fade out the view when it is swiped out of the parent
final float alpha = 1.0f - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
viewHolder.itemView.setAlpha(alpha);
viewHolder.itemView.setTranslationX(dX);
} else {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
// swiped position
final int position = viewHolder.getAdapterPosition();
final String id = Utils.notificationCache.get(position).getNotificationId().toString();
Utils.notificationCache.remove(position);
notificationsAdapter.notifyItemRemoved(position);
Utils.getRetrofitInterface().markNotificationDeleted(Utils.getSessionIDHeader(), id).enqueue(new EmptyCallback<Void>());
NotificationId.setCurrentCount(Utils.notificationCache.size());
ShortcutBadger.applyCount(getContext().getApplicationContext(), NotificationId.getCurrentCount());
if (Utils.notificationCache.size() == 0)
showNotifications(null);
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
itemTouchHelper.attachToRecyclerView(notificationsRecyclerView);
} else {
notificationsAdapter.setList(notifications);
notificationsAdapter.notifyDataSetChanged();
}
}
Aggregations