use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project Tusky by Vavassor.
the class NotificationsFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_timeline_notifications, container, false);
// from inflater to silence warning
@NonNull Context context = inflater.getContext();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
boolean showNotificationsFilterSetting = preferences.getBoolean("showNotificationsFilter", true);
// Clear notifications on filter visibility change to force refresh
if (showNotificationsFilterSetting != showNotificationsFilter)
notifications.clear();
showNotificationsFilter = showNotificationsFilterSetting;
// Setup the SwipeRefreshLayout.
swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout);
recyclerView = rootView.findViewById(R.id.recyclerView);
progressBar = rootView.findViewById(R.id.progressBar);
statusView = rootView.findViewById(R.id.statusView);
appBarOptions = rootView.findViewById(R.id.appBarOptions);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
loadNotificationsFilter();
// Setup the RecyclerView.
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAccessibilityDelegateCompat(new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> {
NotificationViewData notification = notifications.getPairedItemOrNull(pos);
// We support replies only for now
if (notification instanceof NotificationViewData.Concrete) {
return ((NotificationViewData.Concrete) notification).getStatusViewData();
} else {
return null;
}
}));
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions(preferences.getBoolean("animateGifAvatars", false), accountManager.getActiveAccount().getMediaPreviewEnabled(), preferences.getBoolean("absoluteTimeView", false), preferences.getBoolean("showBotOverlay", true), preferences.getBoolean("useBlurhash", true), CardViewMode.NONE, preferences.getBoolean("confirmReblogs", true), preferences.getBoolean("confirmFavourites", false), preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false), preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false));
adapter = new NotificationsAdapter(accountManager.getActiveAccount().getAccountId(), dataSource, statusDisplayOptions, this, this, this);
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
recyclerView.setAdapter(adapter);
topLoading = false;
bottomLoading = false;
bottomId = null;
updateAdapter();
Button buttonClear = rootView.findViewById(R.id.buttonClear);
buttonClear.setOnClickListener(v -> confirmClearNotifications());
buttonFilter = rootView.findViewById(R.id.buttonFilter);
buttonFilter.setOnClickListener(v -> showFilterMenu());
if (notifications.isEmpty()) {
swipeRefreshLayout.setEnabled(false);
sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1);
} else {
progressBar.setVisibility(View.GONE);
}
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
updateFilterVisibility();
return rootView;
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project AntennaPod by AntennaPod.
the class EpisodesListFragment method onCreateView.
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.all_episodes_fragment, container, false);
txtvInformation = root.findViewById(R.id.txtvInformation);
recyclerView = root.findViewById(android.R.id.list);
recyclerView.setRecycledViewPool(((MainActivity) getActivity()).getRecycledViewPool());
setupLoadMoreScrollListener();
RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
swipeRefreshLayout.setOnRefreshListener(() -> {
AutoUpdateManager.runImmediate(requireContext());
new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false), getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
});
progLoading = root.findViewById(R.id.progLoading);
progLoading.setVisibility(View.VISIBLE);
loadingMoreView = root.findViewById(R.id.loadingMore);
emptyView = new EmptyViewHandler(getContext());
emptyView.attachToRecyclerView(recyclerView);
emptyView.setIcon(R.drawable.ic_feed);
emptyView.setTitle(R.string.no_all_episodes_head_label);
emptyView.setMessage(R.string.no_all_episodes_label);
createRecycleAdapter(recyclerView, emptyView);
emptyView.hide();
return root;
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project FlexibleAdapter by davideas.
the class FragmentExpandableSections method initializeRecyclerView.
@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(// Size limit = MAX_VALUE will always animate the changes
Integer.MAX_VALUE).setNotifyMoveOfFilteredItems(// When true, filtering on big list is very slow!
true).setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling).setAnimationOnReverseScrolling(true);
mRecyclerView = getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
mRecyclerView.setAdapter(mAdapter);
// Size of RV will not change
mRecyclerView.setHasFixedSize(true);
// 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));
// Enable long press to drag items
mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(// Enable handle drag
true).setStickyHeaders(true);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project FlexibleAdapter by davideas.
the class FragmentOverall method initializeRecyclerView.
@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);
// Setting ViewCache to 0 (default=2) will animate items better while scrolling down+up with LinearLayout
mRecyclerView.setItemViewCacheSize(0);
mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
mRecyclerView.setAdapter(mAdapter);
// Size of RV will not change
mRecyclerView.setHasFixedSize(true);
mItemDecoration = new FlexibleItemDecoration(getActivity()).addItemViewType(R.layout.recycler_overall_item).withOffset(// This helps when top items are removed!!
8).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);
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project FlexibleAdapter by davideas.
the class FragmentStaggeredLayout method initializeRecyclerView.
@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!
// Make faster the smooth scroll
TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 33f;
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);
// Size of RV will not change
mRecyclerView.setHasFixedSize(true);
// 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));
// Show Headers at startUp!
mAdapter.setDisplayHeadersAtStartUp(true).setNotifyMoveOfFilteredItems(true).setPermanentDelete(// Default=true
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)));
}
Aggregations