use of com.faltenreich.diaguard.shared.event.data.TagSavedEvent in project Diaguard by Faltenreich.
the class TagEditFragment method store.
private void store() {
String name = getBinding().input.getText().toString();
DataLoader.getInstance().load(getContext(), new DataLoaderListener<TagResult>() {
@Override
public TagResult onShouldLoad(Context context) {
if (StringUtils.isBlank(name)) {
return new TagResult(null, Error.EMPTY);
} else if (TagDao.getInstance().getByName(name) != null) {
return new TagResult(null, Error.DUPLICATE);
} else {
Tag tag = new Tag();
tag.setName(name);
TagDao.getInstance().createOrUpdate(tag);
return new TagResult(tag, null);
}
}
@Override
public void onDidLoad(TagResult result) {
if (result.tag != null) {
Events.post(new TagSavedEvent(result.tag));
dismiss();
} else {
String error = getString(result.error != null ? result.error.textResId : R.string.error_unexpected);
getBinding().input.setError(error);
}
}
});
}
Aggregations