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);
}
});
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations