private boolean noteAlreadyOpened(Note note) {
   DetailFragment detailFragment =
       (DetailFragment) mFragmentManager.findFragmentByTag(FRAGMENT_DETAIL_TAG);
   return detailFragment != null
       && detailFragment.getCurrentNote() != null
       && detailFragment.getCurrentNote().get_id() == note.get_id();
 }
 /**
  * Single note permanent deletion
  *
  * @param note Note to be deleted
  */
 @SuppressLint("NewApi")
 public void deleteNote(Note note) {
   // Saving changes to the note
   DeleteNoteTask deleteNoteTask = new DeleteNoteTask(getApplicationContext());
   deleteNoteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, note);
   // Informs about update
   Ln.d("Deleted permanently note with id '" + note.get_id() + "'");
 }
Exemple #3
0
 /** Deleting single note but keeping attachments */
 public boolean deleteNote(Note note, boolean keepAttachments) {
   int deletedNotes;
   boolean result = true;
   SQLiteDatabase db = getDatabase(true);
   // 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 = result && deletedNotes == 1;
   return result;
 }
Exemple #4
0
  /** Retrieves all tags of a specified note */
  public List<Tag> getTags(Note note) {
    List<Tag> tags = new ArrayList<>();
    HashMap<String, Integer> tagsMap = new HashMap<>();

    String whereCondition =
        " WHERE "
            + (note != null ? KEY_ID + " = " + note.get_id() + " AND " : "")
            + "("
            + KEY_CONTENT
            + " LIKE '%#%' OR "
            + KEY_TITLE
            + " LIKE '%#%' "
            + ")"
            + " AND "
            + KEY_TRASHED
            + " IS "
            + (Navigation.checkNavigation(Navigation.TRASH) ? "" : " NOT ")
            + " 1";
    List<Note> notesRetrieved = getNotes(whereCondition, true);

    for (Note noteRetrieved : notesRetrieved) {
      HashMap<String, Integer> tagsRetrieved = TagsHelper.retrieveTags(noteRetrieved);
      for (String s : tagsRetrieved.keySet()) {
        int count = tagsMap.get(s) == null ? 0 : tagsMap.get(s);
        tagsMap.put(s, ++count);
      }
    }

    for (String s : tagsMap.keySet()) {
      Tag tag = new Tag(s, tagsMap.get(s));
      tags.add(tag);
    }

    Collections.sort(tags, (tag1, tag2) -> tag1.getText().compareToIgnoreCase(tag2.getText()));
    return tags;
  }
Exemple #5
0
 /** Retrieves all attachments related to specific note */
 public ArrayList<Attachment> getNoteAttachments(Note note) {
   String whereCondition = " WHERE " + KEY_ATTACHMENT_NOTE_ID + " = " + note.get_id();
   return getAttachments(whereCondition);
 }
Exemple #6
0
  // Inserting or updating single note
  public Note updateNote(Note note, boolean updateLastModification) {
    SQLiteDatabase db = getDatabase(true);

    String content;
    if (note.isLocked()) {
      content = Security.encrypt(note.getContent(), prefs.getString(Constants.PREF_PASSWORD, ""));
    } else {
      content = note.getContent();
    }

    // To ensure note and attachments insertions are atomical and boost performances transaction are
    // used
    db.beginTransaction();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, note.getTitle());
    values.put(KEY_CONTENT, content);
    values.put(
        KEY_CREATION,
        note.getCreation() != null ? note.getCreation() : Calendar.getInstance().getTimeInMillis());
    values.put(
        KEY_LAST_MODIFICATION,
        updateLastModification
            ? Calendar.getInstance().getTimeInMillis()
            : (note.getLastModification() != null
                ? note.getLastModification()
                : Calendar.getInstance().getTimeInMillis()));
    values.put(KEY_ARCHIVED, note.isArchived());
    values.put(KEY_TRASHED, note.isTrashed());
    values.put(KEY_REMINDER, note.getAlarm());
    values.put(KEY_REMINDER_FIRED, note.isReminderFired());
    values.put(KEY_RECURRENCE_RULE, note.getRecurrenceRule());
    values.put(KEY_LATITUDE, note.getLatitude());
    values.put(KEY_LONGITUDE, note.getLongitude());
    values.put(KEY_ADDRESS, note.getAddress());
    values.put(KEY_CATEGORY, note.getCategory() != null ? note.getCategory().getId() : null);
    boolean locked = note.isLocked() != null ? note.isLocked() : false;
    values.put(KEY_LOCKED, locked);
    boolean checklist = note.isChecklist() != null ? note.isChecklist() : false;
    values.put(KEY_CHECKLIST, checklist);

    db.insertWithOnConflict(TABLE_NOTES, KEY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
    Log.d(Constants.TAG, "Updated note titled '" + note.getTitle() + "'");

    // Updating attachments
    List<Attachment> deletedAttachments = note.getAttachmentsListOld();
    for (Attachment attachment : note.getAttachmentsList()) {
      updateAttachment(
          note.get_id() != null ? note.get_id() : values.getAsLong(KEY_CREATION), attachment, db);
      deletedAttachments.remove(attachment);
    }
    // Remove from database deleted attachments
    for (Attachment attachmentDeleted : deletedAttachments) {
      db.delete(
          TABLE_ATTACHMENTS,
          KEY_ATTACHMENT_ID + " = ?",
          new String[] {String.valueOf(attachmentDeleted.getId())});
    }

    db.setTransactionSuccessful();
    db.endTransaction();

    // Fill the note with correct data before returning it
    note.setCreation(
        note.getCreation() != null ? note.getCreation() : values.getAsLong(KEY_CREATION));
    note.setLastModification(values.getAsLong(KEY_LAST_MODIFICATION));

    return note;
  }