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