Search in sources :

Example 46 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Signal-Android by WhisperSystems.

the class StickyHeaderDecoration method onDrawOver.

/**
 * {@inheritDoc}
 */
@Override
public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    final int count = parent.getChildCount();
    int start = 0;
    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(translatedChildPosition(parent, layoutPos));
        final int adapterPos = parent.getChildAdapterPosition(child);
        final long key = adapter.getHeaderId(adapterPos);
        if (key == StickyHeaderAdapter.NO_HEADER_ID) {
            start = layoutPos + 1;
        }
        if (adapterPos != RecyclerView.NO_POSITION && ((layoutPos == start && sticky) || hasHeader(parent, adapter, adapterPos))) {
            View header = getHeader(parent, adapter, adapterPos).itemView;
            c.save();
            final int left = parent.getLeft();
            final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
            c.translate(left, top);
            header.draw(c);
            c.restore();
        }
    }
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 47 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Signal-Android by WhisperSystems.

the class StickyHeaderDecoration method getHeaderTop.

protected int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) {
    int headerHeight = getHeaderHeightForLayout(header);
    int top = getChildY(child) - headerHeight;
    if (sticky && layoutPos == 0) {
        final int count = parent.getChildCount();
        final long currentId = adapter.getHeaderId(adapterPos);
        // find next view with header and compute the offscreen push if needed
        for (int i = 1; i < count; i++) {
            int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(translatedChildPosition(parent, i)));
            if (adapterPosHere != RecyclerView.NO_POSITION) {
                long nextId = adapter.getHeaderId(adapterPosHere);
                if (nextId != currentId) {
                    final View next = parent.getChildAt(translatedChildPosition(parent, i));
                    final int offset = getChildY(next) - (headerHeight + getHeader(parent, adapter, adapterPosHere).itemView.getHeight());
                    if (offset < 0) {
                        return offset;
                    } else {
                        break;
                    }
                }
            }
        }
        if (sticky)
            top = Math.max(0, top);
    }
    return top;
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 48 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Signal-Android by WhisperSystems.

the class ContactSelectionListFragment method initializeCursor.

private void initializeCursor() {
    glideRequests = GlideApp.with(this);
    cursorRecyclerViewAdapter = new ContactSelectionListAdapter(requireContext(), glideRequests, null, new ListClickListener(), isMulti, currentSelection);
    RecyclerViewConcatenateAdapterStickyHeader concatenateAdapter = new RecyclerViewConcatenateAdapterStickyHeader();
    if (listCallback != null) {
        headerAdapter = new FixedViewsAdapter(createNewGroupItem(listCallback));
        headerAdapter.hide();
        concatenateAdapter.addAdapter(headerAdapter);
    }
    concatenateAdapter.addAdapter(cursorRecyclerViewAdapter);
    if (listCallback != null) {
        footerAdapter = new FixedViewsAdapter(createInviteActionView(listCallback));
        footerAdapter.hide();
        concatenateAdapter.addAdapter(footerAdapter);
    }
    recyclerView.addItemDecoration(new LetterHeaderDecoration(requireContext(), this::hideLetterHeaders));
    recyclerView.setAdapter(concatenateAdapter);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                if (scrollCallback != null) {
                    scrollCallback.onBeginScroll();
                }
            }
        }
    });
    if (onContactSelectedListener != null) {
        onContactSelectedListener.onSelectionChanged();
    }
}
Also used : FixedViewsAdapter(org.thoughtcrime.securesms.util.adapter.FixedViewsAdapter) LetterHeaderDecoration(org.thoughtcrime.securesms.contacts.LetterHeaderDecoration) ContactSelectionListAdapter(org.thoughtcrime.securesms.contacts.ContactSelectionListAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) RecyclerViewConcatenateAdapterStickyHeader(org.thoughtcrime.securesms.util.adapter.RecyclerViewConcatenateAdapterStickyHeader) SuppressLint(android.annotation.SuppressLint)

Example 49 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Signal-Android by WhisperSystems.

