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