Search in sources :

Example 1 with Note

use of de.djuelg.neuronizer.domain.model.preview.Note in project Neuronizer by djuelg.

the class AddNoteInteractorImpl method run.

@Override
public void run() {
    final int position = repository.preview().count();
    // try to insert with new UUID on failure
    Note item = new Note(title, position);
    while (!repository.note().insert(item)) {
        item = new Note(title, position);
    }
    final String uuid = item.getUuid();
    final String title = item.getTitle();
    // notify on the main thread that we have inserted this item
    mMainThread.post(new Runnable() {

        @Override
        public void run() {
            callback.onNoteAdded(uuid, title);
        }
    });
}
Also used : Note(de.djuelg.neuronizer.domain.model.preview.Note)

Example 2 with Note

use of de.djuelg.neuronizer.domain.model.preview.Note in project Neuronizer by djuelg.

the class NoteRepositoryImpl method get.

@Override
public Optional<Note> get(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    Optional<NoteDAO> noteDAO = Optional.fromNullable(realm.where(NoteDAO.class).equalTo("uuid", uuid).findFirst());
    Optional<Note> note = noteDAO.transform(new NoteDAOConverter());
    realm.close();
    return note;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) Note(de.djuelg.neuronizer.domain.model.preview.Note) NoteDAOConverter(de.djuelg.neuronizer.storage.converter.NoteDAOConverter) Realm(io.realm.Realm)

Example 3 with Note

use of de.djuelg.neuronizer.domain.model.preview.Note in project Neuronizer by djuelg.

the class PreviewViewModel method bindViewHolder.

@Override
public void bindViewHolder(FlexibleAdapter adapter, ViewHolder holder, int position, List payloads) {
    DateFormat date = SimpleDateFormat.getDateInstance();
    DateFormat time = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
    String title = holder.getFrontView().getResources().getString(R.string.preview_title, getTitle(), getImportance());
    // holder.title.setText(getTitle());
    holder.title.setText(title);
    holder.lastChange.setText(DateUtils.isToday(getChangedAt().getTime()) ? time.format(getChangedAt()) : date.format(getChangedAt()));
    holder.header.setText(preview.getSubtitle());
    holder.items.setText(preview.getDetails());
    if (preview.getBaseItem() instanceof Note) {
        holder.header.setVisibility(GONE);
        holder.typeIcon.setImageResource(R.drawable.ic_note_gray_22dp);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Note(de.djuelg.neuronizer.domain.model.preview.Note)

Example 4 with Note

use of de.djuelg.neuronizer.domain.model.preview.Note in project Neuronizer by djuelg.

the class PreviewFragment method editItem.

private void editItem(int position) {
    PreviewViewModel previewVM = mAdapter.getItem(position);
    if (previewVM != null) {
        BaseModel preview = previewVM.getPreview().getBaseItem();
        if (preview instanceof TodoList) {
            showEditTodoListDialog(this, preview.getUuid(), preview.getTitle(), preview.getPosition());
        } else if (preview instanceof Note) {
            showEditNoteDialog(this, preview.getUuid(), preview.getTitle(), preview.getPosition());
        }
        mAdapter.notifyItemChanged(position);
    }
}
Also used : BaseModel(de.djuelg.neuronizer.domain.model.BaseModel) PreviewViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.PreviewViewModel) Note(de.djuelg.neuronizer.domain.model.preview.Note) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 5 with Note

use of de.djuelg.neuronizer.domain.model.preview.Note in project Neuronizer by djuelg.

the class NoteRepositoryImpl method getAll.

@Override
public List<Note> getAll() {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<NoteDAO> noteDAOs = realm.where(NoteDAO.class).findAll();
    List<Note> notes = new ArrayList<>(noteDAOs.size());
    for (NoteDAO dao : noteDAOs) {
        notes.add(RealmConverter.convert(dao));
    }
    realm.close();
    return notes;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) Note(de.djuelg.neuronizer.domain.model.preview.Note) ArrayList(java.util.ArrayList) Realm(io.realm.Realm)

Aggregations

Note (de.djuelg.neuronizer.domain.model.preview.Note)7 NoteDAO (de.djuelg.neuronizer.storage.model.NoteDAO)2 Realm (io.realm.Realm)2 BaseModel (de.djuelg.neuronizer.domain.model.BaseModel)1 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)1 PreviewViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.PreviewViewModel)1 NoteDAOConverter (de.djuelg.neuronizer.storage.converter.NoteDAOConverter)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1