use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project AntennaPod by AntennaPod.
the class QueueFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.queue_fragment, container, false);
toolbar = root.findViewById(R.id.toolbar);
toolbar.setOnMenuItemClickListener(this);
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
}
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
toolbar.inflateMenu(R.menu.queue);
refreshToolbarState();
infoBar = root.findViewById(R.id.info_bar);
recyclerView = root.findViewById(R.id.recyclerView);
RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
recyclerView.setRecycledViewPool(((MainActivity) getActivity()).getRecycledViewPool());
registerForContextMenu(recyclerView);
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));
});
swipeActions = new QueueSwipeActions();
swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.QUEUED));
swipeActions.attachTo(recyclerView);
emptyView = new EmptyViewHandler(getContext());
emptyView.attachToRecyclerView(recyclerView);
emptyView.setIcon(R.drawable.ic_playlist);
emptyView.setTitle(R.string.no_items_header_label);
emptyView.setMessage(R.string.no_items_label);
progLoading = root.findViewById(R.id.progLoading);
progLoading.setVisibility(View.VISIBLE);
speedDialView = root.findViewById(R.id.fabSD);
speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay));
speedDialView.inflate(R.menu.episodes_apply_action_speeddial);
speedDialView.removeActionItemById(R.id.mark_read_batch);
speedDialView.removeActionItemById(R.id.mark_unread_batch);
speedDialView.removeActionItemById(R.id.add_to_queue_batch);
speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {
@Override
public boolean onMainActionSelected() {
return false;
}
@Override
public void onToggleChanged(boolean open) {
if (open && recyclerAdapter.getSelectedCount() == 0) {
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.no_items_selected, Snackbar.LENGTH_SHORT);
speedDialView.close();
}
}
});
speedDialView.setOnActionSelectedListener(actionItem -> {
new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), recyclerAdapter.getSelectedItems()).handleAction(actionItem.getId());
recyclerAdapter.endSelectMode();
return true;
});
return root;
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project twicalico by moko256.
the class ShowTweetActivity method onCreate.
@SuppressLint("WrongConstant")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_tweet);
statusId = getIntent().getLongExtra("statusId", -1);
client = GlobalApplicationKt.getClient(this);
requestManager = Glide.with(this);
statusActionModel = new StatusActionModelImpl(client.getApiClient(), client.getPostCache());
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_back_white_24dp);
tweetIsReply = findViewById(R.id.tweet_show_is_reply_text);
statusViewBinder = new StatusViewBinder(findViewById(R.id.tweet_show_tweet));
timestampText = findViewById(R.id.tweet_show_timestamp);
viaText = findViewById(R.id.tweet_show_via);
replyFab = findViewById(R.id.tweet_show_fab);
SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.tweet_show_swipe_refresh);
swipeRefreshLayout.setColorSchemeResources(R.color.color_primary);
swipeRefreshLayout.setOnRefreshListener(() -> statusActionModel.updateStatus(statusId));
disposables.addAll(statusActionModel.getStatusObservable().subscribe(id -> {
Post post = client.getPostCache().getPost(statusId);
if (post != null) {
if (!isVisible) {
isVisible = true;
swipeRefreshLayout.getChildAt(0).setVisibility(VISIBLE);
}
updateView(post);
}
swipeRefreshLayout.setRefreshing(false);
}), statusActionModel.getDidActionObservable().subscribe(it -> Toast.makeText(this, TwitterStringUtils.getDidActionStringRes(client.getAccessToken().getClientType(), it), Toast.LENGTH_SHORT).show()), statusActionModel.getErrorObservable().subscribe(error -> {
error.printStackTrace();
Toast.makeText(this, error.getMessage(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
if (client.getPostCache().getPost(statusId) == null) {
finish();
}
}));
Post status = client.getPostCache().getPost(statusId);
if (status != null) {
updateView(status);
} else {
swipeRefreshLayout.setRefreshing(true);
isVisible = false;
swipeRefreshLayout.getChildAt(0).setVisibility(GONE);
statusActionModel.updateStatus(statusId);
}
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project FlexibleAdapter by davideas.
the class FragmentHeadersSections 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("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());
// 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_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), // Optional!!
(EmptyViewHelper.OnEmptyViewListener) getActivity());
// More settings
mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(true).setSwipeEnabled(true).setStickyHeaderElevation(5).setUnlinkAllItemsOnRemoveHeaders(true).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();
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project FlexibleAdapter by davideas.
the class FragmentAsyncFilter method initializeRecyclerView.
private void initializeRecyclerView() {
// Settings for FlipView
FlipView.resetLayoutAnimationDelay(true, 1000L);
// Size limit = MAX_VALUE will always animate the changes
mAdapter.setAnimateChangesWithDiffUtil(DatabaseConfiguration.animateWithDiffUtil).setAnimateToLimit(DatabaseConfiguration.animateToLimit).setNotifyMoveOfFilteredItems(DatabaseConfiguration.notifyMove).setNotifyChangeOfUnfilteredItems(DatabaseConfiguration.notifyChange).setAnimationInitialDelay(100L).setAnimationOnForwardScrolling(true).setAnimationOnReverseScrolling(true).setOnlyEntryAnimation(true);
if (mRecyclerView == null) {
mRecyclerView = getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
// Adapter changes won't affect the size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
}
// ViewHolders are different so we do NOT swap Adapters
mRecyclerView.setAdapter(mAdapter);
// Custom divider item decorator with Offset
if (mDivider == null) {
mDivider = new FlexibleItemDecoration(getActivity()).withDivider(R.drawable.divider_large);
}
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(!configure);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
if (configure) {
mFab.setImageResource(R.drawable.ic_check_white_24dp);
mRecyclerView.addItemDecoration(mDivider);
FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
fastScroller.setEnabled(false);
} else {
mFab.setImageResource(R.drawable.ic_settings_white_24dp);
mRecyclerView.removeItemDecoration(mDivider);
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), // Optional!!
(EmptyViewHelper.OnEmptyViewListener) getActivity());
// Settings for FlipView
FlipView.stopLayoutAnimation();
showFab(1200L);
}
use of androidx.swiperefreshlayout.widget.SwipeRefreshLayout in project FlexibleAdapter by davideas.
the class FragmentInstagramHeaders method initializeRecyclerView.
@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);
// 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());
// 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));
// Show Headers at startUp!
mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(// Make headers sticky
true).setLoadingMoreAtStartUp(true).setEndlessScrollListener(this, new ProgressItem()).setEndlessScrollThreshold(// Default=1
1);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
}
Aggregations