@@ -156,6 +156,17 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
156156 @ Override
157157 public void onResume () {
158158 super .onResume ();
159+
160+ if (note == null ) {
161+ Log .e (TAG , "note is null, onResume" );
162+ return ;
163+ }
164+
165+ if (listener == null ) {
166+ Log .e (TAG , "listener is null, onResume" );
167+ return ;
168+ }
169+
159170 listener .onNoteUpdated (note );
160171 }
161172
@@ -203,6 +214,11 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {
203214 }
204215
205216 private void prepareFavoriteOption (MenuItem item ) {
217+ if (note == null ) {
218+ Log .e (TAG , "note is null, prepareFavoriteOption" );
219+ return ;
220+ }
221+
206222 item .setIcon (note .getFavorite () ? R .drawable .ic_star_white_24dp : R .drawable .ic_star_border_white_24dp );
207223 item .setChecked (note .getFavorite ());
208224
@@ -301,6 +317,11 @@ protected boolean shouldShowToolbar() {
301317 }
302318
303319 public void onCloseNote () {
320+ if (note == null ) {
321+ Log .e (TAG , "note is null, onCloseNote" );
322+ return ;
323+ }
324+
304325 if (!titleModified && originalNote == null && getContent ().isEmpty ()) {
305326 repo .deleteNoteAndSync (localAccount , note .getId ());
306327 }
@@ -313,23 +334,29 @@ public void onCloseNote() {
313334 */
314335 protected void saveNote (@ Nullable ISyncCallback callback ) {
315336 Log .d (TAG , "saveData()" );
316- if (note != null ) {
317- final var newContent = getContent ();
318- if (note .getContent ().equals (newContent )) {
319- if (note .getScrollY () != originalScrollY ) {
320- Log .v (TAG , "... only saving new scroll state, since content did not change" );
321- repo .updateScrollY (note .getId (), note .getScrollY ());
322- } else {
323- Log .v (TAG , "... not saving, since nothing has changed" );
324- }
337+ if (note == null ) {
338+ Log .e (TAG , "note is null, saveNote" );
339+ return ;
340+ }
341+
342+ if (listener == null ) {
343+ Log .e (TAG , "listener is null, saveNote" );
344+ return ;
345+ }
346+
347+ final var newContent = getContent ();
348+ if (note .getContent ().equals (newContent )) {
349+ if (note .getScrollY () != originalScrollY ) {
350+ Log .v (TAG , "... only saving new scroll state, since content did not change" );
351+ repo .updateScrollY (note .getId (), note .getScrollY ());
325352 } else {
326- // FIXME requires database queries on main thread!
327- note = repo .updateNoteAndSync (localAccount , note , newContent , null , callback );
328- listener .onNoteUpdated (note );
329- requireActivity ().invalidateOptionsMenu ();
353+ Log .v (TAG , "... not saving, since nothing has changed" );
330354 }
331355 } else {
332- Log .e (TAG , "note is null" );
356+ // FIXME requires database queries on main thread!
357+ note = repo .updateNoteAndSync (localAccount , note , newContent , null , callback );
358+ listener .onNoteUpdated (note );
359+ requireActivity ().invalidateOptionsMenu ();
333360 }
334361 }
335362
@@ -368,13 +395,33 @@ public void showEditTitleDialog() {
368395
369396 @ Override
370397 public void onCategoryChosen (String category ) {
398+ if (note == null ) {
399+ Log .e (TAG , "note is null, onCategoryChosen" );
400+ return ;
401+ }
402+
403+ if (listener == null ) {
404+ Log .e (TAG , "listener is null, onCategoryChosen" );
405+ return ;
406+ }
407+
371408 repo .setCategory (localAccount , note .getId (), category );
372409 note .setCategory (category );
373410 listener .onNoteUpdated (note );
374411 }
375412
376413 @ Override
377414 public void onTitleEdited (String newTitle ) {
415+ if (note == null ) {
416+ Log .e (TAG , "note is null, onTitleEdited" );
417+ return ;
418+ }
419+
420+ if (listener == null ) {
421+ Log .e (TAG , "listener is null, onTitleEdited" );
422+ return ;
423+ }
424+
378425 titleModified = true ;
379426 note .setTitle (newTitle );
380427 executor .submit (() -> {
@@ -384,6 +431,16 @@ public void onTitleEdited(String newTitle) {
384431 }
385432
386433 public void moveNote (Account account ) {
434+ if (note == null ) {
435+ Log .e (TAG , "note is null, moveNote" );
436+ return ;
437+ }
438+
439+ if (listener == null ) {
440+ Log .e (TAG , "listener is null, moveNote" );
441+ return ;
442+ }
443+
387444 final var moveLiveData = repo .moveNoteToAnotherAccount (account , note );
388445 moveLiveData .observe (this , (v ) -> moveLiveData .removeObservers (this ));
389446 listener .close ();
0 commit comments