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 1163c053..ad2005d4 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 @@ -144,6 +144,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V @NonNull private Category navigationSelection = new Category(null, null); private String navigationOpen = ""; + boolean canMoveNoteToAnotherAccounts = false; private ActionMode mActionMode; private final ISyncCallback syncCallBack = () -> { adapter.clearSelection(listView); @@ -197,6 +198,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V setupNavigationList(categoryAdapterSelectedItem); setupNavigationMenu(); setupNotesList(); + + new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountsCount() > 1).start(); } @Override @@ -774,6 +777,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V if (resultCode == RESULT_FIRST_USER) { selectAccount(null); } + new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountsCount() > 1).start(); break; } default: { @@ -786,6 +790,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name); final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null); db.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities); + new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountsCount() > 1).start(); Log.i(TAG, capabilities.toString()); runOnUiThread(() -> selectAccount(ssoAccount.name)); } catch (SQLiteException e) { @@ -880,7 +885,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V if (selected) { v.setSelected(true); mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback( - this, this, db, localAccount.getId(), 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)); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java index 8a7d9ecb..e5af7ad9 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java @@ -43,6 +43,7 @@ public class MultiSelectedActionModeCallback implements Callback { private final ViewProvider viewProvider; private final NotesDatabase db; private final long currentLocalAccountId; + private final boolean canMoveNoteToAnotherAccounts; private final ItemAdapter adapter; private final RecyclerView recyclerView; private final Runnable refreshLists; @@ -50,11 +51,12 @@ public class MultiSelectedActionModeCallback implements Callback { private final SearchView searchView; public MultiSelectedActionModeCallback( - Context context, ViewProvider viewProvider, NotesDatabase db, long currentLocalAccountId, ItemAdapter adapter, RecyclerView recyclerView, Runnable refreshLists, FragmentManager fragmentManager, SearchView searchView) { + Context context, ViewProvider viewProvider, NotesDatabase db, long currentLocalAccountId, boolean canMoveNoteToAnotherAccounts, ItemAdapter adapter, RecyclerView recyclerView, Runnable refreshLists, FragmentManager fragmentManager, SearchView searchView) { this.context = context; this.viewProvider = viewProvider; this.db = db; this.currentLocalAccountId = currentLocalAccountId; + this.canMoveNoteToAnotherAccounts = canMoveNoteToAnotherAccounts; this.adapter = adapter; this.recyclerView = recyclerView; this.refreshLists = refreshLists; @@ -70,6 +72,7 @@ public class MultiSelectedActionModeCallback implements Callback { public boolean onCreateActionMode(ActionMode mode, Menu menu) { // inflate contextual menu mode.getMenuInflater().inflate(R.menu.menu_list_context_multiple, menu); + menu.findItem(R.id.menu_move).setVisible(canMoveNoteToAnotherAccounts); for (int i = 0; i < menu.size(); i++) { Drawable drawable = menu.getItem(i).getIcon(); if (drawable != null) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java index a47855ee..982cb464 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java @@ -722,10 +722,6 @@ public class NotesDatabase extends AbstractNotesDatabase { }).start(); } - public boolean hasAccounts() { - return DatabaseUtils.queryNumEntries(getReadableDatabase(), table_accounts) > 0; - } - public long getAccountsCount() { return DatabaseUtils.queryNumEntries(getReadableDatabase(), table_accounts); }