Beispiel #1
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;
  }
Beispiel #2
0
  /** Retrieves statistics data based on app usage */
  public Stats getStats() {
    Stats mStats = new Stats();

    // Categories
    mStats.setCategories(getCategories().size());

    // Everything about notes and their text stats
    int notesActive = 0,
        notesArchived = 0,
        notesTrashed = 0,
        reminders = 0,
        remindersFuture = 0,
        checklists = 0,
        notesMasked = 0,
        tags = 0,
        locations = 0;
    int totalWords = 0, totalChars = 0, maxWords = 0, maxChars = 0, avgWords = 0, avgChars = 0;
    int words, chars;
    List<Note> notes = getAllNotes(false);
    for (Note note : notes) {
      if (note.isTrashed()) {
        notesTrashed++;
      } else if (note.isArchived()) {
        notesArchived++;
      } else {
        notesActive++;
      }
      if (note.getAlarm() != null && Long.parseLong(note.getAlarm()) > 0) {
        if (Long.parseLong(note.getAlarm()) > Calendar.getInstance().getTimeInMillis()) {
          remindersFuture++;
        } else {
          reminders++;
        }
      }
      if (note.isChecklist()) {
        checklists++;
      }
      if (note.isLocked()) {
        notesMasked++;
      }
      tags += TagsHelper.retrieveTags(note).size();
      if (note.getLongitude() != null && note.getLongitude() != 0) {
        locations++;
      }
      words = getWords(note);
      chars = getChars(note);
      if (words > maxWords) {
        maxWords = words;
      }
      if (chars > maxChars) {
        maxChars = chars;
      }
      totalWords += words;
      totalChars += chars;
    }
    mStats.setNotesActive(notesActive);
    mStats.setNotesArchived(notesArchived);
    mStats.setNotesTrashed(notesTrashed);
    mStats.setReminders(reminders);
    mStats.setRemindersFutures(remindersFuture);
    mStats.setNotesChecklist(checklists);
    mStats.setNotesMasked(notesMasked);
    mStats.setTags(tags);
    mStats.setLocation(locations);
    avgWords = totalWords / (notes.size() != 0 ? notes.size() : 1);
    avgChars = totalChars / (notes.size() != 0 ? notes.size() : 1);

    mStats.setWords(totalWords);
    mStats.setWordsMax(maxWords);
    mStats.setWordsAvg(avgWords);
    mStats.setChars(totalChars);
    mStats.setCharsMax(maxChars);
    mStats.setCharsAvg(avgChars);

    // Everything about attachments
    int attachmentsAll = 0, images = 0, videos = 0, audioRecordings = 0, sketches = 0, files = 0;
    List<Attachment> attachments = getAllAttachments();
    for (Attachment attachment : attachments) {
      if (Constants.MIME_TYPE_IMAGE.equals(attachment.getMime_type())) {
        images++;
      } else if (Constants.MIME_TYPE_VIDEO.equals(attachment.getMime_type())) {
        videos++;
      } else if (Constants.MIME_TYPE_AUDIO.equals(attachment.getMime_type())) {
        audioRecordings++;
      } else if (Constants.MIME_TYPE_SKETCH.equals(attachment.getMime_type())) {
        sketches++;
      } else if (Constants.MIME_TYPE_FILES.equals(attachment.getMime_type())) {
        files++;
      }
    }
    mStats.setAttachments(attachmentsAll);
    mStats.setImages(images);
    mStats.setVideos(videos);
    mStats.setAudioRecordings(audioRecordings);
    mStats.setSketches(sketches);
    mStats.setFiles(files);

    return mStats;
  }