diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-10-06 13:17:31 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-10-06 13:17:31 +0300 |
commit | 680a6b712102a60e9aef98cf0c51c38ef2086e21 (patch) | |
tree | ef87c45fbc887e18d862b0bb1dd95f70ab9eefa3 /app/src/main/java | |
parent | 23a6958ed4b9f0faa7281aea48ba83b889e2d2c5 (diff) |
#831 Migrate from SQLiteOpenHelper to Room
Diffstat (limited to 'app/src/main/java')
10 files changed, 60 insertions, 60 deletions
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(), |