Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public interface NoteDao {
* @param accountId The user account Id
* @return All of the categories with given accountId
*/
@Query("SELECT accountId, category, COUNT(*) as 'totalNotes' FROM NOTE WHERE STATUS != 'LOCAL_DELETED' AND accountId = :accountId GROUP BY category")
@Query("SELECT accountId, category, COUNT(*) as 'totalNotes' FROM NOTE WHERE STATUS != 'LOCAL_DELETED' AND accountId = :accountId GROUP BY category ORDER BY category = '', category")
LiveData<List<CategoryWithNotesCount>> getCategories$(Long accountId);

@Query("SELECT accountId, category, COUNT(*) as 'totalNotes' FROM NOTE WHERE STATUS != 'LOCAL_DELETED' AND accountId = :accountId AND category != '' AND category LIKE :searchTerm GROUP BY category")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.main.MainActivity;
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.persistence.NotesRepository;

Expand Down Expand Up @@ -54,10 +53,6 @@ public LiveData<List<NavigationItem>> getAdapterCategories(Long accountId) {
items.add(new NavigationItem(MainActivity.ADAPTER_KEY_RECENT, getApplication().getString(R.string.label_all_notes), count, R.drawable.selector_all_notes, RECENT));
items.add(new NavigationItem(MainActivity.ADAPTER_KEY_STARRED, getApplication().getString(R.string.label_favorites), favoritesCount, R.drawable.selector_favorites, FAVORITES));

if (categories.size() > 2 && categories.get(2).label.isEmpty()) {
items.add(new NavigationItem(MainActivity.ADAPTER_KEY_UNCATEGORIZED, "", null, NavigationAdapter.ICON_NOFOLDER));
}

for (final var item : categories) {
final int slashIndex = item.label.indexOf('/');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ public void getCategoriesLiveData() throws InterruptedException {
assertFalse(secondAccountCategories.stream().anyMatch(cat -> "日记".equals(cat.getCategory())));
}

@Test
public void getCategoriesSortsUncategorizedLast() throws InterruptedException {
db.getNoteDao().addNote(new Note(1, 1L, Calendar.getInstance(), "T", "C", "", false, null, VOID, account.getId(), "", 0));
db.getNoteDao().addNote(new Note(2, 2L, Calendar.getInstance(), "T", "C", "Zebra", false, null, VOID, account.getId(), "", 0));
db.getNoteDao().addNote(new Note(3, 3L, Calendar.getInstance(), "T", "C", "Apple", false, null, VOID, account.getId(), "", 0));

final var categories = NotesTestingUtil.getOrAwaitValue(db.getNoteDao().getCategories$(account.getId()));
assertEquals(List.of("Apple", "Zebra", ""), categories.stream().map(CategoryWithNotesCount::getCategory).toList());
}

@Test
public void searchCategories() throws InterruptedException {
final var secondAccount = setupSecondAccountAndTestNotes();
Expand Down
Loading