Browse Source

Add sorting back to bookmarks

master
anthony restaino 8 years ago
parent
commit
f34ac1b255
  1. 2
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  2. 10
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java
  3. 4
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java
  4. 4
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

2
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -117,7 +117,7 @@ public final class BookmarkPage { @@ -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) {

10
app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java

@ -18,6 +18,7 @@ import com.anthonycr.bonsai.SingleAction; @@ -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 @@ -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 @@ -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 @@ -350,6 +353,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
cursor.close();
Collections.sort(folders);
subscriber.onItem(folders);
subscriber.onComplete();
}

4
app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java

@ -132,7 +132,7 @@ public interface BookmarkModel { @@ -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 { @@ -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.

4
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -254,7 +254,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -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, @@ -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…
Cancel
Save