Skip to content

Commit 37546c3

Browse files
committed
Factor out logic to get notes into separate function
1 parent ea8fee8 commit 37546c3

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,33 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
137137

138138
boolean canMoveNoteToAnotherAccounts = false;
139139

140+
private void getNotesListLiveData() {
141+
mainViewModel.getNotesListLiveData().observe(this, notes -> {
142+
// https://stackoverflow.com/a/37342327
143+
itemTouchHelper.attachToRecyclerView(null);
144+
itemTouchHelper.attachToRecyclerView(listView);
145+
adapter.setItemList(notes);
146+
binding.activityNotesListView.progressCircular.setVisibility(GONE);
147+
binding.activityNotesListView.emptyContentView.getRoot().setVisibility(notes.size() > 0 ? GONE : VISIBLE);
148+
// Remove deleted notes from the selection
149+
if (tracker.hasSelection()) {
150+
final var deletedNotes = new LinkedList<Long>();
151+
for (final var id : tracker.getSelection()) {
152+
if (notes
153+
.stream()
154+
.filter(item -> !item.isSection())
155+
.map(item -> (Note) item)
156+
.noneMatch(item -> item.getId() == id)) {
157+
deletedNotes.add(id);
158+
}
159+
}
160+
for (final var id : deletedNotes) {
161+
tracker.deselect(id);
162+
}
163+
}
164+
});
165+
}
166+
140167
@Override
141168
protected void onCreate(Bundle savedInstanceState) {
142169
SplashScreen.installSplashScreen(this);
@@ -264,30 +291,8 @@ protected void onCreate(Bundle savedInstanceState) {
264291
startActivityForResult(createIntent, REQUEST_CODE_CREATE_NOTE);
265292
});
266293
});
267-
mainViewModel.getNotesListLiveData().observe(this, notes -> {
268-
// https://stackoverflow.com/a/37342327
269-
itemTouchHelper.attachToRecyclerView(null);
270-
itemTouchHelper.attachToRecyclerView(listView);
271-
adapter.setItemList(notes);
272-
binding.activityNotesListView.progressCircular.setVisibility(GONE);
273-
binding.activityNotesListView.emptyContentView.getRoot().setVisibility(notes.size() > 0 ? GONE : VISIBLE);
274-
// Remove deleted notes from the selection
275-
if (tracker.hasSelection()) {
276-
final var deletedNotes = new LinkedList<Long>();
277-
for (final var id : tracker.getSelection()) {
278-
if (notes
279-
.stream()
280-
.filter(item -> !item.isSection())
281-
.map(item -> (Note) item)
282-
.noneMatch(item -> item.getId() == id)) {
283-
deletedNotes.add(id);
284-
}
285-
}
286-
for (final var id : deletedNotes) {
287-
tracker.deselect(id);
288-
}
289-
}
290-
});
294+
295+
getNotesListLiveData();
291296
mainViewModel.getSearchTerm().observe(this, adapter::setHighlightSearchQuery);
292297
mainViewModel.getCategorySortingMethodOfSelectedCategory().observe(this, methodOfCategory -> {
293298
updateSortMethodIcon(methodOfCategory.second);

0 commit comments

Comments
 (0)