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
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));

View file

@ -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) {

View file

@ -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);
}