Search in sources :

Example 1 with EndlessOnScrollListener

use of com.keylesspalace.tusky.view.EndlessOnScrollListener in project Tusky by Vavassor.

the class AccountListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    BaseActivity activity = (BaseActivity) getActivity();
    if (jumpToTopAllowed()) {
        TabLayout layout = (TabLayout) activity.findViewById(R.id.tab_layout);
        onTabSelectedListener = new TabLayout.OnTabSelectedListener() {

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                jumpToTop();
            }
        };
        layout.addOnTabSelectedListener(onTabSelectedListener);
    }
    /* MastodonAPI on the base activity is only guaranteed to be initialised after the parent
         * activity is created, so everything needing to access the api object has to be delayed
         * until here. */
    api = activity.mastodonAPI;
    scrollListener = new EndlessOnScrollListener(layoutManager) {

        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            AccountAdapter adapter = (AccountAdapter) view.getAdapter();
            Account account = adapter.getItem(adapter.getItemCount() - 2);
            if (account != null) {
                fetchAccounts(account.id, null);
            } else {
                fetchAccounts();
            }
        }
    };
    recyclerView.addOnScrollListener(scrollListener);
}
Also used : Account(com.keylesspalace.tusky.entity.Account) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) TabLayout(android.support.design.widget.TabLayout) BaseActivity(com.keylesspalace.tusky.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) AccountAdapter(com.keylesspalace.tusky.adapter.AccountAdapter)

Example 2 with EndlessOnScrollListener

use of com.keylesspalace.tusky.view.EndlessOnScrollListener in project Tusky by tuskyapp.

the class AccountListFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Just use the basic scroll listener to load more accounts.
    scrollListener = new EndlessOnScrollListener(layoutManager) {

        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            AccountListFragment.this.onLoadMore(view);
        }
    };
    recyclerView.addOnScrollListener(scrollListener);
    fetchAccounts(null, null, FetchEnd.BOTTOM);
}
Also used : EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with EndlessOnScrollListener

use of com.keylesspalace.tusky.view.EndlessOnScrollListener in project Tusky by Vavassor.

the class NotificationsFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();
    if (activity == null)
        throw new AssertionError("Activity is null");
    /* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't
         * guaranteed to be set until then.
         * Use a modified scroll listener that both loads more notificationsEnabled as it goes, and hides
         * the compose button on down-scroll. */
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
    hideFab = preferences.getBoolean("fabHide", false);
    scrollListener = new EndlessOnScrollListener(layoutManager) {

        @Override
        public void onScrolled(@NonNull RecyclerView view, int dx, int dy) {
            super.onScrolled(view, dx, dy);
            ActionButtonActivity activity = (ActionButtonActivity) getActivity();
            FloatingActionButton composeButton = activity.getActionButton();
            if (composeButton != null) {
                if (hideFab) {
                    if (dy > 0 && composeButton.isShown()) {
                        // hides the button if we're scrolling down
                        composeButton.hide();
                    } else if (dy < 0 && !composeButton.isShown()) {
                        // shows it if we are scrolling up
                        composeButton.show();
                    }
                } else if (!composeButton.isShown()) {
                    composeButton.show();
                }
            }
        }

        @Override
        public void onLoadMore(int totalItemsCount, RecyclerView view) {
            NotificationsFragment.this.onLoadMore();
        }
    };
    recyclerView.addOnScrollListener(scrollListener);
    eventHub.getEvents().observeOn(AndroidSchedulers.mainThread()).to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe(event -> {
        if (event instanceof FavoriteEvent) {
            setFavouriteForStatus(((FavoriteEvent) event).getStatusId(), ((FavoriteEvent) event).getFavourite());
        } else if (event instanceof BookmarkEvent) {
            setBookmarkForStatus(((BookmarkEvent) event).getStatusId(), ((BookmarkEvent) event).getBookmark());
        } else if (event instanceof ReblogEvent) {
            setReblogForStatus(((ReblogEvent) event).getStatusId(), ((ReblogEvent) event).getReblog());
        } else if (event instanceof PinEvent) {
            setPinForStatus(((PinEvent) event).getStatusId(), ((PinEvent) event).getPinned());
        } else if (event instanceof BlockEvent) {
            removeAllByAccountId(((BlockEvent) event).getAccountId());
        } else if (event instanceof PreferenceChangedEvent) {
            onPreferenceChanged(((PreferenceChangedEvent) event).getPreferenceKey());
        }
    });
}
Also used : PinEvent(com.keylesspalace.tusky.appstore.PinEvent) ReblogEvent(com.keylesspalace.tusky.appstore.ReblogEvent) SharedPreferences(android.content.SharedPreferences) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) Activity(android.app.Activity) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) FavoriteEvent(com.keylesspalace.tusky.appstore.FavoriteEvent) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) RecyclerView(androidx.recyclerview.widget.RecyclerView) BookmarkEvent(com.keylesspalace.tusky.appstore.BookmarkEvent) PreferenceChangedEvent(com.keylesspalace.tusky.appstore.PreferenceChangedEvent) BlockEvent(com.keylesspalace.tusky.appstore.BlockEvent)

Example 4 with EndlessOnScrollListener

use of com.keylesspalace.tusky.view.EndlessOnScrollListener in project Tusky by Vavassor.

