Search in sources :

Example 6 with ReaderTag

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

the class ReaderPostTable method purge.

/*
     * purge table of unattached/older posts - no need to wrap this in a transaction since it's
     * only called from ReaderDatabase.purge() which already creates a transaction
     */
protected static int purge(SQLiteDatabase db) {
    // delete posts attached to tags that no longer exist
    int numDeleted = db.delete("tbl_posts", "tag_name NOT IN (SELECT DISTINCT tag_name FROM tbl_tags)", null);
    // delete excess posts on a per-tag basis
    ReaderTagList tags = ReaderTagTable.getAllTags();
    for (ReaderTag tag : tags) {
        numDeleted += purgePostsForTag(db, tag);
    }
    // delete search results
    numDeleted += purgeSearchResults(db);
    return numDeleted;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) ReaderTagList(org.wordpress.android.models.ReaderTagList)

Example 7 with ReaderTag

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

the class ReaderTagActions method parseFollowedTags.

/*
     * return the user's followed tags from the response to read/tags/{tag}/mine/new
     */
/*
        {
        "added_tag": "84776",
        "subscribed": true,
        "tags": [
            {
                "display_name": "fitness",
                "ID": "5189",
                "slug": "fitness",
                "title": "Fitness",
                "URL": "https://public-api.wordpress.com/rest/v1.1/read/tags/fitness/posts"
            },
            ...
        }
     */
private static ReaderTagList parseFollowedTags(JSONObject jsonObject) {
    if (jsonObject == null) {
        return null;
    }
    JSONArray jsonTags = jsonObject.optJSONArray(ReaderConstants.JSON_TAG_TAGS_ARRAY);
    if (jsonTags == null || jsonTags.length() == 0) {
        return null;
    }
    ReaderTagList tags = new ReaderTagList();
    for (int i = 0; i < jsonTags.length(); i++) {
        JSONObject jsonThisTag = jsonTags.optJSONObject(i);
        String tagTitle = JSONUtils.getStringDecoded(jsonThisTag, ReaderConstants.JSON_TAG_TITLE);
        String tagDisplayName = JSONUtils.getStringDecoded(jsonThisTag, ReaderConstants.JSON_TAG_DISPLAY_NAME);
        String tagSlug = JSONUtils.getStringDecoded(jsonThisTag, ReaderConstants.JSON_TAG_SLUG);
        String endpoint = JSONUtils.getString(jsonThisTag, ReaderConstants.JSON_TAG_URL);
        tags.add(new ReaderTag(tagSlug, tagDisplayName, tagTitle, endpoint, ReaderTagType.FOLLOWED));
    }
    return tags;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ReaderTagList(org.wordpress.android.models.ReaderTagList)

Example 8 with ReaderTag

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

the class ReaderPostListActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reader_activity_post_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (getIntent().hasExtra(ReaderConstants.ARG_POST_LIST_TYPE)) {
        mPostListType = (ReaderPostListType) getIntent().getSerializableExtra(ReaderConstants.ARG_POST_LIST_TYPE);
    } else {
        mPostListType = ReaderTypes.DEFAULT_POST_LIST_TYPE;
    }
    if (getPostListType() == ReaderPostListType.TAG_PREVIEW || getPostListType() == ReaderPostListType.BLOG_PREVIEW) {
        // show an X in the toolbar which closes the activity - if this is tag preview, then
        // using the back button will navigate through tags if the user explores beyond a single tag
        toolbar.setNavigationIcon(R.drawable.ic_cross_white_24dp);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                finish();
            }
        });
        if (getPostListType() == ReaderPostListType.BLOG_PREVIEW) {
            setTitle(R.string.reader_title_blog_preview);
            if (savedInstanceState == null) {
                long blogId = getIntent().getLongExtra(ReaderConstants.ARG_BLOG_ID, 0);
                long feedId = getIntent().getLongExtra(ReaderConstants.ARG_FEED_ID, 0);
                if (feedId != 0) {
                    showListFragmentForFeed(feedId);
                } else {
                    showListFragmentForBlog(blogId);
                }
            }
        } else if (getPostListType() == ReaderPostListType.TAG_PREVIEW) {
            setTitle(R.string.reader_title_tag_preview);
            ReaderTag tag = (ReaderTag) getIntent().getSerializableExtra(ReaderConstants.ARG_TAG);
            if (tag != null && savedInstanceState == null) {
                showListFragmentForTag(tag, mPostListType);
            }
        }
    }
    // restore the activity title
    if (savedInstanceState != null && savedInstanceState.containsKey(ReaderConstants.KEY_ACTIVITY_TITLE)) {
        setTitle(savedInstanceState.getString(ReaderConstants.KEY_ACTIVITY_TITLE));
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with ReaderTag

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

the class ReaderPostListFragment method goBackInTagHistory.

/*
    * when previewing posts with a specific tag, a history of previewed tags is retained so
    * the user can navigate back through them - this is faster and requires less memory
    * than creating a new fragment for each previewed tag
    */
private boolean goBackInTagHistory() {
    if (mTagPreviewHistory.empty()) {
        return false;
    }
    String tagName = mTagPreviewHistory.pop();
    if (isCurrentTagName(tagName)) {
        if (mTagPreviewHistory.empty()) {
            return false;
        }
        tagName = mTagPreviewHistory.pop();
    }
    ReaderTag newTag = ReaderUtils.getTagFromTagName(tagName, ReaderTagType.FOLLOWED);
    setCurrentTag(newTag);
    return true;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag)

Example 10 with ReaderTag

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

the class ReaderPostListFragment method getPostAdapter.

private ReaderPostAdapter getPostAdapter() {
    if (mPostAdapter == null) {
        AppLog.d(T.READER, "reader post list > creating post adapter");
        Context context = WPActivityUtils.getThemedContext(getActivity());
        mPostAdapter = new ReaderPostAdapter(context, getPostListType());
        mPostAdapter.setOnPostSelectedListener(this);
        mPostAdapter.setOnPostPopupListener(this);
        mPostAdapter.setOnDataLoadedListener(mDataLoadedListener);
        mPostAdapter.setOnDataRequestedListener(mDataRequestedListener);
        if (getActivity() instanceof ReaderSiteHeaderView.OnBlogInfoLoadedListener) {
            mPostAdapter.setOnBlogInfoLoadedListener((ReaderSiteHeaderView.OnBlogInfoLoadedListener) getActivity());
        }
        if (getPostListType().isTagType()) {
            mPostAdapter.setCurrentTag(getCurrentTag());
        } else if (getPostListType() == ReaderPostListType.BLOG_PREVIEW) {
            mPostAdapter.setCurrentBlogAndFeed(mCurrentBlogId, mCurrentFeedId);
        } else if (getPostListType() == ReaderPostListType.SEARCH_RESULTS) {
            ReaderTag searchTag = ReaderSearchService.getTagForSearchQuery(mCurrentSearchQuery);
            mPostAdapter.setCurrentTag(searchTag);
        }
    }
    return mPostAdapter;
}
Also used : Context(android.content.Context) ReaderTag(org.wordpress.android.models.ReaderTag) ReaderPostAdapter(org.wordpress.android.ui.reader.adapters.ReaderPostAdapter) ReaderSiteHeaderView(org.wordpress.android.ui.reader.views.ReaderSiteHeaderView)

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