use of org.wordpress.android.models.ReaderTag in project WordPress-Android by wordpress-mobile.
the class ReaderPostListFragment method submitSearchQuery.
private void submitSearchQuery(@NonNull String query) {
if (!isAdded())
return;
// this will hide suggestions and the virtual keyboard
mSearchView.clearFocus();
hideSearchMessage();
// remember this query for future suggestions
String trimQuery = query != null ? query.trim() : "";
ReaderSearchTable.addOrUpdateQueryString(trimQuery);
// remove cached results for this search - search results are ephemeral so each search
// should be treated as a "fresh" one
ReaderTag searchTag = ReaderSearchService.getTagForSearchQuery(trimQuery);
ReaderPostTable.deletePostsWithTag(searchTag);
mPostAdapter.setCurrentTag(searchTag);
mCurrentSearchQuery = trimQuery;
updatePostsInCurrentSearch(0);
// track that the user performed a search
if (!trimQuery.equals("")) {
Map<String, Object> properties = new HashMap<>();
properties.put("query", trimQuery);
AnalyticsTracker.track(AnalyticsTracker.Stat.READER_SEARCH_PERFORMED, properties);
}
}
use of org.wordpress.android.models.ReaderTag in project WordPress-Android by wordpress-mobile.
the class ReaderPostService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
return START_NOT_STICKY;
}
UpdateAction action;
if (intent.hasExtra(ARG_ACTION)) {
action = (UpdateAction) intent.getSerializableExtra(ARG_ACTION);
} else {
action = UpdateAction.REQUEST_NEWER;
}
EventBus.getDefault().post(new ReaderEvents.UpdatePostsStarted(action));
if (intent.hasExtra(ARG_TAG)) {
ReaderTag tag = (ReaderTag) intent.getSerializableExtra(ARG_TAG);
updatePostsWithTag(tag, action);
} else if (intent.hasExtra(ARG_BLOG_ID)) {
long blogId = intent.getLongExtra(ARG_BLOG_ID, 0);
updatePostsInBlog(blogId, action);
} else if (intent.hasExtra(ARG_FEED_ID)) {
long feedId = intent.getLongExtra(ARG_FEED_ID, 0);
updatePostsInFeed(feedId, action);
}
return START_NOT_STICKY;
}
use of org.wordpress.android.models.ReaderTag in project WordPress-Android by wordpress-mobile.
the class ReaderTagActions method addTag.
public static boolean addTag(final ReaderTag tag, final ReaderActions.ActionListener actionListener) {
if (tag == null) {
ReaderActions.callActionListener(actionListener, false);
return false;
}
final String tagNameForApi = ReaderUtils.sanitizeWithDashes(tag.getTagSlug());
final String path = "read/tags/" + tagNameForApi + "/mine/new";
String endpoint = "/read/tags/" + tagNameForApi + "/posts";
ReaderTag newTag = new ReaderTag(tag.getTagSlug(), tag.getTagDisplayName(), tag.getTagTitle(), endpoint, ReaderTagType.FOLLOWED);
com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
AppLog.i(T.READER, "add tag succeeded");
// the response will contain the list of the user's followed tags
ReaderTagList tags = parseFollowedTags(jsonObject);
ReaderTagTable.replaceFollowedTags(tags);
ReaderActions.callActionListener(actionListener, true);
}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// treat is as a success if we're adding a tag and the error says the user is
// already following it
String error = VolleyUtils.errStringFromVolleyError(volleyError);
if (error.equals("already_subscribed")) {
AppLog.w(T.READER, "add tag succeeded with error " + error);
ReaderActions.callActionListener(actionListener, true);
return;
}
AppLog.w(T.READER, "add tag failed");
AppLog.e(T.READER, volleyError);
// revert on failure
ReaderTagTable.deleteTag(tag);
ReaderActions.callActionListener(actionListener, false);
}
};
ReaderTagTable.addOrUpdateTag(newTag);
WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener);
return true;
}
use of org.wordpress.android.models.ReaderTag in project WordPress-Android by wordpress-mobile.
the class ReaderSubsActivity method performAddTag.
/*
* called when user manually enters a tag - passed tag is assumed to be validated
*/
private void performAddTag(final String tagName) {
if (!NetworkUtils.checkConnection(this)) {
return;
}
showProgress();
final ReaderTag tag = ReaderUtils.createTagFromTagName(tagName, ReaderTagType.FOLLOWED);
ReaderActions.ActionListener actionListener = new ReaderActions.ActionListener() {
@Override
public void onActionResult(boolean succeeded) {
if (isFinishing()) {
return;
}
hideProgress();
getPageAdapter().refreshFollowedTagFragment();
if (succeeded) {
AnalyticsTracker.track(AnalyticsTracker.Stat.READER_TAG_FOLLOWED);
showInfoToast(getString(R.string.reader_label_added_tag, tag.getLabel()));
mLastAddedTagName = tag.getTagSlug();
} else {
ToastUtils.showToast(ReaderSubsActivity.this, R.string.reader_toast_err_add_tag);
mLastAddedTagName = null;
}
}
};
ReaderTagActions.addTag(tag, actionListener);
}
use of org.wordpress.android.models.ReaderTag in project WordPress-Android by wordpress-mobile.
the class ReaderTagTable method setRecommendedTags.
public static void setRecommendedTags(ReaderTagList tagList) {
if (tagList == null) {
return;
}
SQLiteDatabase db = ReaderDatabase.getWritableDb();
SQLiteStatement stmt = db.compileStatement("INSERT INTO tbl_tags_recommended (tag_slug, tag_display_name, tag_title, tag_type, endpoint) VALUES (?1,?2,?3,?4,?5)");
db.beginTransaction();
try {
try {
// first delete all recommended tags
db.execSQL("DELETE FROM tbl_tags_recommended");
// then insert the passed ones
for (ReaderTag tag : tagList) {
stmt.bindString(1, tag.getTagSlug());
stmt.bindString(2, tag.getTagDisplayName());
stmt.bindString(3, tag.getTagTitle());
stmt.bindLong(4, tag.tagType.toInt());
stmt.bindString(5, tag.getEndpoint());
stmt.execute();
}
db.setTransactionSuccessful();
} catch (SQLException e) {
AppLog.e(T.READER, e);
}
} finally {
SqlUtils.closeStatement(stmt);
db.endTransaction();
}
}
Aggregations