Calendar currentTime = new GregorianCalendar();
Long l = new Long(currentTime.getTimeInMillis());
String newGuid = new String(Long.toString(l));
// Note newNote = oldNote.deepCopy();
Note newNote = (Note)Global.deepCopy(oldNote);
newNote.setUpdateSequenceNum(0);
newNote.setGuid(newGuid);
newNote.setDeleted(0);
newNote.setActive(true);
/*
List<String> tagNames = new ArrayList<String>();
List<String> tagGuids = new ArrayList<String>();;
for (int i=0; i<oldNote.getTagGuidsSize(); i++) {
tagNames.add(oldNote.getTagNames().get(i));
tagGuids.add(oldNote.getTagGuids().get(i));
}
// Sort note Tags to make them look nice
for (int i=0; i<tagNames.size()-1; i++) {
if (tagNames.get(i).compareTo(tagNames.get(i+1))<0) {
String n1 = tagNames.get(i);
String n2 = tagNames.get(i+1);
tagNames.set(i, n2);
tagNames.set(i+1, n1);
}
}
newNote.setTagGuids(tagGuids);
newNote.setTagNames(tagNames);
// Add tag guids to note
*/
// Duplicate resources
List<Resource> resList = oldNote.getResources();
if (resList == null)
resList = new ArrayList<Resource>();
long prevGuid = 0;
for (int i=0; i<resList.size(); i++) {
l = prevGuid;
while (l == prevGuid) {
currentTime = new GregorianCalendar();
l = new Long(currentTime.getTimeInMillis());
}
prevGuid = l;
String newResGuid = new String(Long.toString(l));
resList.get(i).setNoteGuid(newGuid);
resList.get(i).setGuid(newResGuid);
resList.get(i).setUpdateSequenceNum(0);
resList.get(i).setActive(true);
conn.getNoteTable().noteResourceTable.saveNoteResource(
(Resource)Global.deepCopy(resList.get(i)), true);
}
newNote.setResources(resList);
// Add note to the database
conn.getNoteTable().addNote(newNote, true);
NoteMetadata metaData = new NoteMetadata();
NoteMetadata oldMeta = listManager.getNoteMetadata().get(oldNote.getGuid());
metaData.copy(oldMeta);
metaData.setGuid(newNote.getGuid());
listManager.addNote(newNote, metaData);
noteTableView.insertRow(newNote, metaData, true, -1);
currentNoteGuid = newNote.getGuid();
currentNote = newNote;
refreshEvernoteNote(true);
listManager.countNotebookResults(listManager.getNoteIndex());
waitCursor(false);
}