diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-07-29 19:59:41 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-07-29 19:59:41 +0300 |
commit | 94418602133c1352a807fb68ac18af6ccfb68af0 (patch) | |
tree | 0048d5aef0561550c578fb13b6019333d0416c80 /app/src/main | |
parent | 73a9d833e5ecef42697729961afc1111a301373b (diff) |
Only allow filtering when a board has been set to avoid errors
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java | 6 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/MainViewModel.java | 10 |
2 files changed, 12 insertions, 4 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 603e1132f..6bdd4e30b 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 @@ -273,9 +273,13 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener if (!currentBoardIdWasInList) { setCurrentBoard(boardsList.get(0)); } + + binding.filter.setOnClickListener((v) -> FilterDialogFragment.newInstance().show(getSupportFragmentManager(), EditStackDialogFragment.class.getCanonicalName())); } else { clearBrandColors(this); clearCurrentBoard(); + + binding.filter.setOnClickListener(null); } if (hasArchivedBoardsLiveData != null && hasArchivedBoardsLiveDataObserver != null) { @@ -374,8 +378,6 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener }); filterViewModel.getFilterInformation().observe(this, (info) -> binding.filterIndicator.setVisibility(filterViewModel.getFilterInformation().getValue() == null ? View.GONE : View.VISIBLE)); - - binding.filter.setOnClickListener((v) -> FilterDialogFragment.newInstance().show(getSupportFragmentManager(), EditStackDialogFragment.class.getCanonicalName())); binding.archivedCards.setOnClickListener((v) -> startActivity(ArchivedCardsActvitiy.createIntent(this, mainViewModel.getCurrentAccount(), mainViewModel.getCurrentBoardLocalId(), mainViewModel.currentBoardHasEditPermission()))); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainViewModel.java index e5bd4f482..b73b86b33 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainViewModel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainViewModel.java @@ -15,6 +15,7 @@ import it.niedermann.nextcloud.deck.model.Board; public class MainViewModel extends AndroidViewModel { private MutableLiveData<Account> currentAccount = new MutableLiveData<>(); + @Nullable private Board currentBoard; private boolean currentAccountHasArchivedBoards = false; @@ -37,16 +38,21 @@ public class MainViewModel extends AndroidViewModel { this.currentAccountIsSupportedVersion = currentAccount.getServerDeckVersionAsObject().isSupported(getApplication().getApplicationContext()); } - public void setCurrentBoard(Board currentBoard) { + public void setCurrentBoard(@NonNull Board currentBoard) { this.currentBoard = currentBoard; } public Long getCurrentBoardLocalId() { + if(currentBoard == null) { + throw new IllegalStateException("getCurrentBoardLocalId() called before setCurrentBoard()"); + } return this.currentBoard.getLocalId(); } - @Nullable public Long getCurrentBoardRemoteId() { + if(currentBoard == null) { + throw new IllegalStateException("getCurrentBoardRemoteId() called before setCurrentBoard()"); + } return this.currentBoard.getId(); } |