コード例 #1
0
ファイル: EntryService.java プロジェクト: Raak/EnhRick
  /**
   * Edits an {@link com.noiraak.enhrick.model.Entry Entry} at the specified index with the given
   * String and adds it to the corresponding file on the disk.
   *
   * @param newText The content of the edited {@link com.noiraak.enhrick.model.Entry Entry}
   * @param selectedIndex The index of the {@link com.noiraak.enhrick.model.Entry Entry} to edit
   * @return the list with including the newly generated {@link com.noiraak.enhrick.model.Entry
   *     Entry}
   */
  public List<Entry> editEntry(String newText, int selectedIndex) {
    List<Entry> clonedEntries = new ArrayList<>(entries);
    Entry entry = entries.get(selectedIndex);
    entry.setText(newText + "\n");
    entry.setModified(System.currentTimeMillis());

    fileManager.saveEditedEntry(entry, selectedIndex, FileConfigurationProvider.getFilePath());
    // For some bizarre reason fileManager.editEntry() completely empties entries sometimes - hence
    // the cloned list.
    if (entries.size() < clonedEntries.size()) {
      entries = clonedEntries;
    }
    entries.set(selectedIndex, entry);

    return entries;
  }