Added global keywords

pull/209/head
M66B 2 years ago
parent 10dd18a16a
commit d2fb3b154c

@ -8206,16 +8206,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final long id = getArguments().getLong("id"); final long id = getArguments().getLong("id");
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_keyword_manage, null); final Context context = getContext();
final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_keyword_manage, null);
final RecyclerView rvKeyword = dview.findViewById(R.id.rvKeyword); final RecyclerView rvKeyword = dview.findViewById(R.id.rvKeyword);
final FloatingActionButton fabAdd = dview.findViewById(R.id.fabAdd); final FloatingActionButton fabAdd = dview.findViewById(R.id.fabAdd);
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
rvKeyword.setHasFixedSize(false); rvKeyword.setHasFixedSize(false);
final LinearLayoutManager llm = new LinearLayoutManager(getContext()); final LinearLayoutManager llm = new LinearLayoutManager(context);
rvKeyword.setLayoutManager(llm); rvKeyword.setLayoutManager(llm);
final AdapterKeyword adapter = new AdapterKeyword(getContext(), getViewLifecycleOwner()); final AdapterKeyword adapter = new AdapterKeyword(context, getViewLifecycleOwner());
rvKeyword.setAdapter(adapter); rvKeyword.setAdapter(adapter);
fabAdd.setOnClickListener(new View.OnClickListener() { fabAdd.setOnClickListener(new View.OnClickListener() {
@ -8232,16 +8233,26 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
DB db = DB.getInstance(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
DB db = DB.getInstance(context);
db.message().liveMessageKeywords(id).observe(getViewLifecycleOwner(), new Observer<TupleKeyword.Persisted>() { db.message().liveMessageKeywords(id).observe(getViewLifecycleOwner(), new Observer<TupleKeyword.Persisted>() {
@Override @Override
public void onChanged(TupleKeyword.Persisted data) { public void onChanged(TupleKeyword.Persisted data) {
String global = prefs.getString("global_keywords", null);
if (global != null) {
List<String> available = new ArrayList<>();
available.addAll(Arrays.asList(global.split(" ")));
if (data != null && data.available != null)
available.addAll(Arrays.asList(data.available));
data.available = available.toArray(new String[0]);
}
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
adapter.set(id, TupleKeyword.from(getContext(), data)); adapter.set(id, TupleKeyword.from(context, data));
} }
}); });
return new AlertDialog.Builder(getContext()) return new AlertDialog.Builder(context)
.setIcon(R.drawable.twotone_label_important_24) .setIcon(R.drawable.twotone_label_important_24)
.setTitle(R.string.title_manage_keywords) .setTitle(R.string.title_manage_keywords)
.setView(dview) .setView(dview)

@ -197,6 +197,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swExactAlarms; private SwitchCompat swExactAlarms;
private SwitchCompat swInfra; private SwitchCompat swInfra;
private SwitchCompat swDupMsgId; private SwitchCompat swDupMsgId;
private EditText etKeywords;
private SwitchCompat swTestIab; private SwitchCompat swTestIab;
private Button btnImportProviders; private Button btnImportProviders;
private TextView tvProcessors; private TextView tvProcessors;
@ -243,7 +244,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"use_modseq", "uid_command", "perform_expunge", "uid_expunge", "use_modseq", "uid_command", "perform_expunge", "uid_expunge",
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", "use_top", "auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", "use_top",
"keep_alive_poll", "empty_pool", "idle_done", "logarithmic_backoff", "keep_alive_poll", "empty_pool", "idle_done", "logarithmic_backoff",
"exact_alarms", "infra", "dkim_verify", "dup_msgids", "test_iab" "exact_alarms", "infra", "dkim_verify", "dup_msgids", "global_keywords", "test_iab"
}; };
private final static String[] RESET_QUESTIONS = new String[]{ private final static String[] RESET_QUESTIONS = new String[]{
@ -392,6 +393,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swExactAlarms = view.findViewById(R.id.swExactAlarms); swExactAlarms = view.findViewById(R.id.swExactAlarms);
swInfra = view.findViewById(R.id.swInfra); swInfra = view.findViewById(R.id.swInfra);
swDupMsgId = view.findViewById(R.id.swDupMsgId); swDupMsgId = view.findViewById(R.id.swDupMsgId);
etKeywords = view.findViewById(R.id.etKeywords);
swTestIab = view.findViewById(R.id.swTestIab); swTestIab = view.findViewById(R.id.swTestIab);
btnImportProviders = view.findViewById(R.id.btnImportProviders); btnImportProviders = view.findViewById(R.id.btnImportProviders);
tvProcessors = view.findViewById(R.id.tvProcessors); tvProcessors = view.findViewById(R.id.tvProcessors);
@ -1347,6 +1349,32 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
etKeywords.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
String keywords = s.toString().trim();
String[] keyword = keywords.replaceAll("\\s+", " ").split(" ");
for (int i = 0; i < keyword.length; i++)
keyword[i] = MessageHelper.sanitizeKeyword(keyword[i]);
keywords = String.join(" ", keyword);
if (TextUtils.isEmpty(keywords))
prefs.edit().remove("global_keywords").apply();
else
prefs.edit().putString("global_keywords", keywords).apply();
}
});
swTestIab.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swTestIab.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1754,6 +1782,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
if ("vt_apikey".equals(key) || "send_host".equals(key)) if ("vt_apikey".equals(key) || "send_host".equals(key))
return; return;
if ("global_keywords".equals(key))
return;
setOptions(); setOptions();
} }
@ -1974,6 +2005,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swExactAlarms.setChecked(prefs.getBoolean("exact_alarms", true)); swExactAlarms.setChecked(prefs.getBoolean("exact_alarms", true));
swInfra.setChecked(prefs.getBoolean("infra", false)); swInfra.setChecked(prefs.getBoolean("infra", false));
swDupMsgId.setChecked(prefs.getBoolean("dup_msgids", false)); swDupMsgId.setChecked(prefs.getBoolean("dup_msgids", false));
etKeywords.setText(prefs.getString("global_keywords", null));
swTestIab.setChecked(prefs.getBoolean("test_iab", false)); swTestIab.setChecked(prefs.getBoolean("test_iab", false));
tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors())); tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors()));

