use of androidx.recyclerview.widget.ItemTouchHelper 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();
}
}
use of androidx.recyclerview.widget.ItemTouchHelper in project LiYuJapanese by 54wall.
the class FavLessonFragment method setData.
@Override
public void setData(List<LessonFav> data) {
Log.e(TAG, "setData!!!!!!");
lessonFavList = data;
staggeredGridAdapter = new StaggeredGridAdapter(getActivity(), data);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
mRecyclerView.setAdapter(staggeredGridAdapter);
staggeredGridAdapter.setOnItemClickLitener(new OnItemClickLitener() {
@Override
public void onItemClick(View view, int position) {
staggeredGridAdapter.notifyItemRemoved(position);
((MainActivity) getActivity()).switchFavWord(staggeredGridAdapter.getItemLessonId(position), false);
}
@Override
public void onItemLongClick(View view, final int position) {
}
});
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(mRecyclerView);
}
use of androidx.recyclerview.widget.ItemTouchHelper in project Signal-Android by signalapp.
the class ConversationListFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
constraintLayout = view.findViewById(R.id.constraint_layout);
list = view.findViewById(R.id.list);
fab = view.findViewById(R.id.fab);
cameraFab = view.findViewById(R.id.camera_fab);
searchEmptyState = view.findViewById(R.id.search_no_results);
searchAction = view.findViewById(R.id.search_action);
toolbarShadow = view.findViewById(R.id.conversation_list_toolbar_shadow);
notificationProfileStatus = view.findViewById(R.id.conversation_list_notification_profile_status);
proxyStatus = view.findViewById(R.id.conversation_list_proxy_status);
unreadPaymentsDot = view.findViewById(R.id.unread_payments_indicator);
bottomActionBar = view.findViewById(R.id.conversation_list_bottom_action_bar);
reminderView = new Stub<>(view.findViewById(R.id.reminder));
emptyState = new Stub<>(view.findViewById(R.id.empty_state));
searchToolbar = new Stub<>(view.findViewById(R.id.search_toolbar));
megaphoneContainer = new Stub<>(view.findViewById(R.id.megaphone_container));
paymentNotificationView = new Stub<>(view.findViewById(R.id.payments_notification));
voiceNotePlayerViewStub = new Stub<>(view.findViewById(R.id.voice_note_player));
Toolbar toolbar = getToolbar(view);
toolbar.setVisibility(View.VISIBLE);
((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
notificationProfileStatus.setOnClickListener(v -> handleNotificationProfile());
proxyStatus.setOnClickListener(v -> onProxyStatusClicked());
fab.show();
cameraFab.show();
archiveDecoration = new ConversationListArchiveItemDecoration(new ColorDrawable(getResources().getColor(R.color.conversation_list_archive_background_end)));
itemAnimator = new ConversationListItemAnimator();
list.setLayoutManager(new LinearLayoutManager(requireActivity()));
list.setItemAnimator(itemAnimator);
list.addOnScrollListener(new ScrollListener());
list.addItemDecoration(archiveDecoration);
snapToTopDataObserver = new SnapToTopDataObserver(list);
new ItemTouchHelper(new ArchiveListenerCallback(getResources().getColor(R.color.conversation_list_archive_background_start), getResources().getColor(R.color.conversation_list_archive_background_end))).attachToRecyclerView(list);
fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), NewConversationActivity.class)));
cameraFab.setOnClickListener(v -> {
Permissions.with(this).request(Manifest.permission.CAMERA).ifNecessary().withRationaleDialog(getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera), R.drawable.ic_camera_24).withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_the_camera_permission_to_take_photos_or_video)).onAllGranted(() -> startActivity(MediaSelectionActivity.camera(requireContext()))).onAnyDenied(() -> Toast.makeText(requireContext(), R.string.ConversationActivity_signal_needs_camera_permissions_to_take_photos_or_video, Toast.LENGTH_LONG).show()).execute();
});
initializeViewModel();
initializeListAdapters();
initializeTypingObserver();
initializeSearchListener();
initializeVoiceNotePlayer();
RatingManager.showRatingDialogIfNecessary(requireContext());
TooltipCompat.setTooltipText(searchAction, getText(R.string.SearchToolbar_search_for_conversations_contacts_and_messages));
}
use of androidx.recyclerview.widget.ItemTouchHelper in project Signal-Android by signalapp.
the class ConversationItemSwipeCallback method attachToRecyclerView.
void attachToRecyclerView(@NonNull RecyclerView recyclerView) {
recyclerView.addOnItemTouchListener(itemTouchListener);
new ItemTouchHelper(this).attachToRecyclerView(recyclerView);
}
use of androidx.recyclerview.widget.ItemTouchHelper in project android_packages_apps_Settings by omnirom.
the class ContextualCardsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context context = getContext();
final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
mCardsContainer = rootView.findViewById(R.id.card_container);
mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false);
mCardsContainer.setLayoutManager(mLayoutManager);
mContextualCardsAdapter = new ContextualCardsAdapter(context, this, /* lifecycleOwner */
mContextualCardManager);
mCardsContainer.setItemAnimator(null);
mCardsContainer.setAdapter(mContextualCardsAdapter);
mContextualCardManager.setListener(mContextualCardsAdapter);
mCardsContainer.setListener(this);
mItemTouchHelper = new ItemTouchHelper(new SwipeDismissalDelegate(mContextualCardsAdapter));
mItemTouchHelper.attachToRecyclerView(mCardsContainer);
return rootView;
}
Aggregations