Search in sources :

Example 11 with ReaderTag

use of org.wordpress.android.models.ReaderTag 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)

Example 12 with ReaderTag

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

the class ReaderPostListFragment method resumeFollowedTag.

/*
     * called when fragment is resumed and we're looking at posts in a followed tag
     */
private void resumeFollowedTag() {
    Object event = EventBus.getDefault().getStickyEvent(ReaderEvents.TagAdded.class);
    if (event != null) {
        // user just added a tag so switch to it.
        String tagName = ((ReaderEvents.TagAdded) event).getTagName();
        EventBus.getDefault().removeStickyEvent(event);
        ReaderTag newTag = ReaderUtils.getTagFromTagName(tagName, ReaderTagType.FOLLOWED);
        setCurrentTag(newTag);
    } else if (!ReaderTagTable.tagExists(getCurrentTag())) {
        // current tag no longer exists, revert to default
        AppLog.d(T.READER, "reader post list > current tag no longer valid");
        setCurrentTag(ReaderUtils.getDefaultTag());
    } else {
        // otherwise, refresh posts to make sure any changes are reflected and auto-update
        // posts in the current tag if it's time
        refreshPosts();
        updateCurrentTagIfTime();
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag)

Example 13 with ReaderTag

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

the class ReaderTagAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(TagViewHolder holder, int position) {
    final ReaderTag tag = mTags.get(position);
    holder.txtTagName.setText(tag.getLabel());
    holder.btnRemove.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            performDeleteTag(tag);
        }
    });
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 14 with ReaderTag

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

the class ReaderUpdateService method deleteTags.

private static void deleteTags(ReaderTagList tagList) {
    if (tagList == null || tagList.size() == 0) {
        return;
    }
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    db.beginTransaction();
    try {
        for (ReaderTag tag : tagList) {
            ReaderTagTable.deleteTag(tag);
            ReaderPostTable.deletePostsWithTag(tag);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 15 with ReaderTag

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

the class ReaderUpdateService method parseTags.

/*
     * parse a specific topic section from the topic response
     */
private static ReaderTagList parseTags(JSONObject jsonObject, String name, ReaderTagType tagType) {
    ReaderTagList topics = new ReaderTagList();
    if (jsonObject == null) {
        return topics;
    }
    JSONObject jsonTopics = jsonObject.optJSONObject(name);
    if (jsonTopics == null) {
        return topics;
    }
    Iterator<String> it = jsonTopics.keys();
    while (it.hasNext()) {
        String internalName = it.next();
        JSONObject jsonTopic = jsonTopics.optJSONObject(internalName);
        if (jsonTopic != null) {
            String tagTitle = JSONUtils.getStringDecoded(jsonTopic, ReaderConstants.JSON_TAG_TITLE);
            String tagDisplayName = JSONUtils.getStringDecoded(jsonTopic, ReaderConstants.JSON_TAG_DISPLAY_NAME);
            String tagSlug = JSONUtils.getStringDecoded(jsonTopic, ReaderConstants.JSON_TAG_SLUG);
            String endpoint = JSONUtils.getString(jsonTopic, ReaderConstants.JSON_TAG_URL);
            // included in the response as default tags
            if (tagType == ReaderTagType.DEFAULT && endpoint.contains("/read/list/")) {
                topics.add(new ReaderTag(tagSlug, tagDisplayName, tagTitle, endpoint, ReaderTagType.CUSTOM_LIST));
            } else {
                topics.add(new ReaderTag(tagSlug, tagDisplayName, tagTitle, endpoint, tagType));
            }
        }
    }
    return topics;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) JSONObject(org.json.JSONObject) ReaderTagList(org.wordpress.android.models.ReaderTagList)

Aggregations

ReaderTag (org.wordpress.android.models.ReaderTag)18 ReaderTagList (org.wordpress.android.models.ReaderTagList)5 View (android.view.View)4 TextView (android.widget.TextView)3 JSONObject (org.json.JSONObject)3 Context (android.content.Context)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ReaderSiteHeaderView (org.wordpress.android.ui.reader.views.ReaderSiteHeaderView)2 SQLException (android.database.SQLException)1 ActionBar (android.support.v7.app.ActionBar)1 SearchView (android.support.v7.widget.SearchView)1 Toolbar (android.support.v7.widget.Toolbar)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ImageView (android.widget.ImageView)1 VolleyError (com.android.volley.VolleyError)1