Hide move menu if only one account is present

This commit is contained in:
Stefan Niedermann 2020-06-22 14:26:40 +02:00 committed by Niedermann IT-Dienstleistungen
parent 621d4cb8a4
commit fffa6d215e
3 changed files with 10 additions and 6 deletions

View file

@ -144,6 +144,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
@NonNull @NonNull
private Category navigationSelection = new Category(null, null); private Category navigationSelection = new Category(null, null);
private String navigationOpen = ""; private String navigationOpen = "";
boolean canMoveNoteToAnotherAccounts = false;
private ActionMode mActionMode; private ActionMode mActionMode;
private final ISyncCallback syncCallBack = () -> { private final ISyncCallback syncCallBack = () -> {
adapter.clearSelection(listView); adapter.clearSelection(listView);
@ -197,6 +198,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
setupNavigationList(categoryAdapterSelectedItem); setupNavigationList(categoryAdapterSelectedItem);
setupNavigationMenu(); setupNavigationMenu();
setupNotesList(); setupNotesList();
new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountsCount() > 1).start();
} }
@Override @Override
@ -774,6 +777,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
if (resultCode == RESULT_FIRST_USER) { if (resultCode == RESULT_FIRST_USER) {
selectAccount(null); selectAccount(null);
} }
new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountsCount() > 1).start();
break; break;
} }
default: { default: {
@ -786,6 +790,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name); Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null); final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null);
db.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities); db.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities);
new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountsCount() > 1).start();
Log.i(TAG, capabilities.toString()); Log.i(TAG, capabilities.toString());
runOnUiThread(() -> selectAccount(ssoAccount.name)); runOnUiThread(() -> selectAccount(ssoAccount.name));
} catch (SQLiteException e) { } catch (SQLiteException e) {
@ -880,7 +885,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
if (selected) { if (selected) {
v.setSelected(true); v.setSelected(true);
mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback( 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(); int checkedItemCount = adapter.getSelected().size();
mActionMode.setTitle(getResources().getQuantityString(R.plurals.ab_selected, checkedItemCount, checkedItemCount)); mActionMode.setTitle(getResources().getQuantityString(R.plurals.ab_selected, checkedItemCount, checkedItemCount));

View file

@ -43,6 +43,7 @@ public class MultiSelectedActionModeCallback implements Callback {
private final ViewProvider viewProvider; private final ViewProvider viewProvider;
private final NotesDatabase db; private final NotesDatabase db;
private final long currentLocalAccountId; private final long currentLocalAccountId;
private final boolean canMoveNoteToAnotherAccounts;
private final ItemAdapter adapter; private final ItemAdapter adapter;
private final RecyclerView recyclerView; private final RecyclerView recyclerView;
private final Runnable refreshLists; private final Runnable refreshLists;
@ -50,11 +51,12 @@ public class MultiSelectedActionModeCallback implements Callback {
private final SearchView searchView; private final SearchView searchView;
public MultiSelectedActionModeCallback( 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.context = context;
this.viewProvider = viewProvider; this.viewProvider = viewProvider;
this.db = db; this.db = db;
this.currentLocalAccountId = currentLocalAccountId; this.currentLocalAccountId = currentLocalAccountId;
this.canMoveNoteToAnotherAccounts = canMoveNoteToAnotherAccounts;
this.adapter = adapter; this.adapter = adapter;
this.recyclerView = recyclerView; this.recyclerView = recyclerView;
this.refreshLists = refreshLists; this.refreshLists = refreshLists;
@ -70,6 +72,7 @@ public class MultiSelectedActionModeCallback implements Callback {
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// inflate contextual menu // inflate contextual menu
mode.getMenuInflater().inflate(R.menu.menu_list_context_multiple, 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++) { for (int i = 0; i < menu.size(); i++) {
Drawable drawable = menu.getItem(i).getIcon(); Drawable drawable = menu.getItem(i).getIcon();
if (drawable != null) { if (drawable != null) {

View file

@ -722,10 +722,6 @@ public class NotesDatabase extends AbstractNotesDatabase {
}).start(); }).start();
} }
public boolean hasAccounts() {
return DatabaseUtils.queryNumEntries(getReadableDatabase(), table_accounts) > 0;
}
public long getAccountsCount() { public long getAccountsCount() {
return DatabaseUtils.queryNumEntries(getReadableDatabase(), table_accounts); return DatabaseUtils.queryNumEntries(getReadableDatabase(), table_accounts);
} }