Allow hiding answers

This commit is contained in:
M66B 2019-04-20 10:35:30 +02:00
parent 8cacc15a37
commit a1c740676e
11 changed files with 1745 additions and 8 deletions

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -72,6 +72,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);
}

View File

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

View File

@ -51,7 +51,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 70,
version = 71,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -738,6 +738,13 @@ public abstract class DB extends RoomDatabase {
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();
}

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +18,16 @@
app:layout_constraintStart_toStartOf="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
android:id="@+id/vSeparator"
android:layout_width="match_parent"
@ -25,7 +35,7 @@
android:layout_marginTop="6dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />
app:layout_constraintTop_toBottomOf="@+id/cbHide" />
<EditText
android:id="@+id/etText"

View File

@ -469,6 +469,7 @@
<string name="title_answer_reply">Reply template</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_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>