Add sorting back to bookmarks
This commit is contained in:
parent
e794171b8d
commit
f34ac1b255
@ -117,7 +117,7 @@ public final class BookmarkPage {
|
||||
}
|
||||
|
||||
private void buildBookmarkPage(@Nullable final String folder) {
|
||||
mManager.getBookmarksFromFolder(folder)
|
||||
mManager.getBookmarksFromFolderSorted(folder)
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onItem(@Nullable List<HistoryItem> list) {
|
||||
|
@ -18,6 +18,7 @@ import com.anthonycr.bonsai.SingleAction;
|
||||
import com.anthonycr.bonsai.SingleSubscriber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -311,14 +312,16 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Single<List<HistoryItem>> getBookmarksFromFolder(@Nullable final String folder) {
|
||||
public Single<List<HistoryItem>> getBookmarksFromFolderSorted(@Nullable final String folder) {
|
||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
|
||||
String finalFolder = folder != null ? folder : "";
|
||||
Cursor cursor = lazyDatabase().query(TABLE_BOOKMARK, null, KEY_FOLDER + "=?", new String[]{finalFolder}, null, null, null);
|
||||
|
||||
subscriber.onItem(bindCursorToHistoryItemList(cursor));
|
||||
List<HistoryItem> list = bindCursorToHistoryItemList(cursor);
|
||||
Collections.sort(list);
|
||||
subscriber.onItem(list);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
@ -326,7 +329,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Single<List<HistoryItem>> getFolders() {
|
||||
public Single<List<HistoryItem>> getFoldersSorted() {
|
||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull SingleSubscriber<List<HistoryItem>> subscriber) {
|
||||
@ -350,6 +353,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
|
||||
|
||||
cursor.close();
|
||||
|
||||
Collections.sort(folders);
|
||||
subscriber.onItem(folders);
|
||||
subscriber.onComplete();
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public interface BookmarkModel {
|
||||
* in the given folder.
|
||||
*/
|
||||
@NonNull
|
||||
Single<List<HistoryItem>> getBookmarksFromFolder(@Nullable String folder);
|
||||
Single<List<HistoryItem>> getBookmarksFromFolderSorted(@Nullable String folder);
|
||||
|
||||
/**
|
||||
* Returns all folders as {@link HistoryItem}.
|
||||
@ -141,7 +141,7 @@ public interface BookmarkModel {
|
||||
* @return an observable that emits a list of folders.
|
||||
*/
|
||||
@NonNull
|
||||
Single<List<HistoryItem>> getFolders();
|
||||
Single<List<HistoryItem>> getFoldersSorted();
|
||||
|
||||
/**
|
||||
* Returns the names of all folders.
|
||||
|
@ -254,7 +254,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
}
|
||||
|
||||
private void setBookmarksShown(@Nullable final String folder, final boolean animate) {
|
||||
mBookmarksSubscription = mBookmarkManager.getBookmarksFromFolder(folder)
|
||||
mBookmarksSubscription = mBookmarkManager.getBookmarksFromFolderSorted(folder)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
@ -265,7 +265,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
|
||||
mUiModel.setCurrentFolder(folder);
|
||||
if (folder == null) {
|
||||
mBookmarkManager.getFolders()
|
||||
mBookmarkManager.getFoldersSorted()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.main())
|
||||
.subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
|
||||
|
Loading…
Reference in New Issue
Block a user