Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fffa6d21 authored by Stefan Niedermann's avatar Stefan Niedermann Committed by Niedermann IT-Dienstleistungen
Browse files

Hide move menu if only one account is present

parent 621d4cb8
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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));
+4 −1
Original line number Diff line number Diff line
@@ -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) {
+0 −4
Original line number Diff line number Diff line
@@ -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);
    }