Search in sources :

Example 26 with SwipeRefreshLayout

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;
}
Also used : SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) FeedItemFilter(de.danoeh.antennapod.model.feed.FeedItemFilter) FeedItemMenuHandler(de.danoeh.antennapod.menuhandler.FeedItemMenuHandler) Handler(android.os.Handler) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) EpisodeMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler) EpisodeMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler) MainActivity(de.danoeh.antennapod.activity.MainActivity) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView)

Example 27 with SwipeRefreshLayout

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);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) StatusActionModel(com.github.moko256.twitlatte.model.base.StatusActionModel) Intent(android.content.Intent) LinkMovementMethod(android.text.method.LinkMovementMethod) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AppCustomTabsKt(com.github.moko256.twitlatte.intent.AppCustomTabsKt) MenuItem(android.view.MenuItem) ClipData(android.content.ClipData) ActionBar(androidx.appcompat.app.ActionBar) SuppressLint(android.annotation.SuppressLint) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) RequestManager(com.bumptech.glide.RequestManager) TwitterStringUtils(com.github.moko256.twitlatte.text.TwitterStringUtils) Toast(android.widget.Toast) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Menu(android.view.Menu) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Button(android.widget.Button) VISIBLE(android.view.View.VISIBLE) StatusActionModelImpl(com.github.moko256.twitlatte.model.impl.StatusActionModelImpl) DateFormat(java.text.DateFormat) Post(com.github.moko256.latte.client.base.entity.Post) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) Client(com.github.moko256.twitlatte.entity.Client) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Unit(kotlin.Unit) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) GONE(android.view.View.GONE) StatusActionModelImpl(com.github.moko256.twitlatte.model.impl.StatusActionModelImpl) Post(com.github.moko256.latte.client.base.entity.Post) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ActionBar(androidx.appcompat.app.ActionBar) SuppressLint(android.annotation.SuppressLint)

Example 28 with SwipeRefreshLayout

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

Example 29 with SwipeRefreshLayout

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

Example 30 with SwipeRefreshLayout

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

Aggregations

SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)41 RecyclerView (androidx.recyclerview.widget.RecyclerView)20 View (android.view.View)19 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)10 Toolbar (androidx.appcompat.widget.Toolbar)9 FastScroller (eu.davidea.fastscroller.FastScroller)8 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)8 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)8 PreCachingLayoutManager (me.ccrama.redditslide.Views.PreCachingLayoutManager)8 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)7 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)7 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)7 Bundle (android.os.Bundle)6 Intent (android.content.Intent)5 Handler (android.os.Handler)5 TextView (android.widget.TextView)5 ContributionAdapter (me.ccrama.redditslide.Adapters.ContributionAdapter)5 Context (android.content.Context)4 NonNull (androidx.annotation.NonNull)4 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4