Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide notes when app is locked #1905

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Long>();
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);
Expand Down Expand Up @@ -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<Long>();
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);
Expand Down Expand Up @@ -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) -> {
Expand Down