use of de.djuelg.neuronizer.domain.model.preview.TodoList in project Neuronizer by djuelg.
the class EditItemInteractorImpl method run.
@Override
public void run() {
final Optional<TodoListHeader> header = repository.todoList().getHeaderById(parentHeaderUuid);
final Optional<TodoListItem> outDatedItem = repository.todoList().getItemById(uuid);
if (!header.isPresent() || !outDatedItem.isPresent()) {
throw new InputMismatchException("Header, or Item were not existing!");
}
final TodoListItem updatedItem = outDatedItem.get().update(title, position, important, details, done, parentHeaderUuid);
repository.todoList().update(updatedItem);
final Optional<TodoList> todoList = repository.todoList().getTodoListById(updatedItem.getParentTodoListUuid());
final TodoListItem itemFromUI = new TodoListItem(uuid, title, outDatedItem.get().getCreatedAt(), outDatedItem.get().getChangedAt(), position, important, details, done, outDatedItem.get().getParentTodoListUuid(), parentHeaderUuid);
if (todoList.isPresent() && !outDatedItem.get().equals(itemFromUI))
repository.todoList().update(todoList.get().updateLastChange());
mMainThread.post(new Runnable() {
@Override
public void run() {
callback.onItemUpdated(updatedItem);
}
});
}
use of de.djuelg.neuronizer.domain.model.preview.TodoList in project Neuronizer by djuelg.
the class TodoListAppWidgetProvider method createRemoteViews.
private static RemoteViews createRemoteViews(Context context, int appWidgetId, String repositoryName, String uuid) {
Optional<TodoList> todoList = new TodoListRepositoryImpl(repositoryName).getTodoListById(uuid);
String title = todoList.isPresent() ? todoList.get().getTitle() : context.getResources().getString(R.string.widget_empty);
// Pending intent, used to start correct fragment from widget button
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(KEY_SWITCH_FRAGMENT, KEY_TODO_LIST);
intent.putExtra(KEY_WIDGET_REPOSITORY, repositoryName);
intent.putExtra(KEY_UUID, uuid);
intent.putExtra(KEY_TITLE, title);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// RemoteView setup fro WidgetListFactory
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_todo_list);
remoteViews.setOnClickPendingIntent(R.id.widget_todo_list_bar_container, pendingIntent);
remoteViews.setOnClickPendingIntent(R.id.widget_todo_list_bar_button, pendingIntent);
remoteViews.setTextViewText(R.id.widget_todo_list_bar_title, title);
return remoteViews;
}
use of de.djuelg.neuronizer.domain.model.preview.TodoList in project Neuronizer by djuelg.
the class PreviewRepositoryImpl method constructPreview.
private TodoListPreview constructPreview(Realm realm, TodoListDAO todoListDAO, ItemsPerPreview itemsPerPreview) {
TodoList todoList = RealmConverter.convert(todoListDAO);
Optional<TodoListHeaderDAO> headerDAO = Optional.fromNullable(realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", todoListDAO.getUuid()).findAllSorted("position", Sort.DESCENDING).where().findFirst());
TodoListHeader header = headerDAO.transform(new TodoListHeaderDAOConverter()).orNull();
List<TodoListItem> items = getItemPreviewOfHeader(realm, header, itemsPerPreview);
return new TodoListPreview(todoList, header, items);
}
use of de.djuelg.neuronizer.domain.model.preview.TodoList in project Neuronizer by djuelg.
the class TodoListRepositoryImpl method getTodoListById.
@Override
public Optional<TodoList> getTodoListById(String uuid) {
Realm realm = Realm.getInstance(configuration);
Optional<TodoListDAO> todoListDAO = Optional.fromNullable(realm.where(TodoListDAO.class).equalTo("uuid", uuid).findFirst());
Optional<TodoList> todoList = todoListDAO.transform(new TodoListDAOConverter());
realm.close();
return todoList;
}
use of de.djuelg.neuronizer.domain.model.preview.TodoList in project Neuronizer by djuelg.
the class TodoListRepositoryImpl method getAll.
@Override
public List<TodoList> getAll() {
Realm realm = Realm.getInstance(configuration);
RealmResults<TodoListDAO> todoListDAOs = realm.where(TodoListDAO.class).findAll();
List<TodoList> todoLists = new ArrayList<>(todoListDAOs.size());
for (TodoListDAO dao : todoListDAOs) {
todoLists.add(RealmConverter.convert(dao));
}
realm.close();
return todoLists;
}
Aggregations