Long press answer to make favorite

pull/198/head
M66B 4 years ago
parent 8bc5364828
commit 700110d194

@ -135,9 +135,11 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
if (composable) if (composable)
popupMenu.getMenu().add(Menu.NONE, R.string.title_compose, 1, R.string.title_compose); popupMenu.getMenu().add(Menu.NONE, R.string.title_compose, 1, R.string.title_compose);
popupMenu.getMenu().add(Menu.NONE, R.string.title_answer_hide, 2, R.string.title_answer_hide) popupMenu.getMenu().add(Menu.NONE, R.string.title_answer_favorite, 2, R.string.title_answer_favorite)
.setCheckable(true).setChecked(answer.favorite);
popupMenu.getMenu().add(Menu.NONE, R.string.title_answer_hide, 3, R.string.title_answer_hide)
.setCheckable(true).setChecked(answer.hide); .setCheckable(true).setChecked(answer.hide);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 3, R.string.title_copy); popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
@ -146,6 +148,9 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
if (itemId == R.string.title_compose) { if (itemId == R.string.title_compose) {
onActionCompose(); onActionCompose();
return true; return true;
} else if (itemId == R.string.title_answer_favorite) {
onActionFavorite(!item.isChecked());
return true;
} else if (itemId == R.string.title_answer_hide) { } else if (itemId == R.string.title_answer_hide) {
onActionHide(!item.isChecked()); onActionHide(!item.isChecked());
return true; return true;
@ -162,6 +167,30 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
.putExtra("answer", answer.id)); .putExtra("answer", answer.id));
} }
private void onActionFavorite(boolean favorite) {
Bundle args = new Bundle();
args.putLong("id", answer.id);
args.putBoolean("favorite", favorite);
new SimpleTask<Boolean>() {
@Override
protected Boolean onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean favorite = args.getBoolean("favorite");
DB db = DB.getInstance(context);
db.answer().setAnswerFavorite(id, favorite);
return favorite;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "answer:favorite");
}
private void onActionHide(boolean hide) { private void onActionHide(boolean hide) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", answer.id); args.putLong("id", answer.id);
@ -183,7 +212,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
} }
}.execute(context, owner, args, "rule:enable"); }.execute(context, owner, args, "answer:hide");
} }
private void onActionCopy() { private void onActionCopy() {

@ -66,6 +66,9 @@ public interface DaoAnswer {
@Update @Update
int updateAnswer(EntityAnswer answer); int updateAnswer(EntityAnswer answer);
@Query("UPDATE answer SET favorite = :favorite WHERE id = :id AND NOT (favorite IS :favorite)")
int setAnswerFavorite(long id, boolean favorite);
@Query("UPDATE answer SET hide = :hide WHERE id = :id AND NOT (hide IS :hide)") @Query("UPDATE answer SET hide = :hide WHERE id = :id AND NOT (hide IS :hide)")
int setAnswerHidden(long id, boolean hide); int setAnswerHidden(long id, boolean hide);

Loading…
Cancel
Save