Search in sources :

Example 1 with EmptyViewMessageType

use of org.wordpress.android.ui.EmptyViewMessageType in project WordPress-Android by wordpress-mobile.

the class CommentsListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.comment_list_fragment, container, false);
    mFilteredCommentsView = (FilteredRecyclerView) view.findViewById(R.id.filtered_recycler_view);
    mFilteredCommentsView.setLogT(AppLog.T.COMMENTS);
    mFilteredCommentsView.setFilterListener(new FilteredRecyclerView.FilterListener() {

        @Override
        public List<FilterCriteria> onLoadFilterCriteriaOptions(boolean refresh) {
            @SuppressWarnings("unchecked") ArrayList<FilterCriteria> criteria = new ArrayList();
            Collections.addAll(criteria, commentStatuses);
            return criteria;
        }

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

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

        @Override
        public void onFilterSelected(int position, FilterCriteria criteria) {
            AppPrefs.setCommentsStatusFilter((CommentStatusCriteria) criteria);
            mCommentStatusFilter = (CommentStatusCriteria) criteria;
        }

        @Override
        public FilterCriteria onRecallSelection() {
            mCommentStatusFilter = AppPrefs.getCommentsStatusFilter();
            return mCommentStatusFilter;
        }

        @Override
        public String onShowEmptyViewMessage(EmptyViewMessageType emptyViewMsgType) {
            if (emptyViewMsgType == EmptyViewMessageType.NO_CONTENT) {
                FilterCriteria filter = mFilteredCommentsView.getCurrentFilter();
                if (filter == null || filter == CommentStatusCriteria.ALL) {
                    return getString(R.string.comments_empty_list);
                } else {
                    switch(mCommentStatusFilter) {
                        case APPROVED:
                            return getString(R.string.comments_empty_list_filtered_approved);
                        case UNAPPROVED:
                            return getString(R.string.comments_empty_list_filtered_pending);
                        case SPAM:
                            return getString(R.string.comments_empty_list_filtered_spam);
                        case TRASH:
                            return getString(R.string.comments_empty_list_filtered_trashed);
                        default:
                            return getString(R.string.comments_empty_list);
                    }
                }
            } else {
                int stringId = 0;
                switch(emptyViewMsgType) {
                    case LOADING:
                        stringId = R.string.comments_fetching;
                        break;
                    case NETWORK_ERROR:
                        stringId = R.string.no_network_message;
                        break;
                    case PERMISSION_ERROR:
                        stringId = R.string.error_refresh_unauthorized_comments;
                        break;
                    case GENERIC_ERROR:
                        stringId = R.string.error_refresh_comments;
                        break;
                }
                return getString(stringId);
            }
        }

        @Override
        public void onShowCustomEmptyView(EmptyViewMessageType emptyViewMsgType) {
        }
    });
    // the following will change the look and feel of the toolbar to match the current design
    mFilteredCommentsView.setToolbarBackgroundColor(ContextCompat.getColor(getActivity(), R.color.blue_medium));
    mFilteredCommentsView.setToolbarSpinnerTextColor(ContextCompat.getColor(getActivity(), R.color.white));
    mFilteredCommentsView.setToolbarSpinnerDrawable(R.drawable.ic_dropdown_blue_light_24dp);
    mFilteredCommentsView.setToolbarLeftAndRightPadding(getResources().getDimensionPixelSize(R.dimen.margin_filter_spinner), getResources().getDimensionPixelSize(R.dimen.margin_none));
    return view;
}
Also used : ArrayList(java.util.ArrayList) FilterCriteria(org.wordpress.android.models.FilterCriteria) View(android.view.View) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) EmptyViewMessageType(org.wordpress.android.ui.EmptyViewMessageType) ArrayList(java.util.ArrayList) CommentList(org.wordpress.android.models.CommentList) List(java.util.List)

Example 2 with EmptyViewMessageType

use of org.wordpress.android.ui.EmptyViewMessageType 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)

Example 3 with EmptyViewMessageType

use of org.wordpress.android.ui.EmptyViewMessageType in project WordPress-Android by wordpress-mobile.