@ -322,10 +322,10 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_advanced_privacy_risk" android:text="@string/title_advanced_privacy_risk"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning" android:textColor="?attr/colorWarning"
app:drawableTint="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLanguageTool" /> app:layout_constraintTop_toBottomOf="@id/swLanguageTool" />
@ -336,10 +336,10 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_open_in_new_12" android:drawableEnd="@drawable/twotone_open_in_new_12"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?android:attr/textColorLink"
android:text="@string/title_privacy_policy" android:text="@string/title_privacy_policy"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink" android:textColor="?android:attr/textColorLink"
app:drawableTint="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLanguageToolHint" /> app:layout_constraintTop_toBottomOf="@id/tvLanguageToolHint" />
@ -372,10 +372,10 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_open_in_new_12" android:drawableEnd="@drawable/twotone_open_in_new_12"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?android:attr/textColorLink"
android:text="@string/title_privacy_policy" android:text="@string/title_privacy_policy"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink" android:textColor="?android:attr/textColorLink"
app:drawableTint="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDeepL" /> app:layout_constraintTop_toBottomOf="@id/swDeepL" />
@ -408,10 +408,10 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_open_in_new_12" android:drawableEnd="@drawable/twotone_open_in_new_12"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?android:attr/textColorLink"
android:text="@string/title_privacy_policy" android:text="@string/title_privacy_policy"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink" android:textColor="?android:attr/textColorLink"
app:drawableTint="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swVirusTotal" /> app:layout_constraintTop_toBottomOf="@id/swVirusTotal" />
@ -620,10 +620,10 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_open_in_new_12" android:drawableEnd="@drawable/twotone_open_in_new_12"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?android:attr/textColorLink"
android:text="@string/title_advanced_sdcard" android:text="@string/title_advanced_sdcard"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink" android:textColor="?android:attr/textColorLink"
app:drawableTint="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLastCleanup" /> app:layout_constraintTop_toBottomOf="@id/tvLastCleanup" />
@ -672,12 +672,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawableStart="@drawable/twotone_warning_24" android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:gravity="center" android:gravity="center"
android:text="@string/title_setup_advanced" android:text="@string/title_setup_advanced"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="?attr/colorWarning" android:textColor="?attr/colorWarning"
android:textStyle="bold" android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -716,10 +716,10 @@
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:drawableEnd="@drawable/twotone_open_in_new_12" android:drawableEnd="@drawable/twotone_open_in_new_12"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?android:attr/textColorLink"
android:text="@string/title_advanced_experiments_hint" android:text="@string/title_advanced_experiments_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink" android:textColor="?android:attr/textColorLink"
app:drawableTint="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExperiments" /> app:layout_constraintTop_toBottomOf="@id/swExperiments" />
@ -910,11 +910,11 @@
android:drawableStart="@drawable/twotone_warning_24" android:drawableStart="@drawable/twotone_warning_24"
android:drawableEnd="@drawable/twotone_warning_24" android:drawableEnd="@drawable/twotone_warning_24"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:gravity="center" android:gravity="center"
android:text="@string/title_advanced_caption_debug" android:text="@string/title_advanced_caption_debug"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textStyle="bold" android:textStyle="bold"
app:drawableTint="?attr/colorWarning"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -962,8 +962,8 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:drawableStart="@drawable/twotone_warning_24" android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp" android:drawablePadding="6dp"
app:drawableTint="?attr/colorWarning"
android:text="@string/title_advanced_external_storage" android:text="@string/title_advanced_external_storage"
app:drawableTint="?attr/colorWarning"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swWorkManager" app:layout_constraintTop_toBottomOf="@id/swWorkManager"
@ -1648,6 +1648,7 @@
android:id="@+id/tvDkimVerifyHint" android:id="@+id/tvDkimVerifyHint"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginEnd="48dp" android:layout_marginEnd="48dp"
android:text="@string/title_advanced_usage_hint" android:text="@string/title_advanced_usage_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
@ -1668,6 +1669,18 @@
app:layout_constraintTop_toBottomOf="@id/tvDkimVerifyHint" app:layout_constraintTop_toBottomOf="@id/tvDkimVerifyHint"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<EditText
android:id="@+id/etKeywords"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:hint="Global keywords"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDupMsgId" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTestIab" android:id="@+id/swTestIab"
android:layout_width="0dp" android:layout_width="0dp"
@ -1676,7 +1689,7 @@
android:text="@string/title_advanced_test_iab" android:text="@string/title_advanced_test_iab"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDupMsgId" app:layout_constraintTop_toBottomOf="@id/etKeywords"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<Button <Button

Loading…
Cancel
Save