Added favorite answers

pull/172/head
M66B 5 years ago
parent 6b67e3cf63
commit 6bc3488d01

File diff suppressed because it is too large Load Diff

@ -80,7 +80,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
private void bindTo(EntityAnswer answer) {
view.setAlpha(answer.hide ? Helper.LOW_LIGHT : 1.0f);
tvName.setText(answer.name);
tvName.setText(answer.toString());
}
@Override
@ -300,8 +300,9 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
EntityAnswer answer = items.get(position);
holder.unwire();
holder.bindTo(answer);
holder.wire();
}

@ -2974,7 +2974,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
int order = 0;
for (EntityAnswer answer : answers)
popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.name);
popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.toString());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override

@ -56,7 +56,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 130,
version = 131,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -1254,6 +1254,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `fts` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(130, 131) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `answer` ADD COLUMN `favorite` INTEGER NOT NULL DEFAULT 0");
}
})
.build();
}

@ -31,14 +31,14 @@ import java.util.List;
public interface DaoAnswer {
@Query("SELECT * FROM answer" +
" WHERE :all OR NOT hide" +
" ORDER BY name COLLATE NOCASE")
" ORDER BY -favorite, name COLLATE NOCASE")
List<EntityAnswer> getAnswers(boolean all);
@Query("SELECT * FROM answer WHERE id = :id")
EntityAnswer getAnswer(long id);
@Query("SELECT * FROM answer" +
" ORDER BY name COLLATE NOCASE")
" ORDER BY -favorite, name COLLATE NOCASE")
LiveData<List<EntityAnswer>> liveAnswers();
@Query("SELECT COUNT(*) FROM answer" +

@ -48,6 +48,8 @@ public class EntityAnswer implements Serializable {
@NonNull
public String name;
@NonNull
public Boolean favorite;
@NonNull
public Boolean hide;
@NonNull
public String text;
@ -119,6 +121,7 @@ public class EntityAnswer implements Serializable {
if (obj instanceof EntityAnswer) {
EntityAnswer other = (EntityAnswer) obj;
return (this.name.equals(other.name) &&
this.favorite.equals(other.favorite) &&
this.hide.equals(other.hide) &&
this.text.equals(other.text)
);
@ -129,6 +132,6 @@ public class EntityAnswer implements Serializable {
@NonNull
@Override
public String toString() {
return name;
return name + (favorite ? " ★" : "");
}
}

@ -49,6 +49,7 @@ import static android.app.Activity.RESULT_OK;
public class FragmentAnswer extends FragmentBase {
private ViewGroup view;
private EditText etName;
private CheckBox cbFavorite;
private CheckBox cbHide;
private EditTextCompose etText;
private ImageButton ibInfo;
@ -85,6 +86,7 @@ public class FragmentAnswer extends FragmentBase {
// Get controls
etName = view.findViewById(R.id.etName);
cbFavorite = view.findViewById(R.id.cbFavorite);
cbHide = view.findViewById(R.id.cbHide);
etText = view.findViewById(R.id.etText);
ibInfo = view.findViewById(R.id.ibInfo);
@ -168,6 +170,7 @@ public class FragmentAnswer extends FragmentBase {
@Override
protected void onExecuted(Bundle args, EntityAnswer answer) {
etName.setText(answer == null ? null : answer.name);
cbFavorite.setChecked(answer == null ? false : answer.favorite);
cbHide.setChecked(answer == null ? false : answer.hide);
etText.setText(answer == null ? null : HtmlHelper.fromHtml(answer.text));
bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE);
@ -199,6 +202,7 @@ public class FragmentAnswer extends FragmentBase {
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", etName.getText().toString());
args.putBoolean("favorite", cbFavorite.isChecked());
args.putBoolean("hide", cbHide.isChecked());
args.putString("text", HtmlHelper.toHtml(etText.getText()));
@ -217,6 +221,7 @@ public class FragmentAnswer extends FragmentBase {
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
String name = args.getString("name");
boolean favorite = args.getBoolean("favorite");
boolean hide = args.getBoolean("hide");
String text = args.getString("text");
@ -224,12 +229,14 @@ public class FragmentAnswer extends FragmentBase {
if (id < 0) {
EntityAnswer answer = new EntityAnswer();
answer.name = name;
answer.favorite = favorite;
answer.hide = hide;
answer.text = text;
answer.id = db.answer().insertAnswer(answer);
} else {
EntityAnswer answer = db.answer().getAnswer(id);
answer.name = name;
answer.favorite = favorite;
answer.hide = hide;
answer.text = text;
db.answer().updateAnswer(answer);

@ -21,6 +21,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbFavorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:text="@string/title_answer_favorite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />
<CheckBox
android:id="@+id/cbHide"
android:layout_width="wrap_content"
@ -29,7 +39,7 @@
android:layout_marginTop="6dp"
android:text="@string/title_answer_hide"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />
app:layout_constraintTop_toBottomOf="@+id/cbFavorite" />
<View
android:id="@+id/vSeparator"

@ -813,6 +813,7 @@
<string name="title_answer_caption">Edit template</string>
<string name="title_answer_reply">Reply template</string>
<string name="title_answer_name">Template name</string>
<string name="title_answer_favorite">Favorite</string>
<string name="title_answer_hide">Hide from menus</string>
<string name="title_answer_text">Template text</string>
<string name="title_answer_template_name">$name$ will be replaced by the sender full name</string>

Loading…
Cancel
Save