Java Code Examples for androidx.swiperefreshlayout.widget.SwipeRefreshLayout#setEnabled()
The following examples show how to use
androidx.swiperefreshlayout.widget.SwipeRefreshLayout#setEnabled() .
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: MobiComQuickConversationFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void onPreExecute() { super.onPreExecute(); isAlreadyLoading = true; if (loadMoreMessages) { if (!messageList.contains(null)) { messageList.add(null); } if (recyclerAdapter != null) { recyclerAdapter.notifyItemInserted(messageList.size() - 1); } } else { if (swipeRefreshLayoutWeakReference != null) { final SwipeRefreshLayout swipeRefreshLayout = swipeRefreshLayoutWeakReference.get(); if (swipeRefreshLayout != null) { swipeRefreshLayout.setEnabled(true); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); } }); } } } }
Example 2
Source File: FrageMyStar.java From Ruisi with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); initToolbar(true, "我的收藏"); recyclerView = mRootView.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout); refreshLayout.setEnabled(false); String myUid = App.getUid(getActivity()); //我的收藏 url = "home.php?mod=space&uid=" + myUid + "&do=favorite&view=me&type=thread&mobile=no"; datas = new ArrayList<>(); adapter = new MyStarAdapter(getActivity(), datas); adapter.setLongClickListener((v, position) -> { int favId = datas.get(position).favId; String title = datas.get(position).title; new AlertDialog.Builder(getActivity()) .setTitle("取消收藏") .setMessage(title) .setPositiveButton("取消收藏", (dialog, which) -> unStarPost(favId, position)) .setNegativeButton("关闭", null) .setCancelable(true) .create() .show(); }); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity()); recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL)); recyclerView.addOnScrollListener(new LoadMoreListener((LinearLayoutManager) layoutManager, this, 10)); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); refresh(); return mRootView; }
Example 3
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 4
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 5
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 6
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 7
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 8
Source File: SingleNoteWidgetConfigurationActivity.java From nextcloud-notes with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); setResult(Activity.RESULT_CANCELED); fabCreate.setVisibility(View.GONE); Toolbar toolbar = binding.activityNotesListView.toolbar; SwipeRefreshLayout swipeRefreshLayout = binding.activityNotesListView.swiperefreshlayout; toolbar.setTitle(R.string.activity_select_single_note); swipeRefreshLayout.setEnabled(false); swipeRefreshLayout.setRefreshing(false); }
Example 9
Source File: FrageMyTopic.java From Ruisi with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); Bundle bundle = getArguments();//从activity传过来的Bundle int uid = 0; if (bundle != null) { uid = bundle.getInt("uid", 0); String username = bundle.getString("username", "我的"); if (uid == 0) { title = "我的帖子"; } else { title = username + "的帖子"; } } initToolbar(true, title); RecyclerView recyclerView = mRootView.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout); refreshLayout.setEnabled(false); String myUid = App.getUid(getActivity()); url = "home.php?mod=space&uid=" + (uid > 0 ? uid : myUid) + "&do=thread&view=me&mobile=2"; datas = new ArrayList<>(); adapter = new MyPostsListAdapter(getActivity(), datas); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL)); recyclerView.addOnScrollListener(new LoadMoreListener(layoutManager, this, 10)); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); refresh(); return mRootView; }
Example 10
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 11
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 12
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 13
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 14
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 15
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); }
Example 16
Source File: MobiComQuickConversationFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected void onPostExecute(Long result) { if (!loadMoreMessages) { if (swipeRefreshLayoutWeakReference != null) { final SwipeRefreshLayout swipeRefreshLayout = swipeRefreshLayoutWeakReference.get(); if (swipeRefreshLayout != null) { swipeRefreshLayout.setEnabled(true); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(false); } }); } } } if (!loadMoreMessages) { messageList.clear(); latestMessageForEachContact.clear(); } if (!TextUtils.isEmpty(searchString)) { messageList.addAll(nextMessageList); } else { for (Message currentMessage : nextMessageList) { if (currentMessage.isSentToMany()) { continue; } Message recentSms; if (currentMessage.getGroupId() != null) { recentSms = latestMessageForEachContact.get(ConversationUIService.GROUP + currentMessage.getGroupId()); } else { recentSms = latestMessageForEachContact.get(currentMessage.getContactIds()); } if (recentSms != null) { if (currentMessage.getCreatedAtTime() >= recentSms.getCreatedAtTime()) { if (currentMessage.getGroupId() != null) { latestMessageForEachContact.put(ConversationUIService.GROUP + currentMessage.getGroupId(), currentMessage); } else { latestMessageForEachContact.put(currentMessage.getContactIds(), currentMessage); } messageList.remove(recentSms); messageList.add(currentMessage); } } else { if (currentMessage.getGroupId() != null) { latestMessageForEachContact.put(ConversationUIService.GROUP + currentMessage.getGroupId(), currentMessage); } else { latestMessageForEachContact.put(currentMessage.getContactIds(), currentMessage); } messageList.add(currentMessage); } } } if (loadMoreMessages) { if (messageList.contains(null)) { messageList.remove(null); } //progressBar.setVisibility(View.GONE); } if (recyclerAdapter != null) { recyclerAdapter.notifyDataSetChanged(); } if (initial) { if (textViewWeakReference != null) { TextView emptyTextView = textViewWeakReference.get(); if (emptyTextView != null) { emptyTextView.setVisibility(messageList.isEmpty() ? View.VISIBLE : View.GONE); if (!TextUtils.isEmpty(searchString) && messageList.isEmpty()) { emptyTextView.setText(!TextUtils.isEmpty(alCustomizationSettings.getNoSearchFoundForChatMessages()) ? alCustomizationSettings.getNoSearchFoundForChatMessages() : noConversationFound); } else if (TextUtils.isEmpty(searchString) && messageList.isEmpty()) { emptyTextView.setText(!TextUtils.isEmpty(alCustomizationSettings.getNoConversationLabel()) ? alCustomizationSettings.getNoConversationLabel() : conversationLabel); } } } if (!messageList.isEmpty()) { if (recyclerView != null && recyclerAdapter != null) { if (recyclerAdapter.getItemCount() > BroadcastService.lastIndexForChats) { recyclerView.scrollToPosition(BroadcastService.lastIndexForChats); BroadcastService.lastIndexForChats = 0; } else { recyclerView.scrollToPosition(0); } } } } else { if (!loadMoreMessages && recyclerViewWr != null && recyclerViewWr.get() != null) { recyclerViewWr.get().scrollToPosition(firstVisibleItem); } } if (!nextMessageList.isEmpty()) { loadMore = true; } isAlreadyLoading = false; }
Example 17
Source File: SearchFragment.java From hipda with GNU General Public License v2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_search, container, false); mRecyclerView = (XRecyclerView) view.findViewById(R.id.rv_threads); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); mRecyclerView.addItemDecoration(new SimpleDivider(getActivity())); mRecyclerView.addOnScrollListener(new OnScrollListener()); mRecyclerView.setAdapter(mSimpleListAdapter); mSearchFilterLayout = (RelativeLayout) view.findViewById(R.id.search_filter_layout); ViewCompat.setElevation(mSearchFilterLayout, Utils.dpToPx(4)); mSearchFilterLayout.setAlpha(0); mSpForum = (Spinner) view.findViewById(R.id.sp_forum); mSpAdapter = new KeyValueArrayAdapter(getActivity(), R.layout.spinner_row); mSpAdapter.setEntryValues(getForumIds()); mSpAdapter.setEntries(getForumNames()); mSpForum.setAdapter(mSpAdapter); mEtAuthor = (EditText) view.findViewById(R.id.et_author); mEtAuthor.setOnEditorActionListener(mSearchEditorActionListener); mCbFulltext = (CheckBox) view.findViewById(R.id.cb_fulltext); mCbFulltext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (mSearchView != null) { if (isChecked) { mSearchView.setQueryHint("搜索全文"); } else { mSearchView.setQueryHint("搜索标题"); } } } }); RecyclerView rvHistory = (RecyclerView) view.findViewById(R.id.rv_history); rvHistory.setHasFixedSize(true); rvHistory.setLayoutManager(new LinearLayoutManager(getActivity())); rvHistory.setAdapter(mHistoryAdapter); mHistoryAdapter.setDatas(mQueries); mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container); mSwipeLayout.setOnRefreshListener(this); mSwipeLayout.setColorSchemeColors(ColorHelper.getSwipeColor(getActivity())); mSwipeLayout.setProgressBackgroundColorSchemeColor(ColorHelper.getSwipeBackgroundColor(getActivity())); mSwipeLayout.setEnabled(false); mLoadingView = (ContentLoadingView) view.findViewById(R.id.content_loading); mLoadingView.setState(ContentLoadingView.NO_DATA); new Handler().postDelayed(new Runnable() { @Override public void run() { //hide then show mSearchFilterLayout, cannot get it's height on first show //so I use a fixed value here, tell me if you know a better way mSearchFilterLayout.animate() .alpha(0) .setDuration(100) .translationYBy(-300) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mSearchFilterLayout.setVisibility(View.GONE); mSearchFilterAnimating = false; showSearchFilter(); } }); } }, 150); return view; }