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;
}
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;
}
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));
}
}
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;
}
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;
}
Aggregations