the class TimelineFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (jumpToTopAllowed()) {
        TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
        onTabSelectedListener = new TabLayout.OnTabSelectedListener() {

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                jumpToTop();
            }
        };
        layout.addOnTabSelectedListener(onTabSelectedListener);
    }
    /* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't
         * guaranteed to be set until then. */
    if (composeButtonPresent()) {
        /* Use a modified scroll listener that both loads more statuses as it goes, and hides
             * the follow button on down-scroll. */
        MainActivity activity = (MainActivity) getActivity();
        final FloatingActionButton composeButton = activity.composeButton;
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
        preferences.registerOnSharedPreferenceChangeListener(this);
        hideFab = preferences.getBoolean("fabHide", false);
        scrollListener = new EndlessOnScrollListener(layoutManager) {

            @Override
            public void onScrolled(RecyclerView view, int dx, int dy) {
                super.onScrolled(view, dx, dy);
                if (hideFab) {
                    if (dy > 0 && composeButton.isShown()) {
                        // hides the button if we're scrolling down
                        composeButton.hide();
                    } else if (dy < 0 && !composeButton.isShown()) {
                        // shows it if we are scrolling up
                        composeButton.show();
                    }
                } else if (!composeButton.isShown()) {
                    composeButton.show();
                }
            }

            @Override
            public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
                TimelineFragment.this.onLoadMore(view);
            }
        };
    } else {
        // Just use the basic scroll listener to load more statuses.
        scrollListener = new EndlessOnScrollListener(layoutManager) {

            @Override
            public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
                TimelineFragment.this.onLoadMore(view);
            }
        };
    }
    recyclerView.addOnScrollListener(scrollListener);
    preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
}
Also used : EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) SharedPreferences(android.content.SharedPreferences) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) MainActivity(com.keylesspalace.tusky.MainActivity)

Example 5 with EndlessOnScrollListener

use of com.keylesspalace.tusky.view.EndlessOnScrollListener in project Tusky by tuskyapp.

the class TimelineFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (jumpToTopAllowed()) {
        TabLayout layout = getActivity().findViewById(R.id.tab_layout);
        if (layout != null) {
            onTabSelectedListener = new TabLayout.OnTabSelectedListener() {

                @Override
                public void onTabSelected(TabLayout.Tab tab) {
                }

                @Override
                public void onTabUnselected(TabLayout.Tab tab) {
                }

                @Override
                public void onTabReselected(TabLayout.Tab tab) {
                    jumpToTop();
                }
            };
            layout.addOnTabSelectedListener(onTabSelectedListener);
        }
    }
    /* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't
         * guaranteed to be set until then. */
    if (actionButtonPresent()) {
        /* Use a modified scroll listener that both loads more statuses as it goes, and hides
             * the follow button on down-scroll. */
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
        hideFab = preferences.getBoolean("fabHide", false);
        scrollListener = new EndlessOnScrollListener(layoutManager) {

            @Override
            public void onScrolled(RecyclerView view, int dx, int dy) {
                super.onScrolled(view, dx, dy);
                ActionButtonActivity activity = (ActionButtonActivity) getActivity();
                FloatingActionButton composeButton = activity.getActionButton();
                if (composeButton != null) {
                    if (hideFab) {
                        if (dy > 0 && composeButton.isShown()) {
                            // hides the button if we're scrolling down
                            composeButton.hide();
                        } else if (dy < 0 && !composeButton.isShown()) {
                            // shows it if we are scrolling up
                            composeButton.show();
                        }
                    } else if (!composeButton.isShown()) {
                        composeButton.show();
                    }
                }
            }

            @Override
            public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
                TimelineFragment.this.onLoadMore();
            }
        };
    } else {
        // Just use the basic scroll listener to load more statuses.
        scrollListener = new EndlessOnScrollListener(layoutManager) {

            @Override
            public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
                TimelineFragment.this.onLoadMore();
            }
        };
    }
    recyclerView.addOnScrollListener(scrollListener);
}
Also used : EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) SharedPreferences(android.content.SharedPreferences) TabLayout(android.support.design.widget.TabLayout) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

EndlessOnScrollListener (com.keylesspalace.tusky.view.EndlessOnScrollListener)6 RecyclerView (android.support.v7.widget.RecyclerView)5 SharedPreferences (android.content.SharedPreferences)4 TabLayout (android.support.design.widget.TabLayout)4 FloatingActionButton (android.support.design.widget.FloatingActionButton)3 ActionButtonActivity (com.keylesspalace.tusky.interfaces.ActionButtonActivity)3 MainActivity (com.keylesspalace.tusky.MainActivity)2 Activity (android.app.Activity)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1 BaseActivity (com.keylesspalace.tusky.BaseActivity)1 AccountAdapter (com.keylesspalace.tusky.adapter.AccountAdapter)1 BlockEvent (com.keylesspalace.tusky.appstore.BlockEvent)1 BookmarkEvent (com.keylesspalace.tusky.appstore.BookmarkEvent)1 FavoriteEvent (com.keylesspalace.tusky.appstore.FavoriteEvent)1 PinEvent (com.keylesspalace.tusky.appstore.PinEvent)1 PreferenceChangedEvent (com.keylesspalace.tusky.appstore.PreferenceChangedEvent)1 ReblogEvent (com.keylesspalace.tusky.appstore.ReblogEvent)1 Account (com.keylesspalace.tusky.entity.Account)1