diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-22 00:16:59 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-12-22 00:17:24 +0300 |
commit | 0bb2388916a8f4e4191d20571e09f6a5ab2d3564 (patch) | |
tree | 728fdb0114712a33c773121e3957eb42e385e1bd /app/src/main | |
parent | 24040720c5991a0a0c7ec3caa9d6f17542501635 (diff) |
#769 Restore checked state on app start and when switching theme
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main')
3 files changed, 23 insertions, 6 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index 93ca02044..4fc618134 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -258,18 +258,21 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener } boardsList = boards; + Board currentBoard = null; if (boardsList.size() > 0) { boolean currentBoardIdWasInList = false; for (int i = 0; i < boardsList.size(); i++) { if (lastBoardId == boardsList.get(i).getLocalId() || lastBoardId == NO_BOARD_ID) { - setCurrentBoard(boardsList.get(i)); + currentBoard = boardsList.get(i); + setCurrentBoard(currentBoard); currentBoardIdWasInList = true; break; } } if (!currentBoardIdWasInList) { - setCurrentBoard(boardsList.get(0)); + currentBoard = boardsList.get(0); + setCurrentBoard(currentBoard); } binding.filter.setOnClickListener((v) -> FilterDialogFragment.newInstance().show(getSupportFragmentManager(), EditStackDialogFragment.class.getCanonicalName())); @@ -280,13 +283,14 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener binding.filter.setOnClickListener(null); } + final Board finalCurrentBoard = currentBoard; if (hasArchivedBoardsLiveData != null && hasArchivedBoardsLiveDataObserver != null) { hasArchivedBoardsLiveData.removeObserver(hasArchivedBoardsLiveDataObserver); } hasArchivedBoardsLiveData = mainViewModel.hasArchivedBoards(currentAccount.getId()); hasArchivedBoardsLiveDataObserver = (hasArchivedBoards) -> { mainViewModel.setCurrentAccountHasArchivedBoards(Boolean.TRUE.equals(hasArchivedBoards)); - inflateBoardMenu(); + inflateBoardMenu(finalCurrentBoard); }; hasArchivedBoardsLiveData.observe(this, hasArchivedBoardsLiveDataObserver); }; @@ -486,7 +490,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener boardsList.add(createdBoard.getBoard()); setCurrentBoard(createdBoard.getBoard()); - inflateBoardMenu(); + inflateBoardMenu(createdBoard.getBoard()); EditStackDialogFragment.newInstance(NO_STACK_ID).show(getSupportFragmentManager(), addList); } boardsLiveData.observe(this, boardsLiveDataObserver); @@ -546,6 +550,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener lastBoardId = board.getLocalId(); saveCurrentBoardId(this, mainViewModel.getCurrentAccount().getId(), mainViewModel.getCurrentBoardLocalId()); + binding.navigationView.setCheckedItem(boardsList.indexOf(board)); binding.toolbar.setTitle(board.getTitle()); @@ -631,11 +636,12 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener } @UiThread - protected void inflateBoardMenu() { + protected void inflateBoardMenu(@Nullable Board currentBoard) { binding.navigationView.setItemIconTintList(null); Menu menu = binding.navigationView.getMenu(); menu.clear(); DrawerMenuUtil.inflateBoards(this, menu, this.boardsList, mainViewModel.currentAccountHasArchivedBoards(), mainViewModel.getCurrentAccount().getServerDeckVersionAsObject().isSupported(this)); + binding.navigationView.setCheckedItem(boardsList.indexOf(currentBoard)); } @Override @@ -654,7 +660,6 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener startActivity(ArchivedBoardsActvitiy.createIntent(MainActivity.this, mainViewModel.getCurrentAccount())); break; default: - binding.navigationView.setCheckedItem(item); setCurrentBoard(boardsList.get(item.getItemId())); break; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java index d6d9cac1e..fe6a4f1e5 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java @@ -119,6 +119,12 @@ public class ArchivedBoardsActvitiy extends BrandedActivity implements DeleteBoa @Override public void onClone(Board board) { + throw new IllegalStateException("Cloning boards is not available at " + ArchivedBoardsActvitiy.class.getSimpleName()); + } + @Override + public boolean onSupportNavigateUp() { + finish(); // close this activity as oppose to navigating up + return true; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java index 9f170af1e..5fc0990bc 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java @@ -176,6 +176,12 @@ public class EditActivity extends BrandedActivity { return super.onOptionsItemSelected(item); } + @Override + public boolean onSupportNavigateUp() { + finish(); // close this activity as oppose to navigating up + return true; + } + /** * Tries to save the current {@link FullCard} from the {@link EditCardViewModel} and then finishes this activity. */ |