Search in sources :

Example 1 with AccountAdapter

use of com.keylesspalace.tusky.adapter.AccountAdapter 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 AccountAdapter

use of com.keylesspalace.tusky.adapter.AccountAdapter in project Tusky by tuskyapp.

the class AccountListFragment method onLoadMore.

private void onLoadMore(RecyclerView recyclerView) {
    AccountAdapter adapter = (AccountAdapter) recyclerView.getAdapter();
    // if we do not have a bottom id, we know we do not need to load more
    if (adapter.getBottomId() == null)
        return;
    fetchAccounts(adapter.getBottomId(), null, FetchEnd.BOTTOM);
}
Also used : AccountAdapter(com.keylesspalace.tusky.adapter.AccountAdapter)

Aggregations

AccountAdapter (com.keylesspalace.tusky.adapter.AccountAdapter)2 TabLayout (android.support.design.widget.TabLayout)1 RecyclerView (android.support.v7.widget.RecyclerView)1 BaseActivity (com.keylesspalace.tusky.BaseActivity)1 Account (com.keylesspalace.tusky.entity.Account)1 EndlessOnScrollListener (com.keylesspalace.tusky.view.EndlessOnScrollListener)1