Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
2c25280
First pass at adding toolbar above reader post list
nbradbury May 5, 2016
56f0bee
Replaced filtered recycler's ability to add components with a simpler…
nbradbury May 5, 2016
f9e5ca3
Check isAdded() in toolbar listener
nbradbury May 5, 2016
0a015bc
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 5, 2016
518db33
First pass at adding SearchView
nbradbury May 5, 2016
ca0890d
Fixed centering of menu items in toolbar
nbradbury May 6, 2016
5666942
Toggle settings icon with search
nbradbury May 6, 2016
b295c04
Removed toolbar listener from addToolbarMenu
nbradbury May 6, 2016
f340723
Simplified search view config
nbradbury May 6, 2016
ec694f2
Added bare-bones SearchViewStyle
nbradbury May 6, 2016
5b1463e
Implemented shell for search results, including empty message
nbradbury May 6, 2016
d1594ca
Clear the post list when search is expanded, reload the list when sea…
nbradbury May 6, 2016
5bdb33d
Renamed FilteredRecyclerViewFilterContainer style to FilteredRecycler…
nbradbury May 6, 2016
17ee94e
Added tbl_search_history
nbradbury May 6, 2016
67b9a4d
Added suggestion adapter
nbradbury May 6, 2016
95cc569
Moved suggestion adapter to it's own class file
nbradbury May 6, 2016
9fc30b7
Added suggestion filtering
nbradbury May 6, 2016
63097ce
Collapse search input upon submit
nbradbury May 6, 2016
51fbe2b
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 10, 2016
c7fc937
First pass at empty view for search
nbradbury May 10, 2016
891a029
Move empty search title to resources
nbradbury May 10, 2016
62317a9
Don't show updated posts during search
nbradbury May 12, 2016
09fbec3
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 12, 2016
6279f18
Tapping back button when search is expanded now closes it
nbradbury May 12, 2016
d5b0364
Don't show empty message for search when in landscape
nbradbury May 12, 2016
1284722
Use a separate view for the search explainer
nbradbury May 12, 2016
e3e95df
Recycler is now hidden rather than cleared when searching
nbradbury May 12, 2016
8b96bec
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 12, 2016
6e3335b
Merge pull request #4085 from wordpress-mobile/feature/reader-search-…
daniloercoli May 12, 2016
3059d72
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 13, 2016
d3e5585
Resolved conflicts in ReaderDatabase.java and ReaderTagTable.java
nbradbury May 13, 2016
1d9c4e0
First pass at reader search service
nbradbury May 13, 2016
24a4bf5
Submit search query on suggestion click
nbradbury May 13, 2016
5813aed
Empty view for no results now works
nbradbury May 13, 2016
f9a5b4b
Added "Searching..." message while search is active
nbradbury May 13, 2016
ca18d72
Search results are now stored in main post table
nbradbury May 13, 2016
aa4b578
Updated getTagForSearchQuery
nbradbury May 13, 2016
41477b5
Added ReaderPostListType.SEARCH_RESULTS
nbradbury May 13, 2016
9fd61a4
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 13, 2016
39f2a1f
Search results are now correctly displayed when search finishes
nbradbury May 13, 2016
89190a4
Clear existing results before performing search
nbradbury May 13, 2016
b366ecc
Return max 10 results
nbradbury May 13, 2016
b543159
Set the autocomplete search threshold to 1
nbradbury May 13, 2016
60a7fb2
Move setThreshold() to initial setup
nbradbury May 13, 2016
dcbfb3e
Show boxes & pages anim when searching
nbradbury May 13, 2016
87840c5
Retain search activity title upon rotation
nbradbury May 13, 2016
9e5aaf5
No longer removing previous search results
nbradbury May 13, 2016
c358566
Use custom layout for search suggestions
nbradbury May 14, 2016
3f687aa
Apply max suggestions
nbradbury May 14, 2016
fef6b5c
Clean up getQueryStrings
nbradbury May 14, 2016
f5696bd
First pass at infinite scroll for search
nbradbury May 14, 2016
fd35877
Second pass at infinite scroll for search
nbradbury May 15, 2016
1dfe743
Third pass at infinite scroll for search
nbradbury May 15, 2016
bd3551f
Parse score from search results to determine sort order
nbradbury May 15, 2016
4367231
Updated comment about timestamps
nbradbury May 15, 2016
7d529c4
Change post timestamp to REAL (double)
nbradbury May 15, 2016
132fe18
First pass at showing search results in main reader (no separate acti…
nbradbury May 15, 2016
db99f1e
2nd pass at showing search results in main reader
nbradbury May 15, 2016
7112499
3rd pass at showing search results in main reader
nbradbury May 15, 2016
5e7d397
Fixed search message for landscape
nbradbury May 15, 2016
32f883e
Fixed device rotation issues, now re-using empty view for search message
nbradbury May 15, 2016
1363d6f
Simplified post adapter to use the current tag when searching
nbradbury May 15, 2016
007ae27
No longer clearing cached searches again
nbradbury May 15, 2016
0f1b346
Make sure toolbar showing search keyword is showing when returning to…
nbradbury May 15, 2016
d4cd5d0
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 15, 2016
72987f1
Use a CursorAdapter rather than a SimpleCursorAdapter for search sugg…
nbradbury May 15, 2016
5136967
Enable deleting search suggestions
nbradbury May 15, 2016
4032f4c
Renamed suggestion table and dropped counter
nbradbury May 15, 2016
769acfb
Increment db version counter
nbradbury May 15, 2016
ca4c263
Rewrote `setEmptyTitleAndDescription` to better handle search
nbradbury May 15, 2016
d0912a9
Added `showEmptyView()` and `hideEmptyView()`
nbradbury May 16, 2016
11eb8b8
Removed `newInstanceForSearch`
nbradbury May 16, 2016
0808f6e
Show search message even in landscape
nbradbury May 16, 2016
946eed1
Clear query when searchView is collapsed
nbradbury May 16, 2016
8b442e7
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 16, 2016
c973d68
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 16, 2016
ffdf77a
Purge all searches when reader db is purged at startup
nbradbury May 16, 2016
941d999
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 17, 2016
dfca3da
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 17, 2016
fcacbc1
Merge remote-tracking branch 'origin/feature/reader-search-master' in…
nbradbury May 17, 2016
6662401
Simplified and clarified the usage of SearchPostsEnded
nbradbury May 17, 2016
9d2d58e
Switch suggestion adapter to a MatrixCursor
nbradbury May 17, 2016
04382aa
Addd custom item
nbradbury May 17, 2016
8dd6b2b
Assign custom click handler in newView()
nbradbury May 17, 2016
7218345
Clear all is now confirmed
nbradbury May 17, 2016
3a42260
Remove cached results before requesting search results
nbradbury May 17, 2016
d67aabe
Removed todo (separate issue filed)
nbradbury May 19, 2016
d681df6
Merge branches 'feature/reader-search-master' and 'develop' of https:…
nbradbury May 19, 2016
3bbf7b6
Merge branch 'feature/reader-search-master' of https://github.com/wor…
nbradbury May 19, 2016
19c9235
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 20, 2016
84a5048
Merge branch 'feature/reader-search-master' of https://github.com/wor…
nbradbury May 20, 2016
6c572bc
Don't repopulate search suggestions unless the filter has changed
nbradbury May 23, 2016
605a49f
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 23, 2016
0cc5bd2
Merge branch 'feature/reader-search-master' of https://github.com/wor…
nbradbury May 23, 2016
b64f2a8
Ensure `filter` isn't null
nbradbury May 23, 2016
b2d7c07
Merge pull request #4096 from wordpress-mobile/feature/reader-search-…
mzorz May 23, 2016
b367a6c
Merge branches 'feature/reader-search-master' and 'develop' of https:…
nbradbury May 24, 2016
57d0602
Force the searchView to take up the full width
nbradbury May 26, 2016
c407f06
Rename reader menu items to avoid possible conflict
nbradbury May 26, 2016
a6a7c1a
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 27, 2016
18d00be
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury May 31, 2016
367ac8b
Merge branch 'feature/reader-search-master' of https://github.com/wor…
nbradbury May 31, 2016
ae01b4a
Resolve conflicts
nbradbury May 31, 2016
c8df06c
Remove deleting individual items
nbradbury May 31, 2016
00656c9
Removed icon
nbradbury May 31, 2016
ad300b6
Use frame layout for suggestions
nbradbury May 31, 2016
312bfab
Removed deleteQueryString (unused)
nbradbury May 31, 2016
304e6b5
Trim the query string
nbradbury Jun 1, 2016
81effce
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 1, 2016
a8e156d
Handle null query
nbradbury Jun 1, 2016
d771a4e
Merge branches 'feature/reader-clear-suggestions' and 'feature/reader…
nbradbury Jun 1, 2016
87c2fa0
Don't resubmit the same query
nbradbury Jun 1, 2016
73c4cb9
Create the "clear" row in the adapter's constructor rather than each …
nbradbury Jun 1, 2016
9bba89c
Use the new `ResourceUtils.getColorResource`
nbradbury Jun 1, 2016
e41881f
Merge pull request #4144 from wordpress-mobile/feature/reader-clear-s…
tonyr59h Jun 1, 2016
5ce7c80
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 2, 2016
17916b6
Resolved conflicts
nbradbury Jun 2, 2016
54ca6f6
Changed timestamp to sortOrder in ReaderPost model
nbradbury Jun 2, 2016
23b001f
Changed timestamp to sort_order in post table
nbradbury Jun 2, 2016
03d3e2b
Renamed sortOrder to sortIndex (made more sense when used as gap mark…
nbradbury Jun 2, 2016
a72950b
Merge pull request #4160 from wordpress-mobile/issue/4119-reader-sort…
mzorz Jun 2, 2016
94d72e2
First pass at search analytics
nbradbury Jun 2, 2016
628a333
Merge branch 'feature/reader-search-master' of https://github.com/wor…
nbradbury Jun 2, 2016
e4f0335
Use a different view type for the "clear" row so it doesn't get recyc…
nbradbury Jun 2, 2016
ab1e929
To match the web app, renamed READER_SEARCH_RESULTS_LOADED to READER_…
nbradbury Jun 2, 2016
46aa864
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 2, 2016
961772c
Merge pull request #4162 from wordpress-mobile/issue/reader-search-cl…
tonyr59h Jun 2, 2016
9a34671
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 5, 2016
aa4a6e3
Add back the ability to delete individual items
nbradbury Jun 5, 2016
c5d2664
Changed "Clear" to "Clear search history"
nbradbury Jun 5, 2016
99d5868
Changed search hint to "Search WordPress.com"
nbradbury Jun 5, 2016
f788bb4
Limit suggestion to single line
nbradbury Jun 5, 2016
de89715
Simplified clear history dialog
nbradbury Jun 5, 2016
9ee388a
Change empty string to "No posts found"
nbradbury Jun 5, 2016
bf08137
Use HTML <em> for search query in empty message
nbradbury Jun 5, 2016
5f9239d
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 6, 2016
6aa28a8
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 7, 2016
729a8a5
Capitalize words in the MP event name
nbradbury Jun 7, 2016
40a6c2b
Merge pull request #4163 from wordpress-mobile/issue/4105-reader-sear…
maxme Jun 7, 2016
9858a30
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 8, 2016
c21edf2
Use gridicon SVG for search icon
nbradbury Jun 9, 2016
dec08e6
Use gridicon SVG for settings icon
nbradbury Jun 9, 2016
3f96b1f
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 10, 2016
b656433
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 14, 2016
3390ab0
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 15, 2016
8f6ebbc
Disable swipe-to-refresh for reader search results
nbradbury Jun 15, 2016
392a61d
Merge pull request #4238 from wordpress-mobile/issue/4237-reader-sear…
theck13 Jun 15, 2016
00126e4
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 20, 2016
a6de3d6
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 21, 2016
30b7d42
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPre…
nbradbury Jun 22, 2016
4ea5bab
Merge branch 'develop' into feature/reader-search-master
maxme Jun 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@
<activity
android:name=".ui.reader.ReaderPostListActivity"
android:label="@string/reader"
android:theme="@style/Calypso.NoActionBar" />
android:theme="@style/Calypso.NoActionBar">
</activity>
<activity
android:name=".ui.reader.ReaderPostPagerActivity"
android:label="@string/reader_title_post_detail"
Expand Down Expand Up @@ -398,6 +399,10 @@
android:name=".ui.reader.services.ReaderPostService"
android:exported="false"
android:label="Reader Post Service" />
<service
android:name=".ui.reader.services.ReaderSearchService"
android:exported="false"
android:label="Reader Search Service" />
<service
android:name=".ui.reader.services.ReaderCommentService"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class ReaderDatabase extends SQLiteOpenHelper {
protected static final String DB_NAME = "wpreader.db";
private static final int DB_VERSION = 115;
private static final int DB_VERSION = 119;

/*
* version history
Expand Down Expand Up @@ -66,7 +66,11 @@ public class ReaderDatabase extends SQLiteOpenHelper {
* 112 - no structural change, just reset db
* 113 - added tag_title to tag tables
* 114 - renamed tag_name to tag_slug in tag tables
* 115 - added tag_display_name to tag tables
* 115 - added ReaderSearchTable
* 116 - added tag_display_name to tag tables
* 117 - changed tbl_posts.timestamp from INTEGER to REAL
* 118 - renamed tbl_search_history to tbl_search_suggestions
* 119 - renamed tbl_posts.timestamp to sort_index
*/

/*
Expand Down Expand Up @@ -142,6 +146,7 @@ private void createAllTables(SQLiteDatabase db) {
ReaderUserTable.createTables(db);
ReaderThumbnailTable.createTables(db);
ReaderBlogTable.createTables(db);
ReaderSearchTable.createTables(db);
}

private void dropAllTables(SQLiteDatabase db) {
Expand All @@ -152,6 +157,7 @@ private void dropAllTables(SQLiteDatabase db) {
ReaderUserTable.dropTables(db);
ReaderThumbnailTable.dropTables(db);
ReaderBlogTable.dropTables(db);
ReaderSearchTable.dropTables(db);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ReaderPostTable {
+ "featured_image," // 16
+ "featured_video," // 17
+ "post_avatar," // 18
+ "timestamp," // 19
+ "sort_index," // 19 - this is a score for search results, otherwise it's a timestamp
+ "published," // 20
+ "num_replies," // 21
+ "num_likes," // 22
Expand Down Expand Up @@ -83,7 +83,7 @@ public class ReaderPostTable {
+ "tbl_posts.url," // 15
+ "tbl_posts.short_url," // 16
+ "tbl_posts.post_avatar," // 17
+ "tbl_posts.timestamp," // 18
+ "tbl_posts.sort_index," // 18
+ "tbl_posts.published," // 19
+ "tbl_posts.num_replies," // 20
+ "tbl_posts.num_likes," // 21
Expand Down Expand Up @@ -122,7 +122,7 @@ protected static void createTables(SQLiteDatabase db) {
+ " featured_image TEXT,"
+ " featured_video TEXT,"
+ " post_avatar TEXT,"
+ " timestamp INTEGER DEFAULT 0,"
+ " sort_index REAL DEFAULT 0,"
+ " published TEXT,"
+ " num_replies INTEGER DEFAULT 0,"
+ " num_likes INTEGER DEFAULT 0,"
Expand All @@ -142,7 +142,7 @@ protected static void createTables(SQLiteDatabase db) {
+ " xpost_blog_id INTEGER DEFAULT 0,"
+ " PRIMARY KEY (post_id, blog_id)"
+ ")");
db.execSQL("CREATE INDEX idx_posts_timestamp ON tbl_posts(timestamp)");
db.execSQL("CREATE INDEX idx_posts_sort_index ON tbl_posts(sort_index)");

db.execSQL("CREATE TABLE tbl_post_tags ("
+ " post_id INTEGER DEFAULT 0,"
Expand Down Expand Up @@ -180,6 +180,9 @@ protected static int purge(SQLiteDatabase db) {
numDeleted += purgePostsForTag(db, tag);
}

// delete search results
numDeleted += purgeSearchResults(db);

// delete posts in tbl_posts that no longer exist in tbl_post_tags
numDeleted += db.delete("tbl_posts", "pseudo_id NOT IN (SELECT DISTINCT pseudo_id FROM tbl_post_tags)", null);

Expand All @@ -203,14 +206,22 @@ private static int purgePostsForTag(SQLiteDatabase db, ReaderTag tag) {
+ " WHERE tbl_posts.pseudo_id = tbl_post_tags.pseudo_id"
+ " AND tbl_post_tags.tag_name=?"
+ " AND tbl_post_tags.tag_type=?"
+ " ORDER BY tbl_posts.timestamp"
+ " ORDER BY tbl_posts.sort_index"
+ " LIMIT ?"
+ ")";
int numDeleted = db.delete("tbl_post_tags", where, args);
AppLog.d(AppLog.T.READER, String.format("reader post table > purged %d posts in tag %s", numDeleted, tag.getTagNameForLog()));
return numDeleted;
}

/*
* purge all posts that were retained from previous searches
*/
private static int purgeSearchResults(SQLiteDatabase db) {
String[] args = {Integer.toString(ReaderTagType.SEARCH.toInt())};
return db.delete("tbl_post_tags", "tag_type=?", args);
}

public static int getNumPostsInBlog(long blogId) {
if (blogId == 0) {
return 0;
Expand Down Expand Up @@ -455,7 +466,7 @@ public static void removeGapMarkerForTag(final ReaderTag tag) {
/*
* returns the blogId/postId of the post with the passed tag that has a gap marker, or null if none exists
*/
public static ReaderBlogIdPostId getGapMarkerForTag(final ReaderTag tag) {
public static ReaderBlogIdPostId getGapMarkerIdsForTag(final ReaderTag tag) {
if (tag == null) {
return null;
}
Expand Down Expand Up @@ -490,7 +501,7 @@ public static void setGapMarkerForTag(long blogId, long postId, ReaderTag tag) {
}

public static String getGapMarkerPubDateForTag(ReaderTag tag) {
ReaderBlogIdPostId ids = getGapMarkerForTag(tag);
ReaderBlogIdPostId ids = getGapMarkerIdsForTag(tag);
if (ids == null) {
return null;
}
Expand All @@ -499,29 +510,29 @@ public static String getGapMarkerPubDateForTag(ReaderTag tag) {
return SqlUtils.stringForQuery(ReaderDatabase.getReadableDb(), sql, args);
}

private static long getGapMarkerTimestampForTag(ReaderTag tag) {
ReaderBlogIdPostId ids = getGapMarkerForTag(tag);
private static long getGapMarkerSortIndexForTag(ReaderTag tag) {
ReaderBlogIdPostId ids = getGapMarkerIdsForTag(tag);
if (ids == null) {
return 0;
}

String[] args = {Long.toString(ids.getBlogId()), Long.toString(ids.getPostId())};
String sql = "SELECT timestamp FROM tbl_posts WHERE blog_id=? AND post_id=?";
String sql = "SELECT sort_index FROM tbl_posts WHERE blog_id=? AND post_id=?";
return SqlUtils.longForQuery(ReaderDatabase.getReadableDb(), sql, args);
}

/*
* delete posts with the passed tag that are older than one with the gap marker for
* delete posts with the passed tag that come before the one with the gap marker for
* this tag - note this may leave some stray posts in tbl_posts, but these will
* be cleaned up by the next purge
*/
public static void deletePostsOlderThanGapMarkerForTag(ReaderTag tag) {
long timestamp = getGapMarkerTimestampForTag(tag);
if (timestamp == 0) return;
public static void deletePostsBeforeGapMarkerForTag(ReaderTag tag) {
long sortIndex = getGapMarkerSortIndexForTag(tag);
if (sortIndex == 0) return;

String[] args = {Long.toString(timestamp), tag.getTagSlug(), Integer.toString(tag.tagType.toInt())};
String[] args = {Long.toString(sortIndex), tag.getTagSlug(), Integer.toString(tag.tagType.toInt())};
String where = "pseudo_id IN (SELECT tbl_posts.pseudo_id FROM tbl_posts, tbl_post_tags"
+ " WHERE tbl_posts.timestamp < ?"
+ " WHERE tbl_posts.sort_index < ?"
+ " AND tbl_posts.pseudo_id = tbl_post_tags.pseudo_id"
+ " AND tbl_post_tags.tag_name=? AND tbl_post_tags.tag_type=?)";
int numDeleted = ReaderDatabase.getWritableDb().delete("tbl_post_tags", where, args);
Expand Down Expand Up @@ -632,7 +643,7 @@ public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
stmtPosts.bindString(16, post.getFeaturedImage());
stmtPosts.bindString(17, post.getFeaturedVideo());
stmtPosts.bindString(18, post.getPostAvatar());
stmtPosts.bindLong (19, post.timestamp);
stmtPosts.bindDouble(19, post.sortIndex);
stmtPosts.bindString(20, post.getPublished());
stmtPosts.bindLong (21, post.numReplies);
stmtPosts.bindLong (22, post.numLikes);
Expand Down Expand Up @@ -699,7 +710,7 @@ public static ReaderPostList getPostsWithTag(ReaderTag tag, int maxPosts, boolea
}
}

sql += " ORDER BY tbl_posts.timestamp DESC";
sql += " ORDER BY tbl_posts.sort_index DESC";

if (maxPosts > 0) {
sql += " LIMIT " + Integer.toString(maxPosts);
Expand All @@ -716,7 +727,7 @@ public static ReaderPostList getPostsWithTag(ReaderTag tag, int maxPosts, boolea

public static ReaderPostList getPostsInBlog(long blogId, int maxPosts, boolean excludeTextColumn) {
String columns = (excludeTextColumn ? COLUMN_NAMES_NO_TEXT : "tbl_posts.*");
String sql = "SELECT " + columns + " FROM tbl_posts WHERE blog_id = ? ORDER BY tbl_posts.timestamp DESC";
String sql = "SELECT " + columns + " FROM tbl_posts WHERE blog_id = ? ORDER BY tbl_posts.sort_index DESC";

if (maxPosts > 0) {
sql += " LIMIT " + Integer.toString(maxPosts);
Expand All @@ -732,7 +743,7 @@ public static ReaderPostList getPostsInBlog(long blogId, int maxPosts, boolean e

public static ReaderPostList getPostsInFeed(long feedId, int maxPosts, boolean excludeTextColumn) {
String columns = (excludeTextColumn ? COLUMN_NAMES_NO_TEXT : "tbl_posts.*");
String sql = "SELECT " + columns + " FROM tbl_posts WHERE feed_id = ? ORDER BY tbl_posts.timestamp DESC";
String sql = "SELECT " + columns + " FROM tbl_posts WHERE feed_id = ? ORDER BY tbl_posts.sort_index DESC";

if (maxPosts > 0) {
sql += " LIMIT " + Integer.toString(maxPosts);
Expand Down Expand Up @@ -769,7 +780,7 @@ public static ReaderBlogIdPostIdList getBlogIdPostIdsWithTag(ReaderTag tag, int
}
}

sql += " ORDER BY tbl_posts.timestamp DESC";
sql += " ORDER BY tbl_posts.sort_index DESC";

if (maxPosts > 0) {
sql += " LIMIT " + Integer.toString(maxPosts);
Expand All @@ -793,7 +804,7 @@ public static ReaderBlogIdPostIdList getBlogIdPostIdsWithTag(ReaderTag tag, int
* same as getPostsInBlog() but only returns the blogId/postId pairs
*/
public static ReaderBlogIdPostIdList getBlogIdPostIdsInBlog(long blogId, int maxPosts) {
String sql = "SELECT post_id FROM tbl_posts WHERE blog_id = ? ORDER BY tbl_posts.timestamp DESC";
String sql = "SELECT post_id FROM tbl_posts WHERE blog_id = ? ORDER BY tbl_posts.sort_index DESC";

if (maxPosts > 0) {
sql += " LIMIT " + Integer.toString(maxPosts);
Expand Down Expand Up @@ -847,7 +858,7 @@ private static ReaderPost getPostFromCursor(Cursor c) {
post.setShortUrl(c.getString(c.getColumnIndex("short_url")));
post.setPostAvatar(c.getString(c.getColumnIndex("post_avatar")));

post.timestamp = c.getLong(c.getColumnIndex("timestamp"));
post.sortIndex = c.getDouble(c.getColumnIndex("sort_index"));
post.setPublished(c.getString(c.getColumnIndex("published")));

post.numReplies = c.getInt(c.getColumnIndex("num_replies"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.wordpress.android.datasets;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import org.wordpress.android.util.DateTimeUtils;
import org.wordpress.android.util.SqlUtils;

import java.util.Date;

/**
* search suggestion table - populated by user's reader search history
*/
public class ReaderSearchTable {

public static final String COL_ID = "_id";
public static final String COL_QUERY = "query_string";

protected static void createTables(SQLiteDatabase db) {
db.execSQL("CREATE TABLE tbl_search_suggestions ("
+ " _id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ " query_string TEXT NOT NULL COLLATE NOCASE,"
+ " date_used TEXT)");
db.execSQL("CREATE UNIQUE INDEX idx_search_suggestions_query ON tbl_search_suggestions(query_string)");
}

protected static void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS tbl_search_suggestions");
}

/*
* adds the passed query string, updating the usage date
*/
public static void addOrUpdateQueryString(@NonNull String query) {
String date = DateTimeUtils.javaDateToIso8601(new Date());

SQLiteStatement stmt = ReaderDatabase.getWritableDb().compileStatement(
"INSERT OR REPLACE INTO tbl_search_suggestions (query_string, date_used) VALUES (?1,?2)");
try {
stmt.bindString(1, query);
stmt.bindString(2, date);
stmt.execute();
} finally {
SqlUtils.closeStatement(stmt);
}
}

public static void deleteQueryString(@NonNull String query) {
String[]args = new String[]{query};
ReaderDatabase.getWritableDb().delete("tbl_search_suggestions", "query_string=?", args);
}

public static void deleteAllQueries() {
SqlUtils.deleteAllRowsInTable(ReaderDatabase.getWritableDb(), "tbl_search_suggestions");
}

/**
* Returns a cursor containing query strings previously typed by the user
* @param filter - filters the list using LIKE syntax (pass null for no filter)
* @param max - limit the list to this many items (pass zero for no limit)
*/
public static Cursor getQueryStringCursor(String filter, int max) {
String sql;
String[] args;
if (TextUtils.isEmpty(filter)) {
sql = "SELECT * FROM tbl_search_suggestions";
args = null;
} else {
sql = "SELECT * FROM tbl_search_suggestions WHERE query_string LIKE ?";
args = new String[]{filter + "%"};
}

sql += " ORDER BY date_used DESC";

if (max > 0) {
sql += " LIMIT " + max;
}

return ReaderDatabase.getReadableDb().rawQuery(sql, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ReaderPost {
private String primaryTag; // most popular tag on this post based on usage in blog
private String secondaryTag; // second most popular tag on this post based on usage in blog

public long timestamp; // used for sorting
public double sortIndex;
private String published;

private String url;
Expand Down Expand Up @@ -116,14 +116,15 @@ public static ReaderPost fromJson(JSONObject json) {
post.blogName = JSONUtils.getStringDecoded(json, "site_name");
post.published = JSONUtils.getString(json, "date");

// the date a post was liked is only returned by the read/liked/ endpoint - if this exists,
// set it as the timestamp so posts are sorted by the date they were liked rather than the
// date they were published (the timestamp is used to sort posts when querying)
String likeDate = JSONUtils.getString(json, "date_liked");
if (!TextUtils.isEmpty(likeDate)) {
post.timestamp = DateTimeUtils.iso8601ToTimestamp(likeDate);
// sort index determines how posts are sorted - this is a "score" for search results,
// liked date for liked posts, and published date for all others
if (json.has("score")) {
post.sortIndex = json.optDouble("score");
} else if (json.has("date_liked")) {
String likeDate = JSONUtils.getString(json, "date_liked");
post.sortIndex = DateTimeUtils.iso8601ToTimestamp(likeDate);
} else {
post.timestamp = DateTimeUtils.iso8601ToTimestamp(post.published);
post.sortIndex = DateTimeUtils.iso8601ToTimestamp(post.published);
}

// if the post is untitled, make up a title from the excerpt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static boolean isSameTag(ReaderTag tag1, ReaderTag tag2) {
public boolean isPostsILike() {
return tagType == ReaderTagType.DEFAULT && getEndpoint().endsWith("/read/liked");
}

public boolean isFollowedSites() {
return tagType == ReaderTagType.DEFAULT && getEndpoint().endsWith("/read/following");
}
Expand Down
Loading