Allow hiding answers

pull/155/head
M66B 5 years ago
parent 8cacc15a37
commit a1c740676e

File diff suppressed because it is too large Load Diff

@ -535,7 +535,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
// Answers // Answers
JSONArray janswers = new JSONArray(); JSONArray janswers = new JSONArray();
for (EntityAnswer answer : db.answer().getAnswers()) for (EntityAnswer answer : db.answer().getAnswers(true))
janswers.put(answer.toJSON()); janswers.put(answer.toJSON());
// Settings // Settings

@ -72,6 +72,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
} }
private void bindTo(EntityAnswer answer) { private void bindTo(EntityAnswer answer) {
view.setAlpha(answer.hide ? Helper.LOW_LIGHT : 1.0f);
tvName.setText(answer.name); tvName.setText(answer.name);
} }

@ -2960,7 +2960,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
new SimpleTask<List<EntityAnswer>>() { new SimpleTask<List<EntityAnswer>>() {
@Override @Override
protected List<EntityAnswer> onExecute(Context context, Bundle args) { protected List<EntityAnswer> onExecute(Context context, Bundle args) {
return DB.getInstance(context).answer().getAnswers(); return DB.getInstance(context).answer().getAnswers(false);
} }
@Override @Override

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

@ -29,8 +29,9 @@ import java.util.List;
@Dao @Dao
public interface DaoAnswer { public interface DaoAnswer {
@Query("SELECT * FROM answer") @Query("SELECT * FROM answer" +
List<EntityAnswer> getAnswers(); " WHERE :all OR NOT hide")
List<EntityAnswer> getAnswers(boolean all);
@Query("SELECT * FROM answer WHERE id = :id") @Query("SELECT * FROM answer WHERE id = :id")
EntityAnswer getAnswer(long id); EntityAnswer getAnswer(long id);

@ -48,6 +48,8 @@ public class EntityAnswer implements Serializable {
@NonNull @NonNull
public String name; public String name;
@NonNull @NonNull
public Boolean hide;
@NonNull
public String text; public String text;
static String getAnswerText(DB db, long id, Address[] from) { static String getAnswerText(DB db, long id, Address[] from) {
@ -88,6 +90,7 @@ public class EntityAnswer implements Serializable {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("id", id); json.put("id", id);
json.put("name", name); json.put("name", name);
json.put("hide", hide);
json.put("text", text); json.put("text", text);
return json; return json;
} }
@ -96,6 +99,7 @@ public class EntityAnswer implements Serializable {
EntityAnswer answer = new EntityAnswer(); EntityAnswer answer = new EntityAnswer();
// id // id
answer.name = json.getString("name"); answer.name = json.getString("name");
answer.hide = (json.has("hide") && json.getBoolean("hide"));
answer.text = json.getString("text"); answer.text = json.getString("text");
return answer; return answer;
} }
@ -105,6 +109,7 @@ public class EntityAnswer implements Serializable {
if (obj instanceof EntityAnswer) { if (obj instanceof EntityAnswer) {
EntityAnswer other = (EntityAnswer) obj; EntityAnswer other = (EntityAnswer) obj;
return (this.name.equals(other.name) && return (this.name.equals(other.name) &&
this.hide.equals(other.hide) &&
this.text.equals(other.text) this.text.equals(other.text)
); );
} }

@ -26,6 +26,7 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -37,6 +38,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
public class FragmentAnswer extends FragmentBase { public class FragmentAnswer extends FragmentBase {
private ViewGroup view; private ViewGroup view;
private EditText etName; private EditText etName;
private CheckBox cbHide;
private EditText etText; private EditText etText;
private BottomNavigationView bottom_navigation; private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
@ -62,7 +64,7 @@ public class FragmentAnswer extends FragmentBase {
// Get controls // Get controls
etName = view.findViewById(R.id.etName); etName = view.findViewById(R.id.etName);
etText = view.findViewById(R.id.etText); cbHide = view.findViewById(R.id.cbHide);
etText = view.findViewById(R.id.etText); etText = view.findViewById(R.id.etText);
bottom_navigation = view.findViewById(R.id.bottom_navigation); bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
@ -108,6 +110,7 @@ public class FragmentAnswer extends FragmentBase {
@Override @Override
protected void onExecuted(Bundle args, EntityAnswer answer) { protected void onExecuted(Bundle args, EntityAnswer answer) {
etName.setText(answer == null ? null : answer.name); etName.setText(answer == null ? null : answer.name);
cbHide.setChecked(answer == null ? false : answer.hide);
etText.setText(answer == null ? null : HtmlHelper.fromHtml(answer.text)); etText.setText(answer == null ? null : HtmlHelper.fromHtml(answer.text));
bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE); bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE);
@ -169,6 +172,7 @@ public class FragmentAnswer extends FragmentBase {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
args.putString("name", etName.getText().toString()); args.putString("name", etName.getText().toString());
args.putBoolean("hide", cbHide.isChecked());
args.putString("text", HtmlHelper.toHtml(etText.getText())); args.putString("text", HtmlHelper.toHtml(etText.getText()));
new SimpleTask<Void>() { new SimpleTask<Void>() {
@ -186,17 +190,20 @@ public class FragmentAnswer extends FragmentBase {
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
String name = args.getString("name"); String name = args.getString("name");
boolean hide = args.getBoolean("hide");
String text = args.getString("text"); String text = args.getString("text");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
if (id < 0) { if (id < 0) {
EntityAnswer answer = new EntityAnswer(); EntityAnswer answer = new EntityAnswer();
answer.name = name; answer.name = name;
answer.hide = hide;
answer.text = text; answer.text = text;
answer.id = db.answer().insertAnswer(answer); answer.id = db.answer().insertAnswer(answer);
} else { } else {
EntityAnswer answer = db.answer().getAnswer(id); EntityAnswer answer = db.answer().getAnswer(id);
answer.name = name; answer.name = name;
answer.hide = hide;
answer.text = text; answer.text = text;
db.answer().updateAnswer(answer); db.answer().updateAnswer(answer);
} }

@ -305,7 +305,7 @@ public class FragmentRule extends FragmentBase {
EntityFolder.sort(context, data.folders, true); EntityFolder.sort(context, data.folders, true);
data.identities = db.identity().getIdentities(aid); data.identities = db.identity().getIdentities(aid);
data.answers = db.answer().getAnswers(); data.answers = db.answer().getAnswers(false);
return data; return data;
} }

@ -18,6 +18,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbHide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:text="@string/title_answer_hide"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />
<View <View
android:id="@+id/vSeparator" android:id="@+id/vSeparator"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -25,7 +35,7 @@
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:background="?attr/colorSeparator" android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" /> app:layout_constraintTop_toBottomOf="@+id/cbHide" />
<EditText <EditText
android:id="@+id/etText" android:id="@+id/etText"

@ -469,6 +469,7 @@
<string name="title_answer_reply">Reply template</string> <string name="title_answer_reply">Reply template</string>
<string name="title_answer_name">Template name</string> <string name="title_answer_name">Template name</string>
<string name="title_answer_hide">Hide from menus</string>
<string name="title_answer_text">Template text</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> <string name="title_answer_template_name">$name$ will be replaced by the sender full name</string>
<string name="title_answer_template_email">$email$ will be replaced by the sender email address</string> <string name="title_answer_template_email">$email$ will be replaced by the sender email address</string>

Loading…
Cancel
Save