the class ContactSelectionListFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.contact_selection_list_fragment, container, false);
    emptyText = view.findViewById(android.R.id.empty);
    recyclerView = view.findViewById(R.id.recycler_view);
    swipeRefresh = view.findViewById(R.id.swipe_refresh);
    fastScroller = view.findViewById(R.id.fast_scroller);
    showContactsLayout = view.findViewById(R.id.show_contacts_container);
    showContactsButton = view.findViewById(R.id.show_contacts_button);
    showContactsDescription = view.findViewById(R.id.show_contacts_description);
    showContactsProgress = view.findViewById(R.id.progress);
    chipGroup = view.findViewById(R.id.chipGroup);
    chipGroupScrollContainer = view.findViewById(R.id.chipGroupScrollContainer);
    constraintLayout = view.findViewById(R.id.container);
    shadowView = view.findViewById(R.id.toolbar_shadow);
    toolbarShadowAnimationHelper = new ToolbarShadowAnimationHelper(shadowView);
    recyclerView.addOnScrollListener(toolbarShadowAnimationHelper);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setItemAnimator(new DefaultItemAnimator() {

        @Override
        public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
            return true;
        }
    });
    Intent intent = requireActivity().getIntent();
    Bundle arguments = safeArguments();
    int recyclerViewPadBottom = arguments.getInt(RV_PADDING_BOTTOM, intent.getIntExtra(RV_PADDING_BOTTOM, -1));
    boolean recyclerViewClipping = arguments.getBoolean(RV_CLIP, intent.getBooleanExtra(RV_CLIP, true));
    if (recyclerViewPadBottom != -1) {
        ViewUtil.setPaddingBottom(recyclerView, recyclerViewPadBottom);
    }
    recyclerView.setClipToPadding(recyclerViewClipping);
    boolean isRefreshable = arguments.getBoolean(REFRESHABLE, intent.getBooleanExtra(REFRESHABLE, true));
    swipeRefresh.setNestedScrollingEnabled(isRefreshable);
    swipeRefresh.setEnabled(isRefreshable);
    hideCount = arguments.getBoolean(HIDE_COUNT, intent.getBooleanExtra(HIDE_COUNT, false));
    selectionLimit = arguments.getParcelable(SELECTION_LIMITS);
    if (selectionLimit == null) {
        selectionLimit = intent.getParcelableExtra(SELECTION_LIMITS);
    }
    isMulti = selectionLimit != null;
    canSelectSelf = arguments.getBoolean(CAN_SELECT_SELF, intent.getBooleanExtra(CAN_SELECT_SELF, !isMulti));
    if (!isMulti) {
        selectionLimit = SelectionLimits.NO_LIMITS;
    }
    currentSelection = getCurrentSelection();
    return view;
}
Also used : ToolbarShadowAnimationHelper(org.thoughtcrime.securesms.components.recyclerview.ToolbarShadowAnimationHelper) Bundle(android.os.Bundle) RecyclerView(androidx.recyclerview.widget.RecyclerView) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint)

Example 50 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Signal-Android by WhisperSystems.

the class ChatWallpaperSelectionFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    View chooseFromPhotos = view.findViewById(R.id.chat_wallpaper_choose_from_photos);
    RecyclerView recyclerView = view.findViewById(R.id.chat_wallpaper_recycler);
    chooseFromPhotos.setOnClickListener(unused -> {
        askForPermissionIfNeededAndLaunchPhotoSelection();
    });
    toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
    toolbar.setNavigationOnClickListener(nav -> Navigation.findNavController(nav).popBackStack());
    @SuppressWarnings("CodeBlock2Expr") ChatWallpaperSelectionAdapter adapter = new ChatWallpaperSelectionAdapter(chatWallpaper -> {
        startActivityForResult(ChatWallpaperPreviewActivity.create(requireActivity(), chatWallpaper, viewModel.getRecipientId(), viewModel.getDimInDarkTheme().getValue()), CHOOSE_WALLPAPER);
    });
    recyclerView.setAdapter(adapter);
    viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
    viewModel.getWallpapers().observe(getViewLifecycleOwner(), adapter::submitList);
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

RecyclerView (androidx.recyclerview.widget.RecyclerView)272 View (android.view.View)174 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)115 TextView (android.widget.TextView)32 Test (org.junit.Test)24 Nullable (androidx.annotation.Nullable)22 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)22 ImageView (android.widget.ImageView)18 Toolbar (androidx.appcompat.widget.Toolbar)18 NonNull (androidx.annotation.NonNull)16 Bundle (android.os.Bundle)15 ViewGroup (android.view.ViewGroup)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)14 Rect (android.graphics.Rect)13 LayoutInflater (android.view.LayoutInflater)11 SuppressLint (android.annotation.SuppressLint)10 Context (android.content.Context)10 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)10 List (java.util.List)9