Loading app/build.gradle +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ dependencies { // Testing testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:3.9.0' testImplementation 'org.robolectric:robolectric:4.5.1' testImplementation 'androidx.test:core:1.3.0' testImplementation 'androidx.test.ext:junit:1.1.2' Loading app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +5 −5 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding; import it.niedermann.owncloud.notes.manageaccounts.ManageAccountsActivity; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRepository; import it.niedermann.owncloud.notes.persistence.entity.Account; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLayerDrawable; Loading @@ -33,7 +33,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { private static final String KEY_CURRENT_ACCOUNT_ID = "current_account_id"; private NotesDatabase db; private NotesRepository repo; private DialogAccountSwitcherBinding binding; private AccountSwitcherListener accountSwitcherListener; private long currentAccountId; Loading @@ -55,7 +55,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { this.currentAccountId = args.getLong(KEY_CURRENT_ACCOUNT_ID); } db = NotesDatabase.getInstance(requireActivity()); repo = NotesRepository.getInstance(requireContext()); } @NonNull Loading @@ -63,7 +63,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { binding = DialogAccountSwitcherBinding.inflate(requireActivity().getLayoutInflater()); final LiveData<Account> account$ = db.getAccountDao().getAccountById$(currentAccountId); final LiveData<Account> account$ = repo.getAccountById$(currentAccountId); account$.observe(requireActivity(), (currentLocalAccount) -> { account$.removeObservers(requireActivity()); Loading @@ -81,7 +81,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { dismiss(); })); binding.accountsList.setAdapter(adapter); final LiveData<List<Account>> localAccounts$ = db.getAccountDao().getAccounts$(); final LiveData<List<Account>> localAccounts$ = repo.getAccounts$(); localAccounts$.observe(requireActivity(), (localAccounts) -> { localAccounts$.removeObservers(requireActivity()); for (Account localAccount : localAccounts) { Loading app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java +17 −17 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment; import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment.CategoryDialogListener; import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment; import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment.EditTitleListener; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRepository; import it.niedermann.owncloud.notes.persistence.entity.Account; import it.niedermann.owncloud.notes.persistence.entity.Note; import it.niedermann.owncloud.notes.shared.model.ApiVersion; Loading Loading @@ -76,7 +76,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego @Nullable private Note originalNote; private int originalScrollY; protected NotesDatabase db; protected NotesRepository repo; private NoteFragmentListener listener; private boolean titleModified = false; Loading @@ -90,7 +90,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement " + NoteFragmentListener.class); } db = NotesDatabase.getInstance(context); repo = NotesRepository.getInstance(context); } @Override Loading @@ -99,7 +99,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego new Thread(() -> { try { SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext().getApplicationContext()); this.localAccount = db.getAccountDao().getAccountByName(ssoAccount.name); this.localAccount = repo.getAccountByName(ssoAccount.name); if (savedInstanceState == null) { long id = requireArguments().getLong(PARAM_NOTE_ID); Loading @@ -107,11 +107,11 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego long accountId = requireArguments().getLong(PARAM_ACCOUNT_ID); if (accountId > 0) { /* Switch account if account id has been provided */ this.localAccount = db.getAccountDao().getAccountById(accountId); this.localAccount = repo.getAccountById(accountId); SingleAccountHelper.setCurrentAccount(requireContext().getApplicationContext(), localAccount.getAccountName()); } isNew = false; note = originalNote = db.getNoteDao().getNoteById(id); note = originalNote = repo.getNoteById(id); requireActivity().runOnUiThread(() -> onNoteLoaded(note)); requireActivity().invalidateOptionsMenu(); } else { Loading @@ -126,7 +126,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego requireActivity().invalidateOptionsMenu(); } } else { note = db.addNote(localAccount.getId(), cloudNote); note = repo.addNote(localAccount.getId(), cloudNote); originalNote = null; requireActivity().runOnUiThread(() -> onNoteLoaded(note)); requireActivity().invalidateOptionsMenu(); Loading Loading @@ -213,19 +213,19 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (itemId == R.id.menu_cancel) { new Thread(() -> { if (originalNote == null) { db.deleteNoteAndSync(localAccount, note.getId()); repo.deleteNoteAndSync(localAccount, note.getId()); } else { db.updateNoteAndSync(localAccount, originalNote, null, null, null); repo.updateNoteAndSync(localAccount, originalNote, null, null, null); } }).start(); listener.close(); return true; } else if (itemId == R.id.menu_delete) { db.deleteNoteAndSync(localAccount, note.getId()); repo.deleteNoteAndSync(localAccount, note.getId()); listener.close(); return true; } else if (itemId == R.id.menu_favorite) { db.toggleFavoriteAndSync(localAccount, note.getId()); repo.toggleFavoriteAndSync(localAccount, note.getId()); listener.onNoteUpdated(note); prepareFavoriteOption(item); return true; Loading Loading @@ -288,7 +288,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego public void onCloseNote() { if (!titleModified && originalNote == null && getContent().isEmpty()) { db.deleteNoteAndSync(localAccount, note.getId()); repo.deleteNoteAndSync(localAccount, note.getId()); } } Loading @@ -304,13 +304,13 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (note.getContent().equals(newContent)) { if (note.getScrollY() != originalScrollY) { Log.v(TAG, "... only saving new scroll state, since content did not change"); db.getNoteDao().updateScrollY(note.getId(), note.getScrollY()); repo.updateScrollY(note.getId(), note.getScrollY()); } else { Log.v(TAG, "... not saving, since nothing has changed"); } } else { // FIXME requires database queries on main thread! note = db.updateNoteAndSync(localAccount, note, newContent, null, callback); note = repo.updateNoteAndSync(localAccount, note, newContent, null, callback); listener.onNoteUpdated(note); requireActivity().invalidateOptionsMenu(); } Loading Loading @@ -354,7 +354,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego @Override public void onCategoryChosen(String category) { db.setCategory(localAccount, note.getId(), category); repo.setCategory(localAccount, note.getId(), category); note.setCategory(category); listener.onNoteUpdated(note); } Loading @@ -364,13 +364,13 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego titleModified = true; note.setTitle(newTitle); new Thread(() -> { note = db.updateNoteAndSync(localAccount, note, note.getContent(), newTitle, null); note = repo.updateNoteAndSync(localAccount, note, note.getContent(), newTitle, null); requireActivity().runOnUiThread(() -> listener.onNoteUpdated(note)); }).start(); } public void moveNote(Account account) { db.moveNoteToAnotherAccount(account, note); repo.moveNoteToAnotherAccount(account, note); listener.close(); } Loading app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java +6 −6 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O protected void registerInternalNoteLinkHandler() { binding.singleNoteContent.registerOnLinkClickCallback((link) -> { try { final long noteLocalId = db.getNoteDao().getLocalIdByRemoteId(this.note.getAccountId(), Long.parseLong(link)); final long noteLocalId = repo.getLocalIdByRemoteId(this.note.getAccountId(), Long.parseLong(link)); Log.i(TAG, "Found note for remoteId \"" + link + "\" in account \"" + this.note.getAccountId() + "\" with localId + \"" + noteLocalId + "\". Attempt to open " + EditNoteActivity.class.getSimpleName() + " for this note."); startActivity(new Intent(requireActivity().getApplicationContext(), EditNoteActivity.class).putExtra(EditNoteActivity.PARAM_NOTE_ID, noteLocalId)); return true; Loading Loading @@ -153,20 +153,20 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O @Override public void onRefresh() { if (noteLoaded && db.getNoteServerSyncHelper().isSyncPossible() && SSOUtil.isConfigured(getContext())) { if (noteLoaded && repo.isSyncPossible() && SSOUtil.isConfigured(getContext())) { binding.swiperefreshlayout.setRefreshing(true); new Thread(() -> { try { final Account account = db.getAccountDao().getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()).name); db.getNoteServerSyncHelper().addCallbackPull(account, () -> new Thread(() -> { note = db.getNoteDao().getNoteById(note.getId()); final Account account = repo.getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()).name); repo.addCallbackPull(account, () -> new Thread(() -> { note = repo.getNoteById(note.getId()); changedText = note.getContent(); requireActivity().runOnUiThread(() -> { binding.singleNoteContent.setMarkdownString(note.getContent()); binding.swiperefreshlayout.setRefreshing(false); }); }).start()); db.getNoteServerSyncHelper().scheduleSync(account, false); repo.scheduleSync(account, false); } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { e.printStackTrace(); } Loading app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryViewModel.java +4 −4 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import androidx.lifecycle.MutableLiveData; import java.util.List; import it.niedermann.owncloud.notes.main.navigation.NavigationItem; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRepository; import static androidx.lifecycle.Transformations.map; import static androidx.lifecycle.Transformations.switchMap; Loading @@ -19,14 +19,14 @@ import static it.niedermann.owncloud.notes.shared.util.DisplayUtils.convertToCat public class CategoryViewModel extends AndroidViewModel { private final NotesDatabase db; private final NotesRepository repo; @NonNull private final MutableLiveData<String> searchTerm = new MutableLiveData<>(""); public CategoryViewModel(@NonNull Application application) { super(application); db = NotesDatabase.getInstance(application); repo = NotesRepository.getInstance(application); } public void postSearchTerm(@NonNull String searchTerm) { Loading @@ -36,7 +36,7 @@ public class CategoryViewModel extends AndroidViewModel { @NonNull public LiveData<List<NavigationItem.CategoryNavigationItem>> getCategories(long accountId) { return switchMap(this.searchTerm, searchTerm -> map(db.getNoteDao().searchCategories$(accountId, TextUtils.isEmpty(searchTerm) ? "%" : "%" + searchTerm + "%"), map(repo.searchCategories$(accountId, TextUtils.isEmpty(searchTerm) ? "%" : "%" + searchTerm + "%"), categories -> convertToCategoryNavigationItem(getApplication(), categories))); } } Loading
app/build.gradle +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ dependencies { // Testing testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:3.9.0' testImplementation 'org.robolectric:robolectric:4.5.1' testImplementation 'androidx.test:core:1.3.0' testImplementation 'androidx.test.ext:junit:1.1.2' Loading
app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +5 −5 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding; import it.niedermann.owncloud.notes.manageaccounts.ManageAccountsActivity; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRepository; import it.niedermann.owncloud.notes.persistence.entity.Account; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToLayerDrawable; Loading @@ -33,7 +33,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { private static final String KEY_CURRENT_ACCOUNT_ID = "current_account_id"; private NotesDatabase db; private NotesRepository repo; private DialogAccountSwitcherBinding binding; private AccountSwitcherListener accountSwitcherListener; private long currentAccountId; Loading @@ -55,7 +55,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { this.currentAccountId = args.getLong(KEY_CURRENT_ACCOUNT_ID); } db = NotesDatabase.getInstance(requireActivity()); repo = NotesRepository.getInstance(requireContext()); } @NonNull Loading @@ -63,7 +63,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { binding = DialogAccountSwitcherBinding.inflate(requireActivity().getLayoutInflater()); final LiveData<Account> account$ = db.getAccountDao().getAccountById$(currentAccountId); final LiveData<Account> account$ = repo.getAccountById$(currentAccountId); account$.observe(requireActivity(), (currentLocalAccount) -> { account$.removeObservers(requireActivity()); Loading @@ -81,7 +81,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { dismiss(); })); binding.accountsList.setAdapter(adapter); final LiveData<List<Account>> localAccounts$ = db.getAccountDao().getAccounts$(); final LiveData<List<Account>> localAccounts$ = repo.getAccounts$(); localAccounts$.observe(requireActivity(), (localAccounts) -> { localAccounts$.removeObservers(requireActivity()); for (Account localAccount : localAccounts) { Loading
app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java +17 −17 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment; import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment.CategoryDialogListener; import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment; import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment.EditTitleListener; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRepository; import it.niedermann.owncloud.notes.persistence.entity.Account; import it.niedermann.owncloud.notes.persistence.entity.Note; import it.niedermann.owncloud.notes.shared.model.ApiVersion; Loading Loading @@ -76,7 +76,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego @Nullable private Note originalNote; private int originalScrollY; protected NotesDatabase db; protected NotesRepository repo; private NoteFragmentListener listener; private boolean titleModified = false; Loading @@ -90,7 +90,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement " + NoteFragmentListener.class); } db = NotesDatabase.getInstance(context); repo = NotesRepository.getInstance(context); } @Override Loading @@ -99,7 +99,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego new Thread(() -> { try { SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext().getApplicationContext()); this.localAccount = db.getAccountDao().getAccountByName(ssoAccount.name); this.localAccount = repo.getAccountByName(ssoAccount.name); if (savedInstanceState == null) { long id = requireArguments().getLong(PARAM_NOTE_ID); Loading @@ -107,11 +107,11 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego long accountId = requireArguments().getLong(PARAM_ACCOUNT_ID); if (accountId > 0) { /* Switch account if account id has been provided */ this.localAccount = db.getAccountDao().getAccountById(accountId); this.localAccount = repo.getAccountById(accountId); SingleAccountHelper.setCurrentAccount(requireContext().getApplicationContext(), localAccount.getAccountName()); } isNew = false; note = originalNote = db.getNoteDao().getNoteById(id); note = originalNote = repo.getNoteById(id); requireActivity().runOnUiThread(() -> onNoteLoaded(note)); requireActivity().invalidateOptionsMenu(); } else { Loading @@ -126,7 +126,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego requireActivity().invalidateOptionsMenu(); } } else { note = db.addNote(localAccount.getId(), cloudNote); note = repo.addNote(localAccount.getId(), cloudNote); originalNote = null; requireActivity().runOnUiThread(() -> onNoteLoaded(note)); requireActivity().invalidateOptionsMenu(); Loading Loading @@ -213,19 +213,19 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (itemId == R.id.menu_cancel) { new Thread(() -> { if (originalNote == null) { db.deleteNoteAndSync(localAccount, note.getId()); repo.deleteNoteAndSync(localAccount, note.getId()); } else { db.updateNoteAndSync(localAccount, originalNote, null, null, null); repo.updateNoteAndSync(localAccount, originalNote, null, null, null); } }).start(); listener.close(); return true; } else if (itemId == R.id.menu_delete) { db.deleteNoteAndSync(localAccount, note.getId()); repo.deleteNoteAndSync(localAccount, note.getId()); listener.close(); return true; } else if (itemId == R.id.menu_favorite) { db.toggleFavoriteAndSync(localAccount, note.getId()); repo.toggleFavoriteAndSync(localAccount, note.getId()); listener.onNoteUpdated(note); prepareFavoriteOption(item); return true; Loading Loading @@ -288,7 +288,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego public void onCloseNote() { if (!titleModified && originalNote == null && getContent().isEmpty()) { db.deleteNoteAndSync(localAccount, note.getId()); repo.deleteNoteAndSync(localAccount, note.getId()); } } Loading @@ -304,13 +304,13 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (note.getContent().equals(newContent)) { if (note.getScrollY() != originalScrollY) { Log.v(TAG, "... only saving new scroll state, since content did not change"); db.getNoteDao().updateScrollY(note.getId(), note.getScrollY()); repo.updateScrollY(note.getId(), note.getScrollY()); } else { Log.v(TAG, "... not saving, since nothing has changed"); } } else { // FIXME requires database queries on main thread! note = db.updateNoteAndSync(localAccount, note, newContent, null, callback); note = repo.updateNoteAndSync(localAccount, note, newContent, null, callback); listener.onNoteUpdated(note); requireActivity().invalidateOptionsMenu(); } Loading Loading @@ -354,7 +354,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego @Override public void onCategoryChosen(String category) { db.setCategory(localAccount, note.getId(), category); repo.setCategory(localAccount, note.getId(), category); note.setCategory(category); listener.onNoteUpdated(note); } Loading @@ -364,13 +364,13 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego titleModified = true; note.setTitle(newTitle); new Thread(() -> { note = db.updateNoteAndSync(localAccount, note, note.getContent(), newTitle, null); note = repo.updateNoteAndSync(localAccount, note, note.getContent(), newTitle, null); requireActivity().runOnUiThread(() -> listener.onNoteUpdated(note)); }).start(); } public void moveNote(Account account) { db.moveNoteToAnotherAccount(account, note); repo.moveNoteToAnotherAccount(account, note); listener.close(); } Loading
app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java +6 −6 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O protected void registerInternalNoteLinkHandler() { binding.singleNoteContent.registerOnLinkClickCallback((link) -> { try { final long noteLocalId = db.getNoteDao().getLocalIdByRemoteId(this.note.getAccountId(), Long.parseLong(link)); final long noteLocalId = repo.getLocalIdByRemoteId(this.note.getAccountId(), Long.parseLong(link)); Log.i(TAG, "Found note for remoteId \"" + link + "\" in account \"" + this.note.getAccountId() + "\" with localId + \"" + noteLocalId + "\". Attempt to open " + EditNoteActivity.class.getSimpleName() + " for this note."); startActivity(new Intent(requireActivity().getApplicationContext(), EditNoteActivity.class).putExtra(EditNoteActivity.PARAM_NOTE_ID, noteLocalId)); return true; Loading Loading @@ -153,20 +153,20 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O @Override public void onRefresh() { if (noteLoaded && db.getNoteServerSyncHelper().isSyncPossible() && SSOUtil.isConfigured(getContext())) { if (noteLoaded && repo.isSyncPossible() && SSOUtil.isConfigured(getContext())) { binding.swiperefreshlayout.setRefreshing(true); new Thread(() -> { try { final Account account = db.getAccountDao().getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()).name); db.getNoteServerSyncHelper().addCallbackPull(account, () -> new Thread(() -> { note = db.getNoteDao().getNoteById(note.getId()); final Account account = repo.getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()).name); repo.addCallbackPull(account, () -> new Thread(() -> { note = repo.getNoteById(note.getId()); changedText = note.getContent(); requireActivity().runOnUiThread(() -> { binding.singleNoteContent.setMarkdownString(note.getContent()); binding.swiperefreshlayout.setRefreshing(false); }); }).start()); db.getNoteServerSyncHelper().scheduleSync(account, false); repo.scheduleSync(account, false); } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { e.printStackTrace(); } Loading
app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryViewModel.java +4 −4 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ import androidx.lifecycle.MutableLiveData; import java.util.List; import it.niedermann.owncloud.notes.main.navigation.NavigationItem; import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRepository; import static androidx.lifecycle.Transformations.map; import static androidx.lifecycle.Transformations.switchMap; Loading @@ -19,14 +19,14 @@ import static it.niedermann.owncloud.notes.shared.util.DisplayUtils.convertToCat public class CategoryViewModel extends AndroidViewModel { private final NotesDatabase db; private final NotesRepository repo; @NonNull private final MutableLiveData<String> searchTerm = new MutableLiveData<>(""); public CategoryViewModel(@NonNull Application application) { super(application); db = NotesDatabase.getInstance(application); repo = NotesRepository.getInstance(application); } public void postSearchTerm(@NonNull String searchTerm) { Loading @@ -36,7 +36,7 @@ public class CategoryViewModel extends AndroidViewModel { @NonNull public LiveData<List<NavigationItem.CategoryNavigationItem>> getCategories(long accountId) { return switchMap(this.searchTerm, searchTerm -> map(db.getNoteDao().searchCategories$(accountId, TextUtils.isEmpty(searchTerm) ? "%" : "%" + searchTerm + "%"), map(repo.searchCategories$(accountId, TextUtils.isEmpty(searchTerm) ? "%" : "%" + searchTerm + "%"), categories -> convertToCategoryNavigationItem(getApplication(), categories))); } }