Search in sources :

Example 1 with PeopleListFilter

use of org.wordpress.android.models.PeopleListFilter in project WordPress-Android by wordpress-mobile.

the class PeopleListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.people_list_fragment, container, false);
    mSite = (SiteModel) getArguments().getSerializable(WordPress.SITE);
    final boolean isPrivate = mSite != null && mSite.isPrivate();
    mFilteredRecyclerView = (FilteredRecyclerView) rootView.findViewById(R.id.filtered_recycler_view);
    mFilteredRecyclerView.addItemDecoration(new PeopleItemDecoration(getActivity(), R.drawable.people_list_divider));
    mFilteredRecyclerView.setLogT(AppLog.T.PEOPLE);
    mFilteredRecyclerView.setSwipeToRefreshEnabled(false);
    // the following will change the look and feel of the toolbar to match the current design
    mFilteredRecyclerView.setToolbarBackgroundColor(ContextCompat.getColor(getActivity(), R.color.blue_medium));
    mFilteredRecyclerView.setToolbarSpinnerTextColor(ContextCompat.getColor(getActivity(), R.color.white));
    mFilteredRecyclerView.setToolbarSpinnerDrawable(R.drawable.ic_dropdown_blue_light_24dp);
    mFilteredRecyclerView.setToolbarLeftAndRightPadding(getResources().getDimensionPixelSize(R.dimen.margin_filter_spinner), getResources().getDimensionPixelSize(R.dimen.margin_none));
    mFilteredRecyclerView.setFilterListener(new FilteredRecyclerView.FilterListener() {

        @Override
        public List<FilterCriteria> onLoadFilterCriteriaOptions(boolean refresh) {
            ArrayList<FilterCriteria> list = new ArrayList<>();
            Collections.addAll(list, PeopleListFilter.values());
            // Only a private blog can have viewers
            if (!isPrivate) {
                list.remove(PeopleListFilter.VIEWERS);
            }
            return list;
        }

        @Override
        public void onLoadFilterCriteriaOptionsAsync(FilteredRecyclerView.FilterCriteriaAsyncLoaderListener listener, boolean refresh) {
        // no-op
        }

        @Override
        public FilterCriteria onRecallSelection() {
            mPeopleListFilter = AppPrefs.getPeopleListFilter();
            // if viewers is not available for this blog, set the filter to TEAM
            if (mPeopleListFilter == PeopleListFilter.VIEWERS && !isPrivate) {
                mPeopleListFilter = PeopleListFilter.TEAM;
                AppPrefs.setPeopleListFilter(mPeopleListFilter);
            }
            return mPeopleListFilter;
        }

        @Override
        public void onLoadData() {
            updatePeople(false);
        }

        @Override
        public void onFilterSelected(int position, FilterCriteria criteria) {
            mPeopleListFilter = (PeopleListFilter) criteria;
            AppPrefs.setPeopleListFilter(mPeopleListFilter);
        }

        @Override
        public String onShowEmptyViewMessage(EmptyViewMessageType emptyViewMsgType) {
            int stringId = 0;
            switch(emptyViewMsgType) {
                case LOADING:
                    stringId = R.string.people_fetching;
                    break;
                case NETWORK_ERROR:
                    stringId = R.string.no_network_message;
                    break;
                case NO_CONTENT:
                    switch(mPeopleListFilter) {
                        case TEAM:
                            stringId = R.string.people_empty_list_filtered_users;
                            break;
                        case FOLLOWERS:
                            stringId = R.string.people_empty_list_filtered_followers;
                            break;
                        case EMAIL_FOLLOWERS:
                            stringId = R.string.people_empty_list_filtered_email_followers;
                            break;
                        case VIEWERS:
                            stringId = R.string.people_empty_list_filtered_viewers;
                            break;
                    }
                    break;
                case GENERIC_ERROR:
                    switch(mPeopleListFilter) {
                        case TEAM:
                            stringId = R.string.error_fetch_users_list;
                            break;
                        case FOLLOWERS:
                            stringId = R.string.error_fetch_followers_list;
                            break;
                        case EMAIL_FOLLOWERS:
                            stringId = R.string.error_fetch_email_followers_list;
                            break;
                        case VIEWERS:
                            stringId = R.string.error_fetch_viewers_list;
                            break;
                    }
                    break;
            }
            return getString(stringId);
        }

        @Override
        public void onShowCustomEmptyView(EmptyViewMessageType emptyViewMsgType) {
        }
    });
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) FilterCriteria(org.wordpress.android.models.FilterCriteria) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) PeopleListFilter(org.wordpress.android.models.PeopleListFilter) EmptyViewMessageType(org.wordpress.android.ui.EmptyViewMessageType) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ViewGroup (android.view.ViewGroup)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FilterCriteria (org.wordpress.android.models.FilterCriteria)1 PeopleListFilter (org.wordpress.android.models.PeopleListFilter)1 EmptyViewMessageType (org.wordpress.android.ui.EmptyViewMessageType)1 FilteredRecyclerView (org.wordpress.android.ui.FilteredRecyclerView)1