diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-29 20:05:34 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-29 20:05:34 +0300 |
commit | a49f0d053e238754d6dd0327b155cb94513f69f1 (patch) | |
tree | 26f4bf01a5f893b9ff40565977d53e84bd0ef3d3 /app/src/main/java/it | |
parent | de4f94a96da4985332e059f6319380890480f5f9 (diff) |
Fix unit tests
Diffstat (limited to 'app/src/main/java/it')
4 files changed, 34 insertions, 20 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index 67e9f921..16e1004b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -37,7 +37,6 @@ import java.util.List; import java.util.Map; import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData; -import it.niedermann.android.sharedpreferences.SharedPreferenceStringLiveData; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.persistence.dao.AccountDao; @@ -461,7 +460,7 @@ public abstract class NotesDatabase extends RoomDatabase { new Thread(() -> { final Context ctx = context.getApplicationContext(); final SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(ctx).edit(); - int orderIndex = sortingMethod.getCSMID(); + int orderIndex = sortingMethod.getId(); switch (selectedCategory.getType()) { case FAVORITES: { @@ -542,7 +541,7 @@ public abstract class NotesDatabase extends RoomDatabase { } } - return map(new SharedPreferenceIntLiveData(sp, prefKey, CategorySortingMethod.SORT_MODIFIED_DESC.getCSMID()), CategorySortingMethod::getCSM); + return map(new SharedPreferenceIntLiveData(sp, prefKey, CategorySortingMethod.SORT_MODIFIED_DESC.getId()), CategorySortingMethod::findById); } public Context getContext() { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java index 42d1e881..1984df40 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java @@ -1,5 +1,6 @@ package it.niedermann.owncloud.notes.persistence.entity; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.room.TypeConverter; @@ -26,13 +27,15 @@ public class Converters { } @TypeConverter - public static CategorySortingMethod categorySortingMethodFromString(Integer value) { - return value == null ? CategorySortingMethod.SORT_MODIFIED_DESC : CategorySortingMethod.getCSM(value); + @NonNull + public static CategorySortingMethod categorySortingMethodFromString(@Nullable Integer value) { + return value == null ? CategorySortingMethod.SORT_MODIFIED_DESC : CategorySortingMethod.findById(value); } @TypeConverter - public static Integer dbStatusToString(CategorySortingMethod categorySortingMethod) { - return categorySortingMethod == null ? null : categorySortingMethod.getCSMID(); + @Nullable + public static Integer dbStatusToString(@Nullable CategorySortingMethod categorySortingMethod) { + return categorySortingMethod == null ? null : categorySortingMethod.getId(); } @TypeConverter diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java index 48ddd9eb..36630d8d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java @@ -26,13 +26,16 @@ public final class Migration_19_20 extends Migration { @Override public void migrate(@NonNull SupportSQLiteDatabase db) { dropOldIndices(db); + createNewTables(db); createNewIndices(db); + migrateAccounts(db); migrateCategories(db); migrateNotes(db); migrateNotesListWidgets(db); migrateSingleNotesWidgets(db); + dropOldTables(db); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java index 6191bb9e..ecbd4eeb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java @@ -1,41 +1,50 @@ package it.niedermann.owncloud.notes.shared.model; +import java.util.NoSuchElementException; + public enum CategorySortingMethod { - SORT_MODIFIED_DESC("MODIFIED DESC"), - SORT_LEXICOGRAPHICAL_ASC("TITLE COLLATE NOCASE ASC"); + SORT_MODIFIED_DESC(0, "MODIFIED DESC"), + SORT_LEXICOGRAPHICAL_ASC(1, "TITLE COLLATE NOCASE ASC"); - private final String sorder; // sorting method OrderBy for SQL + private final int id; + private final String title; // sorting method OrderBy for SQL /*** * Constructor - * @param orderby given sorting method OrderBy + * @param title given sorting method OrderBy */ - CategorySortingMethod(String orderby) { - this.sorder = orderby; + CategorySortingMethod(int id, String title) { + this.id = id; + this.title = title; } /*** * Retrieve the sorting method id represented in database * @return the sorting method id for the enum item */ - public int getCSMID() { - return this.ordinal(); + public int getId() { + return this.id; } /*** * Retrieve the sorting method order for SQL * @return the sorting method order for the enum item */ - public String getSorder() { - return this.sorder; + public String getTitle() { + return this.title; } /*** * Retrieve the corresponding enum value with given the index (ordinal) - * @param index the index / ordinal of the corresponding enum value stored in DB + * @param id the id of the corresponding enum value stored in DB * @return the corresponding enum item with the index (ordinal) */ - public static CategorySortingMethod getCSM(int index) { - return CategorySortingMethod.values()[index]; + public static CategorySortingMethod findById(int id) { + for(CategorySortingMethod csm : values()) { + if(csm.getId() == id) { + return csm; + } + } + return SORT_MODIFIED_DESC; } } |