Search in sources :

Example 1 with SwipeRefreshLayout

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;
}
Also used : Context(android.content.Context) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) AsyncDifferConfig(androidx.recyclerview.widget.AsyncDifferConfig) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) Utils(at.connyduck.sparkbutton.helpers.Utils) AccountActionListener(com.keylesspalace.tusky.interfaces.AccountActionListener) NotificationTypeConverterKt(com.keylesspalace.tusky.util.NotificationTypeConverterKt) AppBarLayout(com.google.android.material.appbar.AppBarLayout) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) Locale(java.util.Locale) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Function(androidx.arch.core.util.Function) Log(android.util.Log) ViewDataUtils(com.keylesspalace.tusky.util.ViewDataUtils) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) DiffUtil(androidx.recyclerview.widget.DiffUtil) PreferenceChangedEvent(com.keylesspalace.tusky.appstore.PreferenceChangedEvent) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) Set(java.util.Set) Function1(kotlin.jvm.functions.Function1) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) ReselectableFragment(com.keylesspalace.tusky.interfaces.ReselectableFragment) Objects(java.util.Objects) FavoriteEvent(com.keylesspalace.tusky.appstore.FavoriteEvent) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) List(java.util.List) Unit(kotlin.Unit) AutoDispose.autoDisposable(autodispose2.AutoDispose.autoDisposable) Nullable(androidx.annotation.Nullable) Pair(androidx.core.util.Pair) Disposable(io.reactivex.rxjava3.disposables.Disposable) CollectionsKt(kotlin.collections.CollectionsKt) AsyncListDiffer(androidx.recyclerview.widget.AsyncListDiffer) ListView(android.widget.ListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StringUtils.isLessThan(com.keylesspalace.tusky.util.StringUtils.isLessThan) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) BookmarkEvent(com.keylesspalace.tusky.appstore.BookmarkEvent) Notification(com.keylesspalace.tusky.entity.Notification) Single(io.reactivex.rxjava3.core.Single) AlertDialog(androidx.appcompat.app.AlertDialog) Status(com.keylesspalace.tusky.entity.Status) AndroidLifecycleScopeProvider.from(autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider.from) ReblogEvent(com.keylesspalace.tusky.appstore.ReblogEvent) Poll(com.keylesspalace.tusky.entity.Poll) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) PairedList(com.keylesspalace.tusky.util.PairedList) ArrayList(java.util.ArrayList) StatusBaseViewHolder(com.keylesspalace.tusky.adapter.StatusBaseViewHolder) PrefKeys(com.keylesspalace.tusky.settings.PrefKeys) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lifecycle(androidx.lifecycle.Lifecycle) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) Observable(io.reactivex.rxjava3.core.Observable) AttachmentViewData(com.keylesspalace.tusky.viewdata.AttachmentViewData) DialogInterface(android.content.DialogInterface) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) EventHub(com.keylesspalace.tusky.appstore.EventHub) BlockEvent(com.keylesspalace.tusky.appstore.BlockEvent) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) PopupWindow(android.widget.PopupWindow) HttpHeaderLink(com.keylesspalace.tusky.util.HttpHeaderLink) Either(com.keylesspalace.tusky.util.Either) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) ArrayAdapter(android.widget.ArrayAdapter) SparseBooleanArray(android.util.SparseBooleanArray) PinEvent(com.keylesspalace.tusky.appstore.PinEvent) SharedPreferences(android.content.SharedPreferences) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) PreferenceManager(androidx.preference.PreferenceManager) ListUtils(com.keylesspalace.tusky.util.ListUtils) AccountManager(com.keylesspalace.tusky.db.AccountManager) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) Injectable(com.keylesspalace.tusky.di.Injectable) Activity(android.app.Activity) Collections(java.util.Collections) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) SharedPreferences(android.content.SharedPreferences) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ListView(android.widget.ListView) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Button(android.widget.Button) NonNull(androidx.annotation.NonNull) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) Nullable(androidx.annotation.Nullable)

Example 2 with SwipeRefreshLayout

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;
}
Also used : SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) FeedItemMenuHandler(de.danoeh.antennapod.menuhandler.FeedItemMenuHandler) Handler(android.os.Handler) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) RecyclerView(androidx.recyclerview.widget.RecyclerView) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) NonNull(androidx.annotation.NonNull)

Example 3 with SwipeRefreshLayout

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);
}
Also used : FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) FastScroller(eu.davidea.fastscroller.FastScroller) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 4 with SwipeRefreshLayout

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);
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) OverallAdapter(eu.davidea.samples.flexibleadapter.OverallAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Example 5 with SwipeRefreshLayout

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)));
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Aggregations

SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)28 View (android.view.View)10 RecyclerView (androidx.recyclerview.widget.RecyclerView)10 FastScroller (eu.davidea.fastscroller.FastScroller)8 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)8 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)7 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)7 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)7 Toolbar (androidx.appcompat.widget.Toolbar)6 TextView (android.widget.TextView)5 Handler (android.os.Handler)4 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 SimpleItemAnimator (androidx.recyclerview.widget.SimpleItemAnimator)4 Context (android.content.Context)3 DialogInterface (android.content.DialogInterface)3 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)3 SpeedDialView (com.leinardi.android.speeddial.SpeedDialView)3 MainActivity (de.danoeh.antennapod.activity.MainActivity)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2