Skip to content

Commit

Permalink
Choose if to delete merged note after succesfull merge
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Mar 31, 2015
1 parent 5534e2c commit 8bec9da
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions etc/translations/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<string name="delete_note_confirmation">Confirm note deletion?</string>
<string name="confirm">Confirm</string>
<string name="ok">Ok</string>
<string name="no">No</string>
<string name="cancel">Cancel</string>
<string name="note_updated">Note updated</string>
<string name="empty_note_not_saved">Can\'t save an empty note</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ public class DetailFragment extends Fragment implements
private boolean orientationChanged;
private long audioRecordingTimeStart;
private long audioRecordingTime;
private boolean showKeyboard;
private DetailFragment mFragment;
private Attachment sketchEdited;
private ScrollView scrollView;
private int contentLineCounter = 1;
private int contentCursorPosition;
private ArrayList<Integer> mergedNotesIds = new ArrayList<>();


@Override
Expand Down Expand Up @@ -395,6 +395,9 @@ private void handleIntents() {
noteOriginal = new Note();
note = new Note(noteOriginal);
noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
if (i.getIntegerArrayListExtra("merged_notes") != null) {
mergedNotesIds = i.getIntegerArrayListExtra("merged_notes");
}
i.setAction(null);
}

Expand Down Expand Up @@ -1624,11 +1627,20 @@ private boolean lastModificationUpdatedNeeded() {
public void onNoteSaved(Note noteSaved) {
MainActivity.notifyAppWidgets(OmniNotes.getAppContext());
note = new Note(noteSaved);
deleteMergedNotes(mergedNotesIds);
if (goBack) {
goHome();
}
}

private void deleteMergedNotes(ArrayList<Integer> mergedNotesIds) {
for (Integer mergedNoteId : mergedNotesIds) {
Note note = new Note();
note.set_id(mergedNoteId);
DbHelper.getInstance(getActivity().getApplicationContext()).deleteNote(note, true);
}
}


private String getNoteTitle() {
View titleView = root.findViewById(R.id.detail_title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1766,18 +1766,41 @@ private void share() {
}


public void merge() {
new MaterialDialog.Builder(getActivity())
.title(R.string.delete_merged)
.positiveText(R.string.ok)
.negativeText(R.string.no)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
mergeExecute(false);
}

@Override
public void onNegative(MaterialDialog dialog) {
mergeExecute(true);
}
}).build().show();
}


/**
* Merges all the selected notes
*/
public void merge() {
public void mergeExecute(boolean keepMergedNotes) {

Note mergedNote = null;
boolean locked = false;
StringBuilder content = new StringBuilder();
ArrayList<Attachment> attachments = new ArrayList<>();

ArrayList<Integer> notesIds = new ArrayList<>();

for (Note note : getSelectedNotes()) {

notesIds.add(note.get_id());

if (mergedNote == null) {
mergedNote = new Note();
mergedNote.setTitle(note.getTitle());
Expand Down Expand Up @@ -1822,6 +1845,9 @@ public void merge() {

// Sets the intent action to be recognized from DetailFragment and switch fragment
getActivity().getIntent().setAction(Constants.ACTION_MERGE);
if (!keepMergedNotes) {
getActivity().getIntent().putIntegerArrayListExtra("merged_notes", notesIds);
}
getMainActivity().switchToDetail(mergedNote);
}

Expand Down
32 changes: 18 additions & 14 deletions omniNotes/src/main/java/it/feio/android/omninotes/db/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,23 +538,27 @@ public void trashNote(Note note, boolean trash) {
* Deleting single note
*/
public boolean deleteNote(Note note) {
int deletedNotes, deletedAttachments;
boolean result;
SQLiteDatabase db = this.getWritableDatabase();

// Delete notes
deletedNotes = db.delete(TABLE_NOTES, KEY_ID + " = ?",
new String[]{String.valueOf(note.get_id())});
return deleteNote(note, false);
}

// Delete note's attachments
deletedAttachments = db.delete(TABLE_ATTACHMENTS,
KEY_ATTACHMENT_NOTE_ID + " = ?",
new String[]{String.valueOf(note.get_id())});

/**
* Deleting single note but keeping attachments
*/
public boolean deleteNote(Note note, boolean keepAttachments) {
int deletedNotes;
boolean result = true;
SQLiteDatabase db = this.getWritableDatabase();
// Delete notes
deletedNotes = db.delete(TABLE_NOTES, KEY_ID + " = ?", new String[]{String.valueOf(note.get_id())});
if (!keepAttachments) {
// Delete note's attachments
int deletedAttachments = db.delete(TABLE_ATTACHMENTS, KEY_ATTACHMENT_NOTE_ID + " = ?",
new String[]{String.valueOf(note.get_id())});
result = result && deletedAttachments == note.getAttachmentsList().size();
}
// Check on correct and complete deletion
result = deletedNotes == 1
&& deletedAttachments == note.getAttachmentsList().size();

result = result && deletedNotes == 1;
return result;
}

Expand Down
5 changes: 5 additions & 0 deletions omniNotes/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<!--<changelogtext>[b]New![/b] Crash reports can now be deactivated from settings (not recommended)</changelogtext>-->
<!--</changelogversion>-->

<changelogversion versionName="5.0.0 Beta 15" changeDate="Mar 31, 2015">
<changelogtext>[b]New![/b] Choose if to delete merged note after succesfull merge</changelogtext>
<changelogtext>[u]Fix[/u] Fixed Catalan and Asturian translations (sorry for the mistake)</changelogtext>
</changelogversion>

<changelogversion versionName="5.0.0 Beta 14" changeDate="Mar 29, 2015">
<changelogtext>[b]New![/b] Recurrent reminders</changelogtext>
<changelogtext>[u]Fix[/u] Graphic when setting reminder from notification actions</changelogtext>
Expand Down
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="delete_note_confirmation">Confirm note deletion?</string>
<string name="confirm">Confirm</string>
<string name="ok">Ok</string>
<string name="no">No</string>
<string name="cancel">Cancel</string>
<string name="note_updated">Note updated</string>
<string name="empty_note_not_saved">Can\'t save an empty note</string>
Expand Down

0 comments on commit 8bec9da

Please sign in to comment.