Java Code Examples for eu.davidea.flexibleadapter.FlexibleAdapter#useTag()
The following examples show how to use
eu.davidea.flexibleadapter.FlexibleAdapter#useTag() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentViewPager.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
private void initializeRecyclerView() { // Initialize Adapter and RecyclerView // Use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("ViewPagerAdapter"); mAdapter = new FlexibleAdapter<>(createList(50, 5), getActivity(), true); mAdapter.setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling); RecyclerView mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(getActivity())); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); mAdapter.setFastScroller(fastScroller); // Sticky Headers mAdapter.setDisplayHeadersAtStartUp(true) .setStickyHeaders(true); }
Example 2
Source File: FragmentDataBinding.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView FlexibleAdapter.useTag("DataBindingAdapter"); mAdapter = new BindingFlexibleAdapter<>(getActivity(), true); mAdapter.setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new GarageDoorItemAnimator()); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); mAdapter.setFastScroller(fastScroller); // New empty views handling, to set after FastScroller EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view), getView().findViewById(R.id.filter_view)); mAdapter.setLongPressDragEnabled(true) .setHandleDragEnabled(true) .setSwipeEnabled(true) .setDisplayHeadersAtStartUp(true) .setStickyHeaders(true); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem( getString(R.string.databinding_use_case_title), getString(R.string.databinding_use_case_description)), 500L, false); }
Example 3
Source File: FragmentStaggeredLayout.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("StaggeredLayoutAdapter"); mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity()); mRecyclerView = getView().findViewById(R.id.recycler_view); // Customize the speed of the smooth scroll. // NOTE: Every time you change this value you MUST recreate the LayoutManager instance // and to assign it again to the RecyclerView! TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 33f; //Make faster the smooth scroll mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager()); // This value is restored to 100f (default) right here, because it is used in the // constructor by Android. If we don't change it now, others LayoutManager will be // impacted too by the above modification! TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 100f; mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) .addItemViewType(R.layout.recycler_staggered_item, 8) .withEdge(true)); mAdapter.setDisplayHeadersAtStartUp(true) //Show Headers at startUp! .setNotifyMoveOfFilteredItems(true) .setPermanentDelete(true) //Default=true .setOnlyEntryAnimation(true); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // Add 1 Scrollable Header mAdapter.addScrollableHeader(new ScrollableUseCaseItem( getString(R.string.staggered_use_case_title), getString(R.string.staggered_use_case_description))); }
Example 4
Source File: FragmentAnimators.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { FlexibleAdapter.useTag("AnimatorsAdapter"); mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity()); mAdapter.expandItemsAtStartUp() .setAutoCollapseOnExpand(false) .setAutoScrollOnExpand(true) .setOnlyEntryAnimation(false) .setAnimationEntryStep(true) //In Overall, watch the effect at initial loading when Grid Layout is set .setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling) .setAnimationOnReverseScrolling(true) .setAnimationInterpolator(new DecelerateInterpolator()) .setAnimationDuration(300L); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); //mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Custom item animators inherit 'canReuseUpdatedViewHolder()' from Default Item // Animator. It will return true if a Payload is provided. FlexibleAdapter is actually // sending Payloads onItemChange notifications. mRecyclerView.setItemAnimator(new FlexibleItemAnimator()); initializeSpinnerItemAnimators(); initializeSpinnerScrollAnimators(); mAdapter.setSwipeEnabled(true) .getItemTouchHelperCallback() .setSwipeFlags(ItemTouchHelper.RIGHT); //Enable swipe SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(false); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // Add 1 Scrollable Header mAdapter.addScrollableHeader(new ScrollableUseCaseItem( getString(R.string.animator_use_case_title), getString(R.string.animator_use_case_description))); }
Example 5
Source File: FragmentHolderSections.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("HolderSectionsAdapter"); mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity()); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity()); mAdapter.setFastScroller(fastScroller); mAdapter.setDisplayHeadersAtStartUp(true) .setStickyHeaders(true) .setOnlyEntryAnimation(true); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // Add 1 Scrollable Header mAdapter.addScrollableHeader(new ScrollableUseCaseItem( getString(R.string.model_holders_use_case_title), getString(R.string.model_holders_use_case_description))); }
Example 6
Source File: FragmentInstagramHeaders.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked", "ConstantConditions"}) private void initializeRecyclerView() { // Initialize Adapter and RecyclerView // true = it makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("InstagramHeadersAdapter"); mAdapter = new FlexibleAdapter<>(null, getActivity(), true); mAdapter.addListener(getActivity()) .setAnimationOnForwardScrolling(true) .setAnimationOnReverseScrolling(true); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // 24dpi as empty space between sections (each post) mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) .withSectionGapOffset(24)); // New empty views handling EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view)); mAdapter.setDisplayHeadersAtStartUp(true) //Show Headers at startUp! .setStickyHeaders(true) //Make headers sticky // Endless scroll with 1 item threshold .setLoadingMoreAtStartUp(true) .setEndlessScrollListener(this, new ProgressItem()) .setEndlessScrollThreshold(1); //Default=1 SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); }
Example 7
Source File: FragmentAsyncFilter.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Restore FAB button and icon initializeFab(); FlexibleAdapter.useTag("AsyncFilterAdapter"); // IMPORTANT! Upgrading to Support Library v26, stableIds must remain = false. // StableIds cause the entry animation not animate properly: alpha property of views // remain 1 (item not changed) while the entry animation requires the view to be invisible // when Swapping / Changing the Adapter. if (configure) { // Create configuration list DatabaseService.getInstance().createConfigurationDatabase(getResources()); mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity(), false); } else { // Create Database with custom size // N. of items (1000 items it's already a medium size) DatabaseService.getInstance().createEndlessDatabase(DatabaseConfiguration.size); mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity(), false); } initializeRecyclerView(); configure = !configure; }
Example 8
Source File: FragmentEndlessScrolling.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("EndlessScrollingAdapter"); if (savedInstanceState != null) { mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity()); } else { mAdapter = new ExampleAdapter(null, getActivity()); } mAdapter.setAutoScrollOnExpand(true) //.setAnimateToLimit(Integer.MAX_VALUE) //Use the default value .setNotifyMoveOfFilteredItems(true) //When true, filtering on big list is very slow, not in this case! .setNotifyChangeOfUnfilteredItems(true) //true by default .setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling) .setAnimationOnReverseScrolling(true); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use the custom FadeInDownAnimator for ALL notifications for ALL items, // but ScrollableFooterItem implements AnimatedViewHolder with a unique animation: SlideInUp! mRecyclerView.setItemAnimator(new FadeInDownItemAnimator()); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity()); mAdapter.setFastScroller(fastScroller); // New empty views handling, to set after FastScroller EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view), getView().findViewById(R.id.filter_view)); mAdapter.setLongPressDragEnabled(true) //Enable long press to drag items .setHandleDragEnabled(true) //Enable drag using handle view .setSwipeEnabled(true); //Enable swipe items SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // EndlessScrollListener - OnLoadMore (v5.0.0) mAdapter.setLoadingMoreAtStartUp(savedInstanceState == null) //To call only if the list is empty //.setEndlessPageSize(3) //Endless is automatically disabled if newItems < 3 //.setEndlessTargetCount(15) //Endless is automatically disabled if totalItems >= 15 .setEndlessScrollThreshold(20) //Default=1 .setEndlessScrollListener(this, mProgressItem) .setTopEndless(false); // Add 1 Header item ScrollableLayoutItem scrollHeader = new ScrollableLayoutItem("SLI"); scrollHeader.setTitle("Endless Scrolling"); scrollHeader.setSubtitle("...with ScrollableHeaderItem"); mAdapter.addScrollableHeader(scrollHeader); }
Example 9
Source File: FragmentExpandableSections.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("ExpandableSectionAdapter"); mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity()); // OnItemAdd and OnItemRemove listeners mAdapter.addListener(this); mAdapter.expandItemsAtStartUp() .setAutoCollapseOnExpand(false) .setAutoScrollOnExpand(true) .setAnimateToLimit(Integer.MAX_VALUE) //Size limit = MAX_VALUE will always animate the changes .setNotifyMoveOfFilteredItems(true) //When true, filtering on big list is very slow! .setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling) .setAnimationOnReverseScrolling(true); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // Custom divider item decorator mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) .addItemViewType(R.layout.recycler_expandable_header_item) .withOffset(4)); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity()); mAdapter.setFastScroller(fastScroller); // New empty views handling, to set after FastScroller EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view), getView().findViewById(R.id.filter_view)); mAdapter.setLongPressDragEnabled(true) //Enable long press to drag items .setHandleDragEnabled(true) //Enable handle drag //.setDisplayHeadersAtStartUp(true); //Show Headers at startUp: (not necessary if Headers are also Expandable AND expanded at startup) .setStickyHeaders(true); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); }
Example 10
Source File: FragmentSelectionModes.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Get the Database list List<AbstractFlexibleItem> items = DatabaseService.getInstance().getDatabaseList(); // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("SelectionModesAdapter"); mAdapter = new ExampleAdapter(items, getActivity()); mAdapter.setNotifyChangeOfUnfilteredItems(true) //true is the default! This will rebind new item when refreshed .setMode(Mode.SINGLE); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // Divider item decorator with DrawOver enabled mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) .withDivider(R.drawable.divider, R.layout.recycler_simple_item) .withDrawOver(true)); mRecyclerView.postDelayed(new Runnable() { @Override public void run() { Snackbar.make(getView(), "Selection SINGLE is enabled", Snackbar.LENGTH_SHORT).show(); } }, 1500L); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); fastScroller.setAutoHideEnabled(true); //true is the default value! fastScroller.setAutoHideDelayInMillis(1000L); //1000ms is the default value! fastScroller.setMinimumScrollThreshold(70); //0 pixel is the default value! When > 0 it mimics the fling gesture fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity()); // The color (accentColor) is automatically fetched by the FastScroller constructor, but you can change it at runtime // fastScroller.setBubbleAndHandleColor(Color.RED); mAdapter.setFastScroller(fastScroller); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.SINGLE); // Add 2 Scrollable Headers mAdapter.addUserLearnedSelection(savedInstanceState == null); mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem( getString(R.string.selection_modes_use_case_title), getString(R.string.selection_modes_use_case_description)), 1200L, true ); }
Example 11
Source File: FragmentHeadersSections.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("HeadersSectionsAdapter"); mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity()); mAdapter.setNotifyMoveOfFilteredItems(true) .setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) //.addItemViewType(R.layout.recycler_header_item, 8, 8, 8, 8) .addItemViewType(R.layout.recycler_simple_item, 0, 8, 0, 8) .withSectionGapOffset(24) .withEdge(true)); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity()); mAdapter.setFastScroller(fastScroller); // New empty views handling, to set after FastScroller EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view), getView().findViewById(R.id.filter_view), (EmptyViewHelper.OnEmptyViewListener) getActivity()); // Optional!! // More settings mAdapter.setLongPressDragEnabled(true) .setHandleDragEnabled(true) .setSwipeEnabled(true) .setStickyHeaderElevation(5) .setUnlinkAllItemsOnRemoveHeaders(true) // Show Headers at startUp, 1st call, correctly executed, no warning log message! .setDisplayHeadersAtStartUp(true) .setStickyHeaders(true); // Simulate developer 2nd call mistake, now it's safe, not executed, no warning log message! //.setDisplayHeadersAtStartUp(true) // Simulate developer 3rd call mistake, still safe, not executed, warning log message displayed! //.showAllHeaders(); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // Add 2 Scrollable Headers and 1 Footer mAdapter.addUserLearnedSelection(savedInstanceState == null); mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem( getString(R.string.headers_sections_use_case_title), getString(R.string.headers_sections_use_case_description)), 900L, false); mAdapter.addScrollableFooter(); }
Example 12
Source File: FragmentExpandableMultiLevel.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("ExpandableMultiLevelAdapter"); mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity()); mAdapter.expandItemsAtStartUp() .setNotifyMoveOfFilteredItems(true) .setAutoCollapseOnExpand(false) .setMinCollapsibleLevel(1) //Auto-collapse only items with level >= 1 (avoid to collapse also sections!) .setAutoScrollOnExpand(true); mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity()); mAdapter.setFastScroller(fastScroller); // New empty views handling, to set after FastScroller EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view), getView().findViewById(R.id.filter_view)); mAdapter.setLongPressDragEnabled(true) //Enable long press to drag items .setHandleDragEnabled(true) //Enable handle drag .setSwipeEnabled(true); //Enable swipe items //.setDisplayHeadersAtStartUp(true); //Show Headers at startUp: not necessary if Headers are also Expandable! mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) .withSectionGapOffset(24)); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // Add 1 Scrollable Header mAdapter.addUserLearnedSelection(savedInstanceState == null); }
Example 13
Source File: FragmentOverall.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@SuppressWarnings({"ConstantConditions", "NullableProblems"}) private void initializeRecyclerView(Bundle savedInstanceState) { // Initialize Adapter and RecyclerView // OverallAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("OverallAdapter"); mAdapter = new OverallAdapter(getActivity()); mAdapter.setOnlyEntryAnimation(true) .setAnimationInterpolator(new DecelerateInterpolator()) .setAnimationInitialDelay(INITIAL_DELAY_300); // Prepare the RecyclerView and attach the Adapter to it mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setItemViewCacheSize(0); //Setting ViewCache to 0 (default=2) will animate items better while scrolling down+up with LinearLayout mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager()); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change mItemDecoration = new FlexibleItemDecoration(getActivity()) .addItemViewType(R.layout.recycler_overall_item) .withOffset(8) // This helps when top items are removed!! .withEdge(true); mRecyclerView.addItemDecoration(mItemDecoration); // After Adapter is attached to RecyclerView mAdapter.setLongPressDragEnabled(true); mRecyclerView.postDelayed(new Runnable() { @Override public void run() { if (getView() != null) { //Fix NPE when closing app before the execution of Runnable Snackbar.make(getView(), "Long press drag is enabled", Snackbar.LENGTH_SHORT).show(); } } }, 4000L); SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setEnabled(true); mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE); // Add 1 Scrollable Header scrollableUseCaseItem = new ScrollableUseCaseItem( getString(R.string.overall_use_case_title), getString(R.string.overall_use_case_description)); // Delayed! So entry animation will perform together mAdapter.addScrollableHeaderWithDelay(scrollableUseCaseItem, INITIAL_DELAY_300, true); }