the class ReaderPostListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.reader_fragment_post_cards, container, false);
    mRecyclerView = (FilteredRecyclerView) rootView.findViewById(R.id.reader_recycler_view);
    Context context = container.getContext();
    // view that appears when current tag/blog has no posts - box images in this view are
    // displayed and animated for tags only
    mEmptyView = rootView.findViewById(R.id.empty_custom_view);
    mEmptyViewBoxImages = mEmptyView.findViewById(R.id.layout_box_images);
    mRecyclerView.setLogT(AppLog.T.READER);
    mRecyclerView.setCustomEmptyView(mEmptyView);
    mRecyclerView.setFilterListener(new FilteredRecyclerView.FilterListener() {

        @Override
        public List<FilterCriteria> onLoadFilterCriteriaOptions(boolean refresh) {
            return null;
        }

        @Override
        public void onLoadFilterCriteriaOptionsAsync(FilteredRecyclerView.FilterCriteriaAsyncLoaderListener listener, boolean refresh) {
            loadTags(listener);
        }

        @Override
        public void onLoadData() {
            if (!isAdded()) {
                return;
            }
            if (!NetworkUtils.checkConnection(getActivity())) {
                mRecyclerView.setRefreshing(false);
                return;
            }
            if (mFirstLoad) {
                /* let onResume() take care of this logic, as the FilteredRecyclerView.FilterListener onLoadData method
                    * is called on two moments: once for first time load, and then each time the swipe to refresh gesture
                    * triggers a refresh
                    */
                mRecyclerView.setRefreshing(false);
                mFirstLoad = false;
            } else {
                switch(getPostListType()) {
                    case TAG_FOLLOWED:
                    case TAG_PREVIEW:
                        updatePostsWithTag(getCurrentTag(), UpdateAction.REQUEST_NEWER);
                        break;
                    case BLOG_PREVIEW:
                        updatePostsInCurrentBlogOrFeed(UpdateAction.REQUEST_NEWER);
                        break;
                }
                // make sure swipe-to-refresh progress shows since this is a manual refresh
                mRecyclerView.setRefreshing(true);
            }
        }

        @Override
        public void onFilterSelected(int position, FilterCriteria criteria) {
            onTagChanged((ReaderTag) criteria);
        }

        @Override
        public FilterCriteria onRecallSelection() {
            if (hasCurrentTag()) {
                return getCurrentTag();
            } else {
                AppLog.w(T.READER, "reader post list > no current tag in onRecallSelection");
                return ReaderUtils.getDefaultTag();
            }
        }

        @Override
        public String onShowEmptyViewMessage(EmptyViewMessageType emptyViewMsgType) {
            return null;
        }

        @Override
        public void onShowCustomEmptyView(EmptyViewMessageType emptyViewMsgType) {
            setEmptyTitleAndDescription(EmptyViewMessageType.NETWORK_ERROR.equals(emptyViewMsgType) || EmptyViewMessageType.PERMISSION_ERROR.equals(emptyViewMsgType) || EmptyViewMessageType.GENERIC_ERROR.equals(emptyViewMsgType));
        }
    });
    // add the item decoration (dividers) to the recycler, skipping the first item if the first
    // item is the tag toolbar (shown when viewing posts in followed tags) - this is to avoid
    // having the tag toolbar take up more vertical space than necessary
    int spacingHorizontal = context.getResources().getDimensionPixelSize(R.dimen.reader_card_margin);
    int spacingVertical = context.getResources().getDimensionPixelSize(R.dimen.reader_card_gutters);
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical, false));
    // the following will change the look and feel of the toolbar to match the current design
    mRecyclerView.setToolbarBackgroundColor(ContextCompat.getColor(context, R.color.blue_medium));
    mRecyclerView.setToolbarSpinnerTextColor(ContextCompat.getColor(context, R.color.white));
    mRecyclerView.setToolbarSpinnerDrawable(R.drawable.ic_dropdown_blue_light_24dp);
    mRecyclerView.setToolbarLeftAndRightPadding(getResources().getDimensionPixelSize(R.dimen.margin_medium) + spacingHorizontal, getResources().getDimensionPixelSize(R.dimen.margin_extra_large) + spacingHorizontal);
    // add a menu to the filtered recycler's toolbar
    if (mAccountStore.hasAccessToken() && (getPostListType() == ReaderPostListType.TAG_FOLLOWED || getPostListType() == ReaderPostListType.SEARCH_RESULTS)) {
        setupRecyclerToolbar();
    }
    mRecyclerView.setSwipeToRefreshEnabled(isSwipeToRefreshSupported());
    // bar that appears at top after new posts are loaded
    mNewPostsBar = rootView.findViewById(R.id.layout_new_posts);
    mNewPostsBar.setVisibility(View.GONE);
    mNewPostsBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mRecyclerView.scrollRecycleViewToPosition(0);
            refreshPosts();
        }
    });
    // progress bar that appears when loading more posts
    mProgress = (ProgressBar) rootView.findViewById(R.id.progress_footer);
    mProgress.setVisibility(View.GONE);
    return rootView;
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) FilterCriteria(org.wordpress.android.models.FilterCriteria) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) SearchView(android.support.v7.widget.SearchView) ReaderSiteHeaderView(org.wordpress.android.ui.reader.views.ReaderSiteHeaderView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) AutoCompleteTextView(android.widget.AutoCompleteTextView) RecyclerView(android.support.v7.widget.RecyclerView) ReaderTag(org.wordpress.android.models.ReaderTag) RecyclerItemDecoration(org.wordpress.android.widgets.RecyclerItemDecoration) EmptyViewMessageType(org.wordpress.android.ui.EmptyViewMessageType) List(java.util.List) ReaderTagList(org.wordpress.android.models.ReaderTagList) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 FilterCriteria (org.wordpress.android.models.FilterCriteria)3 EmptyViewMessageType (org.wordpress.android.ui.EmptyViewMessageType)3 FilteredRecyclerView (org.wordpress.android.ui.FilteredRecyclerView)3 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Context (android.content.Context)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 CommentList (org.wordpress.android.models.CommentList)1 PeopleListFilter (org.wordpress.android.models.PeopleListFilter)1 ReaderTag (org.wordpress.android.models.ReaderTag)1 ReaderTagList (org.wordpress.android.models.ReaderTagList)1 ReaderSiteHeaderView (org.wordpress.android.ui.reader.views.ReaderSiteHeaderView)1 RecyclerItemDecoration (org.wordpress.android.widgets.RecyclerItemDecoration)1