Search in sources :

Example 1 with NotePreview

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

the class PreviewFragment method permanentDeleteItem.

private void permanentDeleteItem(int position) {
    if (mAdapter == null || mPresenter == null)
        return;
    PreviewViewModel adapterItem = mAdapter.getItem(position);
    mAdapter.clearSelection();
    if (adapterItem != null) {
        if (adapterItem.getPreview() instanceof TodoListPreview) {
            mPresenter.deleteTodoList(adapterItem.getUuid());
        } else if (adapterItem.getPreview() instanceof NotePreview) {
            mPresenter.deleteNote(adapterItem.getUuid());
        }
        mAdapter.removeItem(position);
    }
}
Also used : PreviewViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.PreviewViewModel) NotePreview(de.djuelg.neuronizer.domain.model.preview.NotePreview) TodoListPreview(de.djuelg.neuronizer.domain.model.preview.TodoListPreview)

Example 2 with NotePreview

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

the class PreviewRepositoryImpl method getAll.

@Override
public Iterable<Preview> getAll(ItemsPerPreview itemsPerPreview) {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListDAO> allTodoListDAO = realm.where(TodoListDAO.class).findAllSorted("position", Sort.DESCENDING);
    RealmResults<NoteDAO> allNoteDAO = realm.where(NoteDAO.class).findAllSorted("position", Sort.DESCENDING);
    List<Preview> previews = new ArrayList<>(allTodoListDAO.size() + allNoteDAO.size());
    for (TodoListDAO todoListDAO : allTodoListDAO) {
        previews.add(constructPreview(realm, todoListDAO, itemsPerPreview));
    }
    for (NoteDAO noteDAO : allNoteDAO) {
        previews.add(new NotePreview(RealmConverter.convert(noteDAO)));
    }
    realm.close();
    return previews;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) NotePreview(de.djuelg.neuronizer.domain.model.preview.NotePreview) ArrayList(java.util.ArrayList) Preview(de.djuelg.neuronizer.domain.model.preview.Preview) NotePreview(de.djuelg.neuronizer.domain.model.preview.NotePreview) ItemsPerPreview(de.djuelg.neuronizer.domain.model.preview.ItemsPerPreview) TodoListPreview(de.djuelg.neuronizer.domain.model.preview.TodoListPreview) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO)

Aggregations

NotePreview (de.djuelg.neuronizer.domain.model.preview.NotePreview)2 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)2 ItemsPerPreview (de.djuelg.neuronizer.domain.model.preview.ItemsPerPreview)1 Preview (de.djuelg.neuronizer.domain.model.preview.Preview)1 PreviewViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.PreviewViewModel)1 NoteDAO (de.djuelg.neuronizer.storage.model.NoteDAO)1 TodoListDAO (de.djuelg.neuronizer.storage.model.TodoListDAO)1 Realm (io.realm.Realm)1 ArrayList (java.util.ArrayList)1