Search in sources :

Example 1 with ReaderTag

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);
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) HashMap(java.util.HashMap)

Example 2 with ReaderTag

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;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) ReaderEvents(org.wordpress.android.ui.reader.ReaderEvents)

Example 3 with ReaderTag

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;
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) VolleyError(com.android.volley.VolleyError) RestRequest(com.wordpress.rest.RestRequest) JSONObject(org.json.JSONObject) ReaderTagList(org.wordpress.android.models.ReaderTagList)

Example 4 with ReaderTag

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);
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) ReaderActions(org.wordpress.android.ui.reader.actions.ReaderActions)

Example 5 with ReaderTag

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();
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException)

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