use of org.wordpress.android.models.ReaderBlog in project WordPress-Android by wordpress-mobile.
the class ReaderBlogActions method handleUpdateBlogInfoResponse.
private static void handleUpdateBlogInfoResponse(JSONObject jsonObject, UpdateBlogInfoListener infoListener) {
if (jsonObject == null) {
if (infoListener != null) {
infoListener.onResult(null);
}
return;
}
ReaderBlog blogInfo = ReaderBlog.fromJson(jsonObject);
ReaderBlogTable.addOrUpdateBlog(blogInfo);
if (infoListener != null) {
infoListener.onResult(blogInfo);
}
}
use of org.wordpress.android.models.ReaderBlog in project WordPress-Android by wordpress-mobile.
the class ReaderBlogActions method followFeedById.
public static boolean followFeedById(final long feedId, final boolean isAskingToFollow, final ActionListener actionListener) {
ReaderBlog blogInfo = ReaderBlogTable.getFeedInfo(feedId);
if (blogInfo != null) {
return internalFollowFeed(blogInfo.feedId, blogInfo.getFeedUrl(), isAskingToFollow, actionListener);
}
updateFeedInfo(feedId, null, new UpdateBlogInfoListener() {
@Override
public void onResult(ReaderBlog blogInfo) {
if (blogInfo != null) {
internalFollowFeed(blogInfo.feedId, blogInfo.getFeedUrl(), isAskingToFollow, actionListener);
} else {
ReaderActions.callActionListener(actionListener, false);
}
}
});
return true;
}
use of org.wordpress.android.models.ReaderBlog in project WordPress-Android by wordpress-mobile.
the class ReaderBlogActions method followFeedByUrl.
public static void followFeedByUrl(final String feedUrl, final ActionListener actionListener) {
if (TextUtils.isEmpty(feedUrl)) {
ReaderActions.callActionListener(actionListener, false);
return;
}
// use existing blog info if we can
ReaderBlog blogInfo = ReaderBlogTable.getFeedInfo(ReaderBlogTable.getFeedIdFromUrl(feedUrl));
if (blogInfo != null) {
internalFollowFeed(blogInfo.feedId, blogInfo.getFeedUrl(), true, actionListener);
return;
}
// otherwise, look it up via the endpoint
updateFeedInfo(0, feedUrl, new UpdateBlogInfoListener() {
@Override
public void onResult(ReaderBlog blogInfo) {
// note we attempt to follow even when the look up fails (blogInfo = null) because that
// endpoint doesn't perform feed discovery, whereas the endpoint to follow a feed does
long feedIdToFollow = blogInfo != null ? blogInfo.feedId : 0;
String feedUrlToFollow = (blogInfo != null && blogInfo.hasFeedUrl()) ? blogInfo.getFeedUrl() : feedUrl;
internalFollowFeed(feedIdToFollow, feedUrlToFollow, true, actionListener);
}
});
}
use of org.wordpress.android.models.ReaderBlog in project WordPress-Android by wordpress-mobile.
the class ReaderBlogTable method getFollowedBlogs.
/*
* returns blogInfo for all followed blogs
*/
public static ReaderBlogList getFollowedBlogs() {
Cursor c = ReaderDatabase.getReadableDb().rawQuery("SELECT * FROM tbl_blog_info WHERE is_following!=0 ORDER BY name COLLATE NOCASE, blog_url", null);
try {
ReaderBlogList blogs = new ReaderBlogList();
if (c.moveToFirst()) {
do {
ReaderBlog blogInfo = getBlogInfoFromCursor(c);
blogs.add(blogInfo);
} while (c.moveToNext());
}
return blogs;
} finally {
SqlUtils.closeCursor(c);
}
}
use of org.wordpress.android.models.ReaderBlog in project WordPress-Android by wordpress-mobile.
the class ReaderBlogTable method getBlogInfoFromCursor.
private static ReaderBlog getBlogInfoFromCursor(Cursor c) {
if (c == null) {
return null;
}
ReaderBlog blogInfo = new ReaderBlog();
blogInfo.blogId = c.getLong(c.getColumnIndex("blog_id"));
blogInfo.feedId = c.getLong(c.getColumnIndex("feed_id"));
blogInfo.setUrl(c.getString(c.getColumnIndex("blog_url")));
blogInfo.setImageUrl(c.getString(c.getColumnIndex("image_url")));
blogInfo.setFeedUrl(c.getString(c.getColumnIndex("feed_url")));
blogInfo.setName(c.getString(c.getColumnIndex("name")));
blogInfo.setDescription(c.getString(c.getColumnIndex("description")));
blogInfo.isPrivate = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_private")));
blogInfo.isJetpack = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_jetpack")));
blogInfo.isFollowing = SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("is_following")));
blogInfo.numSubscribers = c.getInt(c.getColumnIndex("num_followers"));
return blogInfo;
}
Aggregations