154
154
import it .feio .android .omninotes .models .adapters .PlacesAutoCompleteAdapter ;
155
155
import it .feio .android .omninotes .models .listeners .OnAttachingFileListener ;
156
156
import it .feio .android .omninotes .models .listeners .OnGeoUtilResultListener ;
157
- import it .feio .android .omninotes .models .listeners .OnNoteSaved ;
158
157
import it .feio .android .omninotes .models .listeners .OnReminderPickedListener ;
159
158
import it .feio .android .omninotes .models .listeners .RecyclerViewItemClickSupport ;
160
159
import it .feio .android .omninotes .models .views .ExpandableHeightGridView ;
183
182
import java .util .ArrayList ;
184
183
import java .util .Arrays ;
185
184
import java .util .Calendar ;
186
- import java .util .Collections ;
187
185
import java .util .Date ;
188
186
import java .util .List ;
189
187
import org .apache .commons .collections4 .CollectionUtils ;
192
190
193
191
public class DetailFragment extends BaseFragment implements OnReminderPickedListener ,
194
192
OnTouchListener ,
195
- OnAttachingFileListener , TextWatcher , CheckListChangedListener , OnNoteSaved ,
193
+ OnAttachingFileListener , TextWatcher , CheckListChangedListener ,
196
194
OnGeoUtilResultListener {
197
195
198
196
private static final int TAKE_PHOTO = 1 ;
@@ -383,7 +381,7 @@ public void onPause() {
383
381
384
382
// Checks "goBack" value to avoid performing a double saving
385
383
if (!goBack ) {
386
- saveNote (this );
384
+ saveNote ();
387
385
}
388
386
389
387
if (toggleChecklistView != null ) {
@@ -1136,7 +1134,7 @@ private void showNoteInfo() {
1136
1134
1137
1135
private void navigateUp () {
1138
1136
afterSavedReturnsToList = true ;
1139
- saveAndExit (this );
1137
+ saveAndExit ();
1140
1138
}
1141
1139
1142
1140
private void toggleChecklist () {
@@ -1480,8 +1478,7 @@ private void discard() {
1480
1478
}
1481
1479
1482
1480
if (noteOriginal .get_id () != null ) {
1483
- new SaveNoteTask (mFragment , false )
1484
- .executeOnExecutor (AsyncTask .THREAD_POOL_EXECUTOR , noteOriginal );
1481
+ new SaveNoteTask (false ).executeOnExecutor (AsyncTask .THREAD_POOL_EXECUTOR , noteOriginal );
1485
1482
BaseActivity .notifyAppWidgets (mainActivity );
1486
1483
} else {
1487
1484
goHome ();
@@ -1501,7 +1498,7 @@ private void archiveNote(boolean archive) {
1501
1498
goBack = true ;
1502
1499
exitMessage = archive ? getString (R .string .note_archived ) : getString (R .string .note_unarchived );
1503
1500
exitCroutonStyle = archive ? ONStyle .WARN : ONStyle .INFO ;
1504
- saveNote (this );
1501
+ saveNote ();
1505
1502
}
1506
1503
1507
1504
@ SuppressLint ("NewApi" )
@@ -1522,7 +1519,7 @@ private void trashNote(boolean trash) {
1522
1519
} else {
1523
1520
ReminderHelper .addReminder (getAppContext (), note );
1524
1521
}
1525
- saveNote (this );
1522
+ saveNote ();
1526
1523
}
1527
1524
1528
1525
private void deleteNote () {
@@ -1537,21 +1534,19 @@ private void deleteNote() {
1537
1534
}).build ().show ();
1538
1535
}
1539
1536
1540
- public void saveAndExit (OnNoteSaved mOnNoteSaved ) {
1537
+ public void saveAndExit () {
1541
1538
if (isAdded ()) {
1542
1539
exitMessage = getString (R .string .note_updated );
1543
1540
exitCroutonStyle = ONStyle .CONFIRM ;
1544
1541
goBack = true ;
1545
- saveNote (mOnNoteSaved );
1542
+ saveNote ();
1546
1543
}
1547
1544
}
1548
1545
1549
1546
/**
1550
1547
* Save new notes, modify them or archive
1551
1548
*/
1552
- void saveNote (OnNoteSaved mOnNoteSaved ) {
1553
-
1554
- // Changed fields
1549
+ void saveNote () {
1555
1550
noteTmp .setTitle (getNoteTitle ());
1556
1551
noteTmp .setContent (getNoteContent ());
1557
1552
@@ -1575,7 +1570,7 @@ void saveNote(OnNoteSaved mOnNoteSaved) {
1575
1570
1576
1571
noteTmp .setAttachmentsListOld (note .getAttachmentsList ());
1577
1572
1578
- new SaveNoteTask (mOnNoteSaved , lastModificationUpdatedNeeded ()).executeOnExecutor (AsyncTask
1573
+ new SaveNoteTask (lastModificationUpdatedNeeded ()).executeOnExecutor (AsyncTask
1579
1574
.THREAD_POOL_EXECUTOR , noteTmp );
1580
1575
}
1581
1576
@@ -1602,21 +1597,6 @@ private boolean lastModificationUpdatedNeeded() {
1602
1597
return noteTmp .isChanged (note );
1603
1598
}
1604
1599
1605
- @ Override
1606
- public void onNoteSaved (Note noteSaved ) {
1607
- if (!activityPausing ) {
1608
- EventBus .getDefault ().post (new NotesUpdatedEvent (Collections .singletonList (noteSaved )));
1609
- deleteMergedNotes (mergedNotesIds );
1610
- if (noteTmp .getAlarm () != null && !noteTmp .getAlarm ().equals (note .getAlarm ())) {
1611
- ReminderHelper .showReminderMessage (String .valueOf (noteTmp .getAlarm ()));
1612
- }
1613
- }
1614
- note = new Note (noteSaved );
1615
- if (goBack ) {
1616
- goHome ();
1617
- }
1618
- }
1619
-
1620
1600
private void deleteMergedNotes (List <String > mergedNotesIds ) {
1621
1601
ArrayList <Note > notesToDelete = new ArrayList <>();
1622
1602
if (mergedNotesIds != null ) {
@@ -2190,6 +2170,19 @@ public void onEventMainThread(PushbulletReplyEvent pushbulletReplyEvent) {
2190
2170
binding .fragmentDetailContent .detailContent .setText (text );
2191
2171
}
2192
2172
2173
+ public void onEvent (NotesUpdatedEvent event ) {
2174
+ if (!activityPausing ) {
2175
+ deleteMergedNotes (mergedNotesIds );
2176
+ if (noteTmp .getAlarm () != null && !noteTmp .getAlarm ().equals (note .getAlarm ())) {
2177
+ ReminderHelper .showReminderMessage (String .valueOf (noteTmp .getAlarm ()));
2178
+ }
2179
+ }
2180
+ note = new Note (event .getNotes ().get (0 ));
2181
+ if (goBack ) {
2182
+ goHome ();
2183
+ }
2184
+ }
2185
+
2193
2186
private static class OnGeoUtilResultListenerImpl implements OnGeoUtilResultListener {
2194
2187
2195
2188
private final WeakReference <MainActivity > mainActivityWeakReference ;
0 commit comments