@@ -137,6 +137,33 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
137
137
138
138
boolean canMoveNoteToAnotherAccounts = false ;
139
139
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
+
140
167
@ Override
141
168
protected void onCreate (Bundle savedInstanceState ) {
142
169
SplashScreen .installSplashScreen (this );
@@ -264,30 +291,8 @@ protected void onCreate(Bundle savedInstanceState) {
264
291
startActivityForResult (createIntent , REQUEST_CODE_CREATE_NOTE );
265
292
});
266
293
});
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 ();
291
296
mainViewModel .getSearchTerm ().observe (this , adapter ::setHighlightSearchQuery );
292
297
mainViewModel .getCategorySortingMethodOfSelectedCategory ().observe (this , methodOfCategory -> {
293
298
updateSortMethodIcon (methodOfCategory .second );
0 commit comments