Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2020-10-06 13:17:31 +0300
committerStefan Niedermann <info@niedermann.it>2020-10-06 13:17:31 +0300
commit680a6b712102a60e9aef98cf0c51c38ef2086e21 (patch)
treeef87c45fbc887e18d862b0bb1dd95f70ab9eefa3
parent23a6958ed4b9f0faa7281aea48ba83b889e2d2c5 (diff)
#831 Migrate from SQLiteOpenHelper to Room
-rw-r--r--app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesNotesRoomDatabaseTest.java180
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java54
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java12
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java10
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java6
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java6
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java8
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java14
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java2
11 files changed, 149 insertions, 151 deletions
diff --git a/app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesNotesRoomDatabaseTest.java b/app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesNotesRoomDatabaseTest.java
index 44493fb1..71ab4b62 100644
--- a/app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesNotesRoomDatabaseTest.java
+++ b/app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesNotesRoomDatabaseTest.java
@@ -51,8 +51,7 @@ import static org.junit.Assert.fail;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class NotesNotesRoomDatabaseTest {
- private NotesDatabase sqliteOpenHelperDatabase = null;
- private NotesRoomDatabase roomDatabase = null;
+ private NotesRoomDatabase db = null;
private String accountURL = "HelloHowAreYou";
private String accountUserName = "John Doe";
@@ -62,23 +61,22 @@ public class NotesNotesRoomDatabaseTest {
@Before
public void setupDB() throws NextcloudHttpRequestFailedException {
Context context = ApplicationProvider.getApplicationContext();
- sqliteOpenHelperDatabase = NotesDatabase.getInstance(context);
- roomDatabase = NotesRoomDatabase.getInstance(context);
+ db = NotesRoomDatabase.getInstance(context);
// Create a new account if not exist
- account = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(accountName);
+ account = db.getLocalAccountDao().getLocalAccountByAccountName(accountName);
if (account == null) {
final String response = "{\"ocs\":{\"meta\":{\"status\":\"ok\",\"statuscode\":200,\"message\":\"OK\"},\"data\":{\"version\":{\"major\":18,\"minor\":0,\"micro\":4,\"string\":\"18.0.4\",\"edition\":\"\",\"extendedSupport\":false},\"capabilities\":{\"core\":{\"pollinterval\":60,\"webdav-root\":\"remote.php\\/webdav\"},\"bruteforce\":{\"delay\":0},\"files\":{\"bigfilechunking\":true,\"blacklisted_files\":[\".htaccess\"],\"directEditing\":{\"url\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/files\\/api\\/v1\\/directEditing\",\"etag\":\"ed2b141af2a39b0e42666952ba60988d\"},\"versioning\":true,\"undelete\":true},\"activity\":{\"apiv2\":[\"filters\",\"filters-api\",\"previews\",\"rich-strings\"]},\"ocm\":{\"enabled\":true,\"apiVersion\":\"1.0-proposal1\",\"endPoint\":\"https:\\/\\/efss.qloud.my\\/index.php\\/ocm\",\"resourceTypes\":[{\"name\":\"file\",\"shareTypes\":[\"user\",\"group\"],\"protocols\":{\"webdav\":\"\\/public.php\\/webdav\\/\"}}]},\"deck\":{\"version\":\"0.8.2\"},\"richdocuments\":{\"mimetypes\":[\"application\\/vnd.oasis.opendocument.text\",\"application\\/vnd.oasis.opendocument.spreadsheet\",\"application\\/vnd.oasis.opendocument.graphics\",\"application\\/vnd.oasis.opendocument.presentation\",\"application\\/vnd.lotus-wordpro\",\"application\\/vnd.visio\",\"application\\/vnd.wordperfect\",\"application\\/msonenote\",\"application\\/msword\",\"application\\/rtf\",\"text\\/rtf\",\"application\\/vnd.openxmlformats-officedocument.wordprocessingml.document\",\"application\\/vnd.openxmlformats-officedocument.wordprocessingml.template\",\"application\\/vnd.ms-word.document.macroEnabled.12\",\"application\\/vnd.ms-word.template.macroEnabled.12\",\"application\\/vnd.ms-excel\",\"application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\"application\\/vnd.openxmlformats-officedocument.spreadsheetml.template\",\"application\\/vnd.ms-excel.sheet.macroEnabled.12\",\"application\\/vnd.ms-excel.template.macroEnabled.12\",\"application\\/vnd.ms-excel.addin.macroEnabled.12\",\"application\\/vnd.ms-excel.sheet.binary.macroEnabled.12\",\"application\\/vnd.ms-powerpoint\",\"application\\/vnd.openxmlformats-officedocument.presentationml.presentation\",\"application\\/vnd.openxmlformats-officedocument.presentationml.template\",\"application\\/vnd.openxmlformats-officedocument.presentationml.slideshow\",\"application\\/vnd.ms-powerpoint.addin.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.presentation.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.template.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.slideshow.macroEnabled.12\",\"text\\/csv\"],\"mimetypesNoDefaultOpen\":[\"image\\/svg+xml\",\"application\\/pdf\",\"text\\/plain\",\"text\\/spreadsheet\"],\"collabora\":[],\"direct_editing\":false,\"templates\":false,\"productName\":\"\\u5728\\u7ebf\\u534f\\u4f5c\"},\"dav\":{\"chunking\":\"1.0\"},\"files_sharing\":{\"api_enabled\":true,\"public\":{\"enabled\":true,\"password\":{\"enforced\":true,\"askForOptionalPassword\":false},\"expire_date\":{\"enabled\":true,\"days\":\"7\",\"enforced\":false},\"multiple_links\":true,\"expire_date_internal\":{\"enabled\":false},\"send_mail\":false,\"upload\":true,\"upload_files_drop\":true},\"resharing\":true,\"user\":{\"send_mail\":false,\"expire_date\":{\"enabled\":true}},\"group_sharing\":true,\"group\":{\"enabled\":true,\"expire_date\":{\"enabled\":true}},\"default_permissions\":31,\"federation\":{\"outgoing\":false,\"incoming\":false,\"expire_date\":{\"enabled\":true}},\"sharee\":{\"query_lookup_default\":false},\"sharebymail\":{\"enabled\":true,\"upload_files_drop\":{\"enabled\":true},\"password\":{\"enabled\":true},\"expire_date\":{\"enabled\":true}}},\"external\":{\"v1\":[\"sites\",\"device\",\"groups\",\"redirect\"]},\"notifications\":{\"ocs-endpoints\":[\"list\",\"get\",\"delete\",\"delete-all\",\"icons\",\"rich-strings\",\"action-web\"],\"push\":[\"devices\",\"object-data\",\"delete\"],\"admin-notifications\":[\"ocs\",\"cli\"]},\"password_policy\":{\"minLength\":8,\"enforceNonCommonPassword\":true,\"enforceNumericCharacters\":false,\"enforceSpecialCharacters\":false,\"enforceUpperLowerCase\":false,\"api\":{\"generate\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/password_policy\\/api\\/v1\\/generate\",\"validate\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/password_policy\\/api\\/v1\\/validate\"}},\"theming\":{\"name\":\"QloudData\",\"url\":\"https:\\/\\/www.qloud.my\\/qloud-data\\/\",\"slogan\":\"Powered by NextCloud\",\"color\":\"#1E4164\",\"color-text\":\"#ffffff\",\"color-element\":\"#1E4164\",\"logo\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\",\"background\":\"https:\\/\\/efss.qloud.my\\/core\\/img\\/background.png?v=47\",\"background-plain\":false,\"background-default\":true,\"logoheader\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\",\"favicon\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\"},\"registration\":{\"enabled\":true,\"apiRoot\":\"\\/ocs\\/v2.php\\/apps\\/registration\\/api\\/v1\\/\",\"apiLevel\":\"v1\"}}}}}";
Capabilities capabilities = new Capabilities(response, null);
assertNotNull(capabilities);
- roomDatabase.addAccount(accountURL, accountUserName, accountName, capabilities);
- account = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(accountName);
+ db.addAccount(accountURL, accountUserName, accountName, capabilities);
+ account = db.getLocalAccountDao().getLocalAccountByAccountName(accountName);
}
}
@Test
public void testSetUpEnv() {
- Log.i("Test_DB_Instance", sqliteOpenHelperDatabase.toString());
- List<LocalAccountEntity> accounts = roomDatabase.getLocalAccountDao().getAccounts();
+ Log.i("Test_DB_Instance", db.toString());
+ List<LocalAccountEntity> accounts = db.getLocalAccountDao().getAccounts();
for (LocalAccountEntity account : accounts) {
Log.i("Test_Get_Accounts", account.toString());
}
@@ -93,14 +91,14 @@ public class NotesNotesRoomDatabaseTest {
true, "Diary", null);
// Pre-check
- List<NoteEntity> notes = roomDatabase.getNoteDao().getNotes(accountID);
+ List<NoteEntity> notes = db.getNoteDao().getNotes(accountID);
int pre_size = notes.size();
Log.i("Test_01_addNote_All_Notes_Before_Addition", "Size: " + pre_size);
// Add a new note
- long noteID = roomDatabase.addNote(accountID, cloudNote);
+ long noteID = db.addNote(accountID, cloudNote);
// Check if this note is added successfully
- NoteEntity note = roomDatabase.getNoteDao().getNote(accountID, noteID);
+ NoteEntity note = db.getNoteDao().getNote(accountID, noteID);
Log.i("Test_01_addNote_Cur_Note", note.toString());
Log.i("Test_01_addNote_Cur_Note", "Title: " + note.getTitle());
Log.i("Test_01_addNote_Cur_Note", "Content: " + note.getContent());
@@ -109,10 +107,10 @@ public class NotesNotesRoomDatabaseTest {
assertEquals("A Great Day", note.getTitle());
assertEquals(cloudNote.getContent(), note.getContent());
assertEquals("Diary", note.getCategory());
- assertEquals(accountID, note.getAccountId());
+ assertEquals(accountID, note.getAccountId().longValue());
// Check if this note is in all notes
- notes = roomDatabase.getNoteDao().getNotes(accountID);
+ notes = db.getNoteDao().getNotes(accountID);
int added_size = notes.size();
assertEquals(1, added_size - pre_size);
@@ -125,13 +123,13 @@ public class NotesNotesRoomDatabaseTest {
NoteEntity cloudNote_re0 = new NoteEntity(0, Calendar.getInstance(),
"A Bad Day", getCurDate() + " You're faking a smile with just a coffee to go (Daniel Powter).",
true, "A Nice Song", null);
- noteID = roomDatabase.addNote(accountID, cloudNote_re0);
- note = roomDatabase.getNoteDao().getNote(accountID, noteID);
+ noteID = db.addNote(accountID, cloudNote_re0);
+ note = db.getNoteDao().getNote(accountID, noteID);
// Check
assertEquals("A Bad Day", note.getTitle());
assertEquals(cloudNote_re0.getContent(), note.getContent());
assertEquals("A Nice Song", note.getCategory());
- assertEquals(accountID, note.getAccountId());
+ assertEquals(accountID, note.getAccountId().longValue());
}
@Test
@@ -141,10 +139,10 @@ public class NotesNotesRoomDatabaseTest {
// get a new note id to avoid UNIQUE Note_ID constraint
// getNotesCustom also tested here
- Method getNC = NotesDatabase.class.getDeclaredMethod("getNotesCustom", long.class, String.class, String[].class, String.class, boolean.class);
+ Method getNC = NotesRoomDatabase.class.getDeclaredMethod("getNotesCustom", long.class, String.class, String[].class, String.class, boolean.class);
getNC.setAccessible(true);
- List<NoteEntity> notes = (List<NoteEntity>) getNC.invoke(sqliteOpenHelperDatabase, accountID, NotesDatabase.key_status + " != ? AND " + NotesDatabase.key_account_id + " = ?",
- new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountID}, NotesDatabase.key_id + " ASC", false);
+ List<NoteEntity> notes = (List<NoteEntity>) getNC.invoke(db, accountID, "status != ? AND accountId = ?",
+ new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountID}, "id ASC", false);
long newNoteID = notes.get(notes.size() - 1).getId() + 1; // avoid UNIQUE Note_ID constraint
// Create a DBNote for argument passing
@@ -154,9 +152,9 @@ public class NotesNotesRoomDatabaseTest {
accountID, NoteUtil.generateNoteExcerpt(newContent, "Test-Title"), 0);
// Add a new note
- long noteID = roomDatabase.addNote(accountID, dbNote);
+ long noteID = db.addNote(accountID, dbNote);
// Check if this note is added successfully
- NoteEntity note = roomDatabase.getNoteDao().getNote(accountID, noteID);
+ NoteEntity note = db.getNoteDao().getNote(accountID, noteID);
assertEquals(dbNote.getTitle(), note.getTitle());
assertEquals(dbNote.getContent(), note.getContent());
assertEquals(dbNote.getCategory(), note.getCategory());
@@ -168,19 +166,19 @@ public class NotesNotesRoomDatabaseTest {
newContent, true, "Sincere Friend's Record", null, DBStatus.VOID,
accountID, NoteUtil.generateNoteExcerpt(newContent, "Test-Title"), 0);
// Add a new note
- noteID = roomDatabase.addNote(accountID, dbNote);
+ noteID = db.addNote(accountID, dbNote);
// Check if this note is added successfully
- note = roomDatabase.getNoteDao().getNote(accountID, noteID);
+ note = db.getNoteDao().getNote(accountID, noteID);
assertEquals(dbNote.getTitle(), note.getTitle());
assertEquals(dbNote.getContent(), note.getContent());
assertEquals(dbNote.getCategory(), note.getCategory());
assertEquals(dbNote.getAccountId(), note.getAccountId());
// Test the rest case of getNotesCustom - ORDER BY ~ null, LIMIT ~ not null
- Method getNCWOW = NotesDatabase.class.getDeclaredMethod("getNotesCustom", long.class, String.class, String[].class, String.class, String.class, boolean.class);
+ Method getNCWOW = NotesRoomDatabase.class.getDeclaredMethod("getNotesCustom", long.class, String.class, String[].class, String.class, String.class, boolean.class);
getNCWOW.setAccessible(true);
int aSize = 1;
- notes = (List<NoteEntity>) getNCWOW.invoke(sqliteOpenHelperDatabase, accountID, NotesDatabase.key_status + " != ? AND " + NotesDatabase.key_account_id + " = ?",
+ notes = (List<NoteEntity>) getNCWOW.invoke(db, accountID, " status != ? AND accountId = ?",
new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountID}, null, String.valueOf(aSize), false);
assertEquals(aSize, notes.size());
} catch (Exception e) {
@@ -192,26 +190,26 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_03_searchNotes() {
long thisAccountID = account.getId();
- List<NoteEntity> notes = roomDatabase.searchNotes(thisAccountID, null, null, false, null); // All three added notes are marked as favorite
+ List<NoteEntity> notes = db.searchNotes(thisAccountID, null, null, false, null); // All three added notes are marked as favorite
Log.i("Test_03_searchNotes_Favorite_false", "Size: " + notes.size());
assertEquals(notes.size(), 0);
- notes = roomDatabase.searchNotes(thisAccountID, null, "Hello", true, null); // There is no category named "Hello"
+ notes = db.searchNotes(thisAccountID, null, "Hello", true, null); // There is no category named "Hello"
Log.i("Test_03_searchNotes_Category_Hello", "Size: " + notes.size());
assertEquals(notes.size(), 0);
- notes = roomDatabase.searchNotes(thisAccountID, null, "Diary", true, null); // There is one category named "Diary"
+ notes = db.searchNotes(thisAccountID, null, "Diary", true, null); // There is one category named "Diary"
Log.i("Test_03_searchNotes_Category_Diary_Favorite_True", "Size: " + notes.size());
assertEquals(notes.size(), 1);
- notes = roomDatabase.searchNotes(thisAccountID, null, null, null, null); // Fetch all notes
+ notes = db.searchNotes(thisAccountID, null, null, null, null); // Fetch all notes
Log.i("Test_03_searchNotes_Three_NULL", "Size: " + notes.size());
assertEquals(notes.size(), 4); // We've added three test notes by now
}
@Test
public void test_04_getCategories() {
- List<NavigationAdapter.CategoryNavigationItem> categories = roomDatabase.getCategories(account.getId());
+ List<NavigationAdapter.CategoryNavigationItem> categories = db.getCategories(account.getId());
boolean exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_04_getCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -224,7 +222,7 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_05_searchCategories() {
- List<NavigationAdapter.CategoryNavigationItem> categories = roomDatabase.searchCategories(account.getId(), "Dia");
+ List<NavigationAdapter.CategoryNavigationItem> categories = db.searchCategories(account.getId(), "Dia");
boolean exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_05_searchCategories_Dia", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -234,7 +232,7 @@ public class NotesNotesRoomDatabaseTest {
}
assertTrue(exitFlag);
- categories = roomDatabase.searchCategories(account.getId(), "Mike Chester Wang");
+ categories = db.searchCategories(account.getId(), "Mike Chester Wang");
exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_05_searchCategories_Item_Mike_Chester_Wang", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -248,7 +246,7 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_06_deleteNote() {
long thisAccountID = account.getId();
- List<NoteEntity> notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ List<NoteEntity> notes = db.getNoteDao().getNotes(thisAccountID);
int added_size = notes.size();
Log.i("Test_06_deleteNote_All_Before_Deletion", "Size: " + added_size);
@@ -256,12 +254,12 @@ public class NotesNotesRoomDatabaseTest {
for (NoteEntity cnote : notes) {
Log.i("Test_06_deleteNote_All_Before_Deletion", cnote.toString());
// Delete the note after testing
- roomDatabase.deleteNote(cnote.getId(), cnote.getStatus());
+ db.deleteNote(cnote.getId(), cnote.getStatus());
counter++;
}
// Check if the note is deleted successfully
- notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ notes = db.getNoteDao().getNotes(thisAccountID);
int deleted_size = notes.size();
assertEquals(counter, added_size - deleted_size);
Log.i("Test_06_deleteNote_All_Notes_After_Deletion", "Size: " + deleted_size);
@@ -303,27 +301,27 @@ public class NotesNotesRoomDatabaseTest {
false, "Diary", null));
// Pre-check
- List<NoteEntity> notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ List<NoteEntity> notes = db.getNoteDao().getNotes(thisAccountID);
int pre_size = notes.size();
Log.i("Test_07_multiAddNote_All_Notes_Before_Addition", "Size: " + pre_size);
long[] multiNoteID = new long[10];
for (int i = 0; i < 10; ++i) {
- multiNoteID[i] = roomDatabase.addNote(thisAccountID, multiCloudNote.get(i));
+ multiNoteID[i] = db.addNote(thisAccountID, multiCloudNote.get(i));
}
// check if the node added successfully
for (int i = 0; i < 10; ++i) {
- NoteEntity nodeTemp = NoteEntity.entityToDBNote(roomDatabase.getNoteDao().getNote(thisAccountID, multiNoteID[i]));
+ NoteEntity nodeTemp = db.getNoteDao().getNote(thisAccountID, multiNoteID[i]);
assertEquals(nodeTemp.getTitle(), multiCloudNote.get(i).getTitle());
assertEquals(nodeTemp.getCategory(), multiCloudNote.get(i).getCategory());
assertEquals(nodeTemp.getContent(), multiCloudNote.get(i).getContent());
- assertEquals(nodeTemp.getAccountId(), thisAccountID);
+ assertEquals(nodeTemp.getAccountId().longValue(), thisAccountID);
Log.i("Test_07_multiAddNote_All_Notes_Addition_sucessful", nodeTemp.toString());
}
// check if these note is in all notes
- notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ notes = db.getNoteDao().getNotes(thisAccountID);
int add_size = notes.size();
assertEquals(10, add_size - pre_size);
@@ -333,34 +331,34 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_08_multiSearchNotes() {
long thisAccountID = account.getId();
- List<NoteEntity> notes = roomDatabase.searchNotes(thisAccountID, null, null, null, null);
+ List<NoteEntity> notes = db.searchNotes(thisAccountID, null, null, null, null);
Log.i("Test_08_multiSearchNotes_null_null_null", "Size: " + notes.size());
assertEquals(notes.size(), 10);
- notes = roomDatabase.searchNotes(thisAccountID, null, null, true, null);
+ notes = db.searchNotes(thisAccountID, null, null, true, null);
Log.i("Test_08_multiSearchNotes_null_null_true", "Size: " + notes.size());
assertEquals(notes.size(), 7);
- notes = roomDatabase.searchNotes(thisAccountID, null, "Music", null, null);
+ notes = db.searchNotes(thisAccountID, null, "Music", null, null);
Log.i("Test_08_multiSearchNotes_null_Music_null", "Size: " + notes.size());
assertEquals(notes.size(), 2);
- notes = roomDatabase.searchNotes(thisAccountID, null, "Work", true, null);
+ notes = db.searchNotes(thisAccountID, null, "Work", true, null);
Log.i("Test_08_multiSearchNotes_null_Work_true", "Size: " + notes.size());
assertEquals(notes.size(), 0);
- notes = roomDatabase.searchNotes(thisAccountID, null, "Diary", null, null);
+ notes = db.searchNotes(thisAccountID, null, "Diary", null, null);
Log.i("Test_08_multiSearchNotes_null_Diary_null", "Size: " + notes.size());
assertEquals(notes.size(), 1);
- notes = roomDatabase.searchNotes(thisAccountID, "Mike", null, null, null);
+ notes = db.searchNotes(thisAccountID, "Mike", null, null, null);
Log.i("Test_08_multiSearchNotes_Mike_null_null", "Size: " + notes.size());
assertEquals(notes.size(), 1);
}
@Test
public void test_09_multiGetCategories() {
- List<NavigationAdapter.CategoryNavigationItem> categories = roomDatabase.getCategories(account.getId());
+ List<NavigationAdapter.CategoryNavigationItem> categories = db.getCategories(account.getId());
int count = 0;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_09_multiGetCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -373,7 +371,7 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_10_multiSearchCategories() {
- List<NavigationAdapter.CategoryNavigationItem> categories = roomDatabase.searchCategories(account.getId(), "M");
+ List<NavigationAdapter.CategoryNavigationItem> categories = db.searchCategories(account.getId(), "M");
int count = 0;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_10_multiSearchCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -381,7 +379,7 @@ public class NotesNotesRoomDatabaseTest {
}
assertEquals(3, count);
- categories = roomDatabase.searchCategories(account.getId(), "Mike");
+ categories = db.searchCategories(account.getId(), "Mike");
count = 0;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_10_multiSearchCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -389,7 +387,7 @@ public class NotesNotesRoomDatabaseTest {
}
assertEquals(0, count);
- categories = roomDatabase.searchCategories(account.getId(), "M");
+ categories = db.searchCategories(account.getId(), "M");
boolean exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_10_multiSearchCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -400,7 +398,7 @@ public class NotesNotesRoomDatabaseTest {
assertTrue(exitFlag);
- categories = roomDatabase.searchCategories(account.getId(), "WOk");
+ categories = db.searchCategories(account.getId(), "WOk");
exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_10_multiSearchCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -410,7 +408,7 @@ public class NotesNotesRoomDatabaseTest {
}
assertFalse(exitFlag);
- categories = roomDatabase.searchCategories(account.getId(), "hello");
+ categories = db.searchCategories(account.getId(), "hello");
exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_10_multiSearchCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -424,17 +422,17 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_11_multiDeleteNote() {
long thisAccountID = account.getId();
- List<NoteEntity> notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ List<NoteEntity> notes = db.getNoteDao().getNotes(thisAccountID);
int added_size = notes.size();
Log.i("Test_11_multiDeleteNote_All_Before_Deletion", "Size: " + added_size);
for (NoteEntity e : notes) {
Log.i("Test_11_multiDeleteNote_All_Before_Deletion", e.toString());
- roomDatabase.deleteNote(e.getId(), e.getStatus());
+ db.deleteNote(e.getId(), e.getStatus());
}
// Check if the note is deleted successfully
- notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ notes = db.getNoteDao().getNotes(thisAccountID);
int deleted_size = notes.size();
assertEquals(10, added_size - deleted_size);
Log.i("Test_11_multiDeleteNote_All_After_Deletion", "Size: " + deleted_size);
@@ -448,14 +446,14 @@ public class NotesNotesRoomDatabaseTest {
true, "日记", null);
// Pre-check
- List<NoteEntity> notes = roomDatabase.getNoteDao().getNotes(accountID);
+ List<NoteEntity> notes = db.getNoteDao().getNotes(accountID);
int pre_size = notes.size();
Log.i("Test_12_Chinese_All_Notes_Before_Addition", "Size: " + pre_size);
// Add a new note
- long noteID = roomDatabase.addNote(accountID, cloudNote);
+ long noteID = db.addNote(accountID, cloudNote);
// Check if this note is added successfully
- NoteEntity note = roomDatabase.getNoteDao().getNote(accountID, noteID);
+ NoteEntity note = db.getNoteDao().getNote(accountID, noteID);
Log.i("Test_12_Chinese_Cur_Note", note.toString());
Log.i("Test_12_Chinese_Cur_Note", "Title: " + note.getTitle());
Log.i("Test_12_Chinese_Cur_Note", "Content: " + note.getContent());
@@ -464,10 +462,10 @@ public class NotesNotesRoomDatabaseTest {
assertEquals("美好的一天", note.getTitle());
assertEquals(cloudNote.getContent(), note.getContent());
assertEquals("日记", note.getCategory());
- assertEquals(accountID, note.getAccountId());
+ assertEquals(accountID, note.getAccountId().longValue());
// Check if this note is in all notes
- notes = roomDatabase.getNoteDao().getNotes(accountID);
+ notes = db.getNoteDao().getNotes(accountID);
int added_size = notes.size();
assertEquals(1, added_size - pre_size);
@@ -478,11 +476,11 @@ public class NotesNotesRoomDatabaseTest {
}
long thisAccountID = account.getId();
- notes = roomDatabase.searchNotes(thisAccountID, "美好", "日记", true, null);
+ notes = db.searchNotes(thisAccountID, "美好", "日记", true, null);
Log.i("Test_12_Chinese", "Size: " + notes.size());
assertEquals(1, notes.size());
- List<NavigationAdapter.CategoryNavigationItem> categories = roomDatabase.getCategories(account.getId());
+ List<NavigationAdapter.CategoryNavigationItem> categories = db.getCategories(account.getId());
boolean exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_12_Chinese_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -492,7 +490,7 @@ public class NotesNotesRoomDatabaseTest {
}
assertTrue(exitFlag);
- categories = roomDatabase.searchCategories(account.getId(), "记");
+ categories = db.searchCategories(account.getId(), "记");
exitFlag = false;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_12_Chinese_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon));
@@ -502,15 +500,15 @@ public class NotesNotesRoomDatabaseTest {
}
assertTrue(exitFlag);
- notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ notes = db.getNoteDao().getNotes(thisAccountID);
for (NoteEntity cnote : notes) {
Log.i("Test_12_Chinese_All_Before_Deletion", cnote.toString());
// Delete the note after testing
- roomDatabase.deleteNote(cnote.getId(), cnote.getStatus());
+ db.deleteNote(cnote.getId(), cnote.getStatus());
}
// Check if the note is deleted successfully
- notes = roomDatabase.getNoteDao().getNotes(thisAccountID);
+ notes = db.getNoteDao().getNotes(thisAccountID);
int deleted_size = notes.size();
assertEquals(1, added_size - deleted_size);
Log.i("Test_12_Chinese_All_Notes_After_Deletion", "Size: " + deleted_size);
@@ -519,12 +517,12 @@ public class NotesNotesRoomDatabaseTest {
@Test
public void test_13_getCategoryIdByTitle() {
try {
- Method method = NotesDatabase.class.getDeclaredMethod("getCategoryIdByTitle",
+ Method method = NotesRoomDatabase.class.getDeclaredMethod("getCategoryIdByTitle",
long.class,
String.class);
method.setAccessible(true);
- List<NavigationAdapter.CategoryNavigationItem> categories = roomDatabase.getCategories(account.getId());
+ List<NavigationAdapter.CategoryNavigationItem> categories = db.getCategories(account.getId());
int count = 0;
for (NavigationAdapter.NavigationItem categoryItem : categories) {
Log.i("Test_13_getCategoryIdByTitle", String.format("%s | %s | %d | %d",
@@ -537,13 +535,13 @@ public class NotesNotesRoomDatabaseTest {
// Find an existing category to test false
if (count > 0) {
- catID = (int) method.invoke(sqliteOpenHelperDatabase, account.getId(), categories.get(0).label);
+ catID = (int) method.invoke(db, account.getId(), categories.get(0).label);
assertNotEquals(-1, catID);
}
// Create a category not existing
String cur_cat = "Mike Chester Wang's Diary" + getCurDate();
- catID = (int) method.invoke(sqliteOpenHelperDatabase, account.getId(), cur_cat);
+ catID = (int) method.invoke(db, account.getId(), cur_cat);
assertNotEquals(-1, catID);
} catch (Exception e) {
fail(Arrays.toString(e.getStackTrace()));
@@ -567,19 +565,19 @@ public class NotesNotesRoomDatabaseTest {
NoteEntity cloudNote = new NoteEntity(1, Calendar.getInstance(),
"A Coding Day", "This is a day which is very suitable to code.",
true, "CodingDiary", null);
- long noteID = roomDatabase.addNote(account.getId(), cloudNote);
+ long noteID = db.addNote(account.getId(), cloudNote);
// check the default value of ordering_method
- CategorySortingMethod defaultMethod = roomDatabase.getCategoryDao().getCategoryOrderByTitle(account.getId(), "CodingDiary");
+ CategorySortingMethod defaultMethod = db.getCategoryDao().getCategoryOrderByTitle(account.getId(), "CodingDiary");
assertEquals(defaultMethod, CategorySortingMethod.getCSM(0));
// modify the value of ordering_method and check
- roomDatabase.getCategoryDao().modifyCategoryOrderByTitle(account.getId(), "CodingDiary", CategorySortingMethod.getCSM(1));
- CategorySortingMethod methodAfterModify = roomDatabase.getCategoryDao().getCategoryOrderByTitle(account.getId(), "CodingDiary");
+ db.getCategoryDao().modifyCategoryOrderByTitle(account.getId(), "CodingDiary", CategorySortingMethod.getCSM(1));
+ CategorySortingMethod methodAfterModify = db.getCategoryDao().getCategoryOrderByTitle(account.getId(), "CodingDiary");
assertEquals(methodAfterModify, CategorySortingMethod.getCSM(1));
// delete the Node
- roomDatabase.deleteNote(noteID, DBStatus.VOID);
+ db.deleteNote(noteID, DBStatus.VOID);
}
@Test
@@ -589,53 +587,53 @@ public class NotesNotesRoomDatabaseTest {
NoteEntity cloudNote = new NoteEntity(1, Calendar.getInstance(),
"A Coding Day", "This is a day which is very suitable to code.",
true, "CodingDiary", null);
- long noteID = roomDatabase.addNote(account.getId(), cloudNote);
+ long noteID = db.addNote(account.getId(), cloudNote);
// check the default value of ordering_method
- CategorySortingMethod defaultMethod = roomDatabase.getCategoryOrder(account.getId(), new Category("CodingDiary", false));
+ CategorySortingMethod defaultMethod = db.getCategoryOrder(account.getId(), new Category("CodingDiary", false));
assertEquals(defaultMethod, CategorySortingMethod.getCSM(0));
// modify the value of ordering_method and check
- roomDatabase.getCategoryDao().modifyCategoryOrderByTitle(account.getId(), "CodingDiary", CategorySortingMethod.getCSM(1));
- CategorySortingMethod methodAfterModify = roomDatabase.getCategoryOrder(account.getId(), new Category("CodingDiary", false));
+ db.getCategoryDao().modifyCategoryOrderByTitle(account.getId(), "CodingDiary", CategorySortingMethod.getCSM(1));
+ CategorySortingMethod methodAfterModify = db.getCategoryOrder(account.getId(), new Category("CodingDiary", false));
assertEquals(methodAfterModify, CategorySortingMethod.getCSM(1));
// delete the Node
- roomDatabase.deleteNote(noteID, DBStatus.VOID);
+ db.deleteNote(noteID, DBStatus.VOID);
// Special categories
- Context ctx = sqliteOpenHelperDatabase.getContext().getApplicationContext();
+ Context ctx = db.getContext().getApplicationContext();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ctx);
SharedPreferences.Editor spe = sp.edit();
spe.clear();
spe.apply();
// check default value
// all notes
- defaultMethod = roomDatabase.getCategoryOrder(account.getId(), new Category(null, false));
+ defaultMethod = db.getCategoryOrder(account.getId(), new Category(null, false));
assertEquals(defaultMethod, CategorySortingMethod.getCSM(0));
// uncategorized
- defaultMethod = roomDatabase.getCategoryOrder(account.getId(), new Category("", false));
+ defaultMethod = db.getCategoryOrder(account.getId(), new Category("", false));
assertEquals(defaultMethod, CategorySortingMethod.getCSM(0));
// favorite
- defaultMethod = roomDatabase.getCategoryOrder(account.getId(), new Category(null, true));
+ defaultMethod = db.getCategoryOrder(account.getId(), new Category(null, true));
assertEquals(defaultMethod, CategorySortingMethod.getCSM(0));
// modify the value of ordering_method and check
// all notes
- roomDatabase.modifyCategoryOrder(account.getId(), new Category(null, false), CategorySortingMethod.getCSM(1));
- methodAfterModify = roomDatabase.getCategoryOrder(account.getId(), new Category(null, false));
+ db.modifyCategoryOrder(account.getId(), new Category(null, false), CategorySortingMethod.getCSM(1));
+ methodAfterModify = db.getCategoryOrder(account.getId(), new Category(null, false));
assertEquals(methodAfterModify, CategorySortingMethod.getCSM(1));
// uncategorized
- roomDatabase.modifyCategoryOrder(account.getId(), new Category("", false), CategorySortingMethod.getCSM(1));
- methodAfterModify = roomDatabase.getCategoryOrder(account.getId(), new Category("", false));
+ db.modifyCategoryOrder(account.getId(), new Category("", false), CategorySortingMethod.getCSM(1));
+ methodAfterModify = db.getCategoryOrder(account.getId(), new Category("", false));
assertEquals(methodAfterModify, CategorySortingMethod.getCSM(1));
// favorite
- roomDatabase.modifyCategoryOrder(account.getId(), new Category(null, true), CategorySortingMethod.getCSM(1));
- methodAfterModify = roomDatabase.getCategoryOrder(account.getId(), new Category(null, true));
+ db.modifyCategoryOrder(account.getId(), new Category(null, true), CategorySortingMethod.getCSM(1));
+ methodAfterModify = db.getCategoryOrder(account.getId(), new Category(null, true));
assertEquals(methodAfterModify, CategorySortingMethod.getCSM(1));
// delete SharedPreferences
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java
index 8c4a6fca..d397203b 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java
@@ -36,7 +36,7 @@ public class AppendToNoteActivity extends MainActivity {
@Override
public void onNoteClick(int position, View v) {
if (receivedText != null && receivedText.length() > 0) {
- final NoteEntity note = roomDatabase.getNoteDao().getNote(localAccount.getId(), ((NoteEntity) adapter.getItem(position)).getId());
+ final NoteEntity note = db.getNoteDao().getNote(localAccount.getId(), ((NoteEntity) adapter.getItem(position)).getId());
final String oldContent = note.getContent();
String newContent;
if (oldContent != null && oldContent.length() > 0) {
@@ -44,7 +44,7 @@ public class AppendToNoteActivity extends MainActivity {
} else {
newContent = receivedText;
}
- roomDatabase.updateNoteAndSync(ssoAccount, localAccount, note, newContent, null, () -> Toast.makeText(this, getString(R.string.added_content, receivedText), Toast.LENGTH_SHORT).show());
+ db.updateNoteAndSync(ssoAccount, localAccount, note, newContent, null, () -> Toast.makeText(this, getString(R.string.added_content, receivedText), Toast.LENGTH_SHORT).show());
} else {
Toast.makeText(this, R.string.shared_text_empty, Toast.LENGTH_SHORT).show();
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
index c99293ae..e44701a4 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
@@ -138,7 +138,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
protected ItemAdapter adapter;
- protected NotesRoomDatabase roomDatabase = null;
+ protected NotesRoomDatabase db = null;
private NavigationAdapter adapterCategories;
private NavigationItem itemRecent;
private NavigationItem itemFavorites;
@@ -189,14 +189,14 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
categoryAdapterSelectedItem = savedInstanceState.getString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION);
}
- roomDatabase = NotesRoomDatabase.getInstance(this);
+ db = NotesRoomDatabase.getInstance(this);
gridView = isGridViewEnabled();
if (!gridView || isDarkThemeActive(this)) {
activityBinding.activityNotesListView.setBackgroundColor(ContextCompat.getColor(this, R.color.primary));
}
- LocalAccountDao dao = roomDatabase.getLocalAccountDao();
+ LocalAccountDao dao = db.getLocalAccountDao();
new Thread(() -> {
List<LocalAccountEntity> localAccountEntities = dao.getAccounts();
Log.v("TEST", localAccountEntities.size() + " acs");
@@ -206,7 +206,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
setupNavigationMenu();
setupNotesList();
- new Thread(() -> canMoveNoteToAnotherAccounts = roomDatabase.getLocalAccountDao().getAccountsCount() > 1).start();
+ new Thread(() -> canMoveNoteToAnotherAccounts = db.getLocalAccountDao().getAccountsCount() > 1).start();
}
@Override
@@ -218,7 +218,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
}
} catch (NoCurrentAccountSelectedException | NextcloudFilesAppAccountNotFoundException e) {
if (localAccount == null) {
- List<LocalAccountEntity> localAccounts = roomDatabase.getLocalAccountDao().getAccounts();
+ List<LocalAccountEntity> localAccounts = db.getLocalAccountDao().getAccounts();
if (localAccounts.size() > 0) {
localAccount = localAccounts.get(0);
}
@@ -232,7 +232,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
refreshLists();
if (localAccount != null) {
synchronize();
- roomDatabase.getNoteServerSyncHelper().addCallbackPull(ssoAccount, syncCallBack);
+ db.getNoteServerSyncHelper().addCallbackPull(ssoAccount, syncCallBack);
}
super.onResume();
}
@@ -250,12 +250,12 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
private void selectAccount(String accountName) {
fabCreate.hide();
SingleAccountHelper.setCurrentAccount(getApplicationContext(), accountName);
- localAccount = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(accountName);
+ localAccount = db.getLocalAccountDao().getLocalAccountByAccountName(accountName);
if (localAccount != null) {
try {
BrandingUtil.saveBrandColors(this, Color.parseColor(localAccount.getColor()), Color.parseColor(localAccount.getTextColor()));
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(getApplicationContext());
- new NotesListViewItemTouchHelper(ssoAccount, this, roomDatabase, adapter, syncCallBack, this::refreshLists, swipeRefreshLayout, this, gridView)
+ new NotesListViewItemTouchHelper(ssoAccount, this, db, adapter, syncCallBack, this::refreshLists, swipeRefreshLayout, this, gridView)
.attachToRecyclerView(listView);
synchronize();
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
@@ -372,12 +372,12 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
final Capabilities capabilities;
try {
capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, localAccount.getCapabilitiesETag());
- roomDatabase.getLocalAccountDao().updateCapabilitiesETag(localAccount.getId(), capabilities.getETag());
- roomDatabase.updateBrand(localAccount.getId(), capabilities);
+ db.getLocalAccountDao().updateCapabilitiesETag(localAccount.getId(), capabilities.getETag());
+ db.updateBrand(localAccount.getId(), capabilities);
localAccount.setColor(capabilities.getColor());
localAccount.setTextColor(capabilities.getTextColor());
BrandingUtil.saveBrandColors(this, Color.parseColor(localAccount.getColor()), Color.parseColor(localAccount.getTextColor()));
- roomDatabase.updateApiVersion(localAccount.getId(), capabilities.getApiVersion());
+ db.updateApiVersion(localAccount.getId(), capabilities.getApiVersion());
Log.i(TAG, capabilities.toString());
} catch (Exception e) {
if (e instanceof NextcloudHttpRequestFailedException && ((NextcloudHttpRequestFailedException) e).getStatusCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
@@ -407,14 +407,14 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
activityBinding.sortingMethod.setOnClickListener((v) -> {
CategorySortingMethod method;
- method = roomDatabase.getCategoryOrder(localAccount.getId(), navigationSelection);
+ method = db.getCategoryOrder(localAccount.getId(), navigationSelection);
if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) {
method = CategorySortingMethod.SORT_MODIFIED_DESC;
} else {
method = CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC;
}
- roomDatabase.modifyCategoryOrder(localAccount.getId(), navigationSelection, method);
+ db.modifyCategoryOrder(localAccount.getId(), navigationSelection, method);
refreshLists();
updateSortMethodIcon(localAccount.getId());
});
@@ -517,7 +517,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
if (localAccount == null) {
return new ArrayList<>();
}
- List<CategoryNavigationItem> categories = roomDatabase.getCategories(localAccount.getId());
+ List<CategoryNavigationItem> categories = db.getCategories(localAccount.getId());
if (!categories.isEmpty() && categories.get(0).label.isEmpty()) {
itemUncategorized = categories.get(0);
itemUncategorized.label = getString(R.string.action_uncategorized);
@@ -526,8 +526,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
itemUncategorized = null;
}
- int numFavorites = roomDatabase.getNoteDao().getFavoritesCount(localAccount.getId());
- int numNonFavorites = roomDatabase.getNoteDao().getNonFavoritesCount(localAccount.getId());
+ int numFavorites = db.getNoteDao().getFavoritesCount(localAccount.getId());
+ int numNonFavorites = db.getNoteDao().getNonFavoritesCount(localAccount.getId());
itemFavorites.count = numFavorites;
itemRecent.count = numFavorites + numNonFavorites;
@@ -708,7 +708,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
* Updates sorting method icon.
*/
private void updateSortMethodIcon(long localAccountId) {
- CategorySortingMethod method = roomDatabase.getCategoryOrder(localAccountId, navigationSelection);
+ CategorySortingMethod method = db.getCategoryOrder(localAccountId, navigationSelection);
if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) {
activityBinding.sortingMethod.setImageResource(R.drawable.alphabetical_asc);
activityBinding.sortingMethod.setContentDescription(getString(R.string.sort_last_modified));
@@ -780,7 +780,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
if (resultCode == RESULT_FIRST_USER) {
selectAccount(null);
}
- new Thread(() -> canMoveNoteToAnotherAccounts = roomDatabase.getLocalAccountDao().getAccountsCount() > 1).start();
+ new Thread(() -> canMoveNoteToAnotherAccounts = db.getLocalAccountDao().getAccountsCount() > 1).start();
break;
}
default: {
@@ -792,8 +792,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
try {
Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null);
- roomDatabase.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities);
- new Thread(() -> canMoveNoteToAnotherAccounts = roomDatabase.getLocalAccountDao().getAccountsCount() > 1).start();
+ db.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities);
+ new Thread(() -> canMoveNoteToAnotherAccounts = db.getLocalAccountDao().getAccountsCount() > 1).start();
Log.i(TAG, capabilities.toString());
runOnUiThread(() -> selectAccount(ssoAccount.name));
} catch (SQLiteException e) {
@@ -801,7 +801,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
runOnUiThread(() -> selectAccount(ssoAccount.name));
} catch (Exception e) {
// Happens when importing an already existing account the second time
- if (e instanceof TokenMismatchException && roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name) != null) {
+ if (e instanceof TokenMismatchException && db.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name) != null) {
Log.w(TAG, "Received " + TokenMismatchException.class.getSimpleName() + " and the given ssoAccount.name (" + ssoAccount.name + ") does already exist in the database. Assume that this account has already been imported.");
runOnUiThread(() -> {
selectAccount(ssoAccount.name);
@@ -888,7 +888,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
if (selected) {
v.setSelected(true);
mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback(
- this, this, roomDatabase, localAccount.getId(), canMoveNoteToAnotherAccounts, adapter, listView, this::refreshLists, getSupportFragmentManager(), activityBinding.searchView
+ this, this, db, localAccount.getId(), canMoveNoteToAnotherAccounts, adapter, listView, this::refreshLists, getSupportFragmentManager(), activityBinding.searchView
));
int checkedItemCount = adapter.getSelected().size();
mActionMode.setTitle(getResources().getQuantityString(R.plurals.ab_selected, checkedItemCount, checkedItemCount));
@@ -922,7 +922,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
}
private void synchronize() {
- NoteServerSyncHelper syncHelper = roomDatabase.getNoteServerSyncHelper();
+ NoteServerSyncHelper syncHelper = db.getNoteServerSyncHelper();
if (!syncHelper.isSyncPossible()) {
syncHelper.updateNetworkStatus();
}
@@ -954,9 +954,9 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
@Override
public void onAccountDeleted(LocalAccountEntity localAccount) {
- roomDatabase.deleteAccount(localAccount);
+ db.deleteAccount(localAccount);
if (localAccount.getId() == this.localAccount.getId()) {
- List<LocalAccountEntity> remainingAccounts = roomDatabase.getLocalAccountDao().getAccounts();
+ List<LocalAccountEntity> remainingAccounts = db.getLocalAccountDao().getAccounts();
if (remainingAccounts.size() > 0) {
this.localAccount = remainingAccounts.get(0);
selectAccount(this.localAccount.getAccountName());
@@ -974,7 +974,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
adapter.deselect(0);
for (Integer i : selection) {
NoteEntity note = (NoteEntity) adapter.getItem(i);
- roomDatabase.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), roomDatabase.getNoteDao().getNote(note.getAccountId(), note.getId()), account.getId());
+ db.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), db.getNoteDao().getNote(note.getAccountId(), note.getId()), account.getId());
RecyclerView.ViewHolder viewHolder = listView.findViewHolderForAdapterPosition(i);
if (viewHolder != null) {
viewHolder.itemView.setSelected(false);
@@ -994,7 +994,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
CategoryEntity c = new CategoryEntity();
c.setTitle(category);
note.setCategory(c);
- roomDatabase.setCategory(ssoAccount, note, category, this::refreshLists);
+ db.setCategory(ssoAccount, note, category, this::refreshLists);
}
mActionMode.finish();
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java
index 864d1313..fcf9e248 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java
@@ -33,7 +33,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
public NotesListViewItemTouchHelper(
@NonNull SingleSignOnAccount ssoAccount,
@NonNull Context context,
- @NonNull NotesRoomDatabase roomDatabase,
+ @NonNull NotesRoomDatabase db,
@NonNull ItemAdapter adapter,
@NonNull ISyncCallback syncCallBack,
@NonNull Runnable refreshLists,
@@ -72,8 +72,8 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
switch (direction) {
case ItemTouchHelper.LEFT:
final NoteEntity dbNoteWithoutContent = (NoteEntity) adapter.getItem(viewHolder.getAdapterPosition());
- final NoteEntity dbNote = roomDatabase.getNoteDao().getNote(dbNoteWithoutContent.getAccountId(), dbNoteWithoutContent.getId());
- roomDatabase.deleteNoteAndSync(ssoAccount, dbNote.getId());
+ final NoteEntity dbNote = db.getNoteDao().getNote(dbNoteWithoutContent.getAccountId(), dbNoteWithoutContent.getId());
+ db.deleteNoteAndSync(ssoAccount, dbNote.getId());
adapter.remove(dbNote);
refreshLists.run();
Log.v(TAG, "Item deleted through swipe ----------------------------------------------");
@@ -82,8 +82,8 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
} else {
BrandedSnackbar.make(viewProvider.getView(), context.getString(R.string.action_note_deleted, dbNote.getTitle()), UNDO_DURATION)
.setAction(R.string.action_undo, (View v) -> {
- roomDatabase.getNoteServerSyncHelper().addCallbackPush(ssoAccount, refreshLists::run);
- roomDatabase.addNoteAndSync(ssoAccount, dbNote.getAccountId(), dbNote);
+ db.getNoteServerSyncHelper().addCallbackPush(ssoAccount, refreshLists::run);
+ db.addNoteAndSync(ssoAccount, dbNote.getAccountId(), dbNote);
refreshLists.run();
BrandedSnackbar.make(viewProvider.getView(), context.getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT)
.show();
@@ -93,7 +93,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
break;
case ItemTouchHelper.RIGHT:
final NoteEntity adapterNote = (NoteEntity) adapter.getItem(viewHolder.getAdapterPosition());
- roomDatabase.toggleFavoriteAndSync(ssoAccount, adapterNote.getId(), syncCallBack);
+ db.toggleFavoriteAndSync(ssoAccount, adapterNote.getId(), syncCallBack);
refreshLists.run();
break;
default:
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java
index ae5d2165..8cf0d51d 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java
@@ -21,7 +21,7 @@ public class ManageAccountsActivity extends LockedActivity {
private ActivityManageAccountsBinding binding;
private ManageAccountAdapter adapter;
- private NotesRoomDatabase roomDatabase = null;
+ private NotesRoomDatabase db = null;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -32,12 +32,12 @@ public class ManageAccountsActivity extends LockedActivity {
setSupportActionBar(binding.toolbar);
- roomDatabase = NotesRoomDatabase.getInstance(this);
+ db = NotesRoomDatabase.getInstance(this);
- List<LocalAccountEntity> localAccounts = roomDatabase.getLocalAccountDao().getAccounts();
+ List<LocalAccountEntity> localAccounts = db.getLocalAccountDao().getAccounts();
adapter = new ManageAccountAdapter((localAccount) -> SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccount.getAccountName()), (localAccount) -> {
- roomDatabase.deleteAccount(localAccount);
+ db.deleteAccount(localAccount);
for (LocalAccountEntity temp : localAccounts) {
if (temp.getId() == localAccount.getId()) {
localAccounts.remove(temp);
@@ -56,7 +56,7 @@ public class ManageAccountsActivity extends LockedActivity {
try {
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this);
if (ssoAccount != null) {
- adapter.setCurrentLocalAccount(roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name));
+ adapter.setCurrentLocalAccount(db.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name));
}
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java
index 62f5d66c..676fad9f 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java
@@ -39,9 +39,9 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
@Override
protected List<Item> doInBackground(Void... voids) {
List<NoteEntity> noteList;
- NotesRoomDatabase roomDatabase = NotesRoomDatabase.getInstance(context);
- CategorySortingMethod sortingMethod = roomDatabase.getCategoryOrder(accountId, category);
- noteList = roomDatabase.getNoteDao().searchNotesSubcategory(accountId, searchQuery.toString(), category.category, category.favorite, sortingMethod);
+ NotesRoomDatabase db = NotesRoomDatabase.getInstance(context);
+ CategorySortingMethod sortingMethod = db.getCategoryOrder(accountId, category);
+ noteList = db.getNoteDao().searchNotesSubcategory(accountId, searchQuery.toString(), category.category, category.favorite, sortingMethod);
if (category.category == null) {
if (sortingMethod == CategorySortingMethod.SORT_MODIFIED_DESC) {
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
index 362fdf44..bf6c906d 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
@@ -118,12 +118,12 @@ public class NoteServerSyncHelper {
* This has to be a singleton in order to realize correct registering and unregistering of
* the BroadcastReceiver, which listens on changes of network connectivity.
*
- * @param roomDatabase {@link NotesRoomDatabase}
+ * @param db {@link NotesRoomDatabase}
* @return NoteServerSyncHelper
*/
- public static synchronized NoteServerSyncHelper getInstance(NotesRoomDatabase roomDatabase) {
+ public static synchronized NoteServerSyncHelper getInstance(NotesRoomDatabase db) {
if (instance == null) {
- instance = new NoteServerSyncHelper(roomDatabase);
+ instance = new NoteServerSyncHelper(db);
}
return instance;
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java
index 51a589c0..80edb446 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java
@@ -36,19 +36,19 @@ public class NoteListWidget extends AppWidgetProvider {
public static final int PENDING_INTENT_OPEN_APP_RQ = 2;
static void updateAppWidget(Context context, AppWidgetManager awm, int[] appWidgetIds) {
- final NotesRoomDatabase roomDatabase = NotesRoomDatabase.getInstance(context);
+ final NotesRoomDatabase db = NotesRoomDatabase.getInstance(context);
RemoteViews views;
DarkModeSetting darkTheme;
for (int appWidgetId : appWidgetIds) {
try {
- final NoteListsWidgetData data = roomDatabase.getWidgetNotesListDao().getNoteListWidgetData(appWidgetId);
- final LocalAccountEntity localAccountEntity = roomDatabase.getLocalAccountDao().getAccount(data.getAccountId());
+ final NoteListsWidgetData data = db.getWidgetNotesListDao().getNoteListWidgetData(appWidgetId);
+ final LocalAccountEntity localAccountEntity = db.getLocalAccountDao().getAccount(data.getAccountId());
String category = null;
if (data.getCategoryId() != null) {
- category = roomDatabase.getCategoryDao().getCategoryTitleById(data.getCategoryId());
+ category = db.getCategoryDao().getCategoryTitleById(data.getCategoryId());
}
darkTheme = DarkModeSetting.fromModeID(data.getThemeMode());
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java
index cdcb6d0c..10ac43fc 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java
@@ -40,7 +40,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
private NavigationAdapter adapterCategories;
private NavigationAdapter.NavigationItem itemRecent;
private NavigationAdapter.NavigationItem itemFavorites;
- private NotesRoomDatabase roomDatabase = null;
+ private NotesRoomDatabase db = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -48,9 +48,9 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
setResult(RESULT_CANCELED);
setContentView(R.layout.activity_note_list_configuration);
- roomDatabase = NotesRoomDatabase.getInstance(this);
+ db = NotesRoomDatabase.getInstance(this);
try {
- this.localAccount = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(this).name);
+ this.localAccount = db.getLocalAccountDao().getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(this).name);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
Toast.makeText(this, R.string.widget_not_logged_in, Toast.LENGTH_LONG).show();
@@ -104,7 +104,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
data.setAccountId(localAccount.getId());
data.setThemeMode(NotesApplication.getAppTheme(getApplicationContext()).getModeId());
- roomDatabase.getWidgetNotesListDao().createOrUpdateNoteListWidgetData(data);
+ db.getWidgetNotesListDao().createOrUpdateNoteListWidgetData(data);
Intent updateIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null,
getApplicationContext(), NoteListWidget.class);
@@ -143,7 +143,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
return new ArrayList<>();
}
NavigationAdapter.NavigationItem itemUncategorized;
- List<CategoryNavigationItem> categories = roomDatabase.getCategories(localAccount.getId());
+ List<CategoryNavigationItem> categories = db.getCategories(localAccount.getId());
if (!categories.isEmpty() && categories.get(0).label.isEmpty()) {
itemUncategorized = categories.get(0);
@@ -151,8 +151,8 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
itemUncategorized.icon = NavigationAdapter.ICON_NOFOLDER;
}
- int numFavorites = roomDatabase.getNoteDao().getFavoritesCount(localAccount.getId());
- int numNonFavorites = roomDatabase.getNoteDao().getNonFavoritesCount(localAccount.getId());
+ int numFavorites = db.getNoteDao().getFavoritesCount(localAccount.getId());
+ int numNonFavorites = db.getNoteDao().getNonFavoritesCount(localAccount.getId());
itemFavorites.count = numFavorites;
itemRecent.count = numFavorites + numNonFavorites;
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java
index 7ecec33a..b2c46c8a 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java
@@ -80,10 +80,10 @@ public class SingleNoteWidget extends AppWidgetProvider {
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
- final NotesRoomDatabase roomDatabase = NotesRoomDatabase.getInstance(context);
+ final NotesRoomDatabase db = NotesRoomDatabase.getInstance(context);
for (int appWidgetId : appWidgetIds) {
- roomDatabase.getWidgetSingleNoteDao().removeSingleNoteWidget(appWidgetId);
+ db.getWidgetSingleNoteDao().removeSingleNoteWidget(appWidgetId);
}
super.onDeleted(context, appWidgetIds);
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java
index 555a9d87..60c6fb44 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java
@@ -53,7 +53,7 @@ public class SingleNoteWidgetConfigurationActivity extends MainActivity {
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
try {
- roomDatabase.getWidgetSingleNoteDao().createOrUpdateSingleNoteWidgetData(
+ db.getWidgetSingleNoteDao().createOrUpdateSingleNoteWidgetData(
new WidgetSingleNoteEntity(
appWidgetId,
note.getAccountId(),