@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case DELETE_MENU_ITEM: // Mark the selected note to be deleted and send changes to the // server AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); AppNote note = listAdapter.getItem((int) info.id); mDbHelper.markToDelete(note.getId()); if (note.getOpera_id() != null) { notesDeleted = true; if (automaticSync) { sendChanges(); } } fillData(); return true; } return super.onContextItemSelected(item); }
/** * Delete notes which were marked as those to be deleted, delete them also from the Opera Link * server * * @return true if deleting notes at the server succeeded */ private boolean deleteNotes() { ArrayList<AppNote> toDelete = mDbHelper.fetchNotes(NotesDbAdapter.TO_DELETE_SELECTION); boolean allDeleted = true; for (AppNote appNote : toDelete) { try { if (appNote.getOpera_id() != null) { link.delete(appNote.getNote()); } mDbHelper.deleteNote(appNote.getId()); } catch (LinkItemNotFound e) { e.printStackTrace(); mDbHelper.deleteNote(appNote.getId()); } catch (LinkAccessDeniedException e) { e.printStackTrace(); isConnected = false; allDeleted = false; } catch (LibOperaLinkException e) { e.printStackTrace(); allDeleted = false; } } return allDeleted; }