diff --git a/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java index f5695a408..ab68ff34f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java @@ -17,7 +17,7 @@ public abstract class LockedActivity extends BrandedActivity { private static final String TAG = LockedActivity.class.getSimpleName(); - private static final int REQUEST_CODE_UNLOCK = 100; + protected static final int REQUEST_CODE_UNLOCK = 100; @Override diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index 43e482a75..948a0abc8 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -65,6 +65,7 @@ import it.niedermann.android.util.ColorUtil; import it.niedermann.owncloud.notes.LockedActivity; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener; import it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherDialog; @@ -137,6 +138,33 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A boolean canMoveNoteToAnotherAccounts = false; + private void getNotesListLiveData() { + mainViewModel.getNotesListLiveData().observe(this, notes -> { + // https://stackoverflow.com/a/37342327 + itemTouchHelper.attachToRecyclerView(null); + itemTouchHelper.attachToRecyclerView(listView); + adapter.setItemList(notes); + binding.activityNotesListView.progressCircular.setVisibility(GONE); + binding.activityNotesListView.emptyContentView.getRoot().setVisibility(notes.size() > 0 ? GONE : VISIBLE); + // Remove deleted notes from the selection + if (tracker.hasSelection()) { + final var deletedNotes = new LinkedList(); + for (final var id : tracker.getSelection()) { + if (notes + .stream() + .filter(item -> !item.isSection()) + .map(item -> (Note) item) + .noneMatch(item -> item.getId() == id)) { + deletedNotes.add(id); + } + } + for (final var id : deletedNotes) { + tracker.deselect(id); + } + } + }); + } + @Override protected void onCreate(Bundle savedInstanceState) { SplashScreen.installSplashScreen(this); @@ -264,30 +292,10 @@ protected void onCreate(Bundle savedInstanceState) { startActivityForResult(createIntent, REQUEST_CODE_CREATE_NOTE); }); }); - mainViewModel.getNotesListLiveData().observe(this, notes -> { - // https://stackoverflow.com/a/37342327 - itemTouchHelper.attachToRecyclerView(null); - itemTouchHelper.attachToRecyclerView(listView); - adapter.setItemList(notes); - binding.activityNotesListView.progressCircular.setVisibility(GONE); - binding.activityNotesListView.emptyContentView.getRoot().setVisibility(notes.size() > 0 ? GONE : VISIBLE); - // Remove deleted notes from the selection - if (tracker.hasSelection()) { - final var deletedNotes = new LinkedList(); - for (final var id : tracker.getSelection()) { - if (notes - .stream() - .filter(item -> !item.isSection()) - .map(item -> (Note) item) - .noneMatch(item -> item.getId() == id)) { - deletedNotes.add(id); - } - } - for (final var id : deletedNotes) { - tracker.deselect(id); - } - } - }); + + if (!NotesApplication.isLocked()) { + getNotesListLiveData(); + } mainViewModel.getSearchTerm().observe(this, adapter::setHighlightSearchQuery); mainViewModel.getCategorySortingMethodOfSelectedCategory().observe(this, methodOfCategory -> { updateSortMethodIcon(methodOfCategory.second); @@ -683,6 +691,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } break; } + case REQUEST_CODE_UNLOCK: { + if (RESULT_OK == resultCode) { + getNotesListLiveData(); + } + break; + } default: { try { AccountImporter.onActivityResult(requestCode, resultCode, data, this, (ssoAccount) -> {