Search in sources :

Example 11 with ItemTouchHelper

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();
    }
}
Also used : Canvas(android.graphics.Canvas) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) NotificationsAdapter(app.insti.adapter.NotificationsAdapter) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 12 with ItemTouchHelper

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);
}
Also used : OnItemClickLitener(pri.weiqiang.liyujapanese.ui.adapter.stagger.OnItemClickLitener) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) StaggeredGridAdapter(pri.weiqiang.liyujapanese.ui.adapter.StaggeredGridAdapter) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) FavLessonFragmentView(pri.weiqiang.liyujapanese.mvp.view.dic.FavLessonFragmentView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 13 with ItemTouchHelper

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));
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) ColorDrawable(android.graphics.drawable.ColorDrawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SearchToolbar(org.thoughtcrime.securesms.components.SearchToolbar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 14 with ItemTouchHelper

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);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper)

Example 15 with ItemTouchHelper

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;
}
Also used : Context(android.content.Context) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SwipeDismissalDelegate(com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate) View(android.view.View)

Aggregations

ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)24 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 View (android.view.View)10 Intent (android.content.Intent)3 Canvas (android.graphics.Canvas)3 NonNull (androidx.annotation.NonNull)3 Context (android.content.Context)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 Toolbar (androidx.appcompat.widget.Toolbar)2 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)2 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)2 BindView (butterknife.BindView)2 SwipeDismissalDelegate (com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate)2 EpisodeItemViewHolder (de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder)2 ArrayList (java.util.ArrayList)2