From e937719480e46f5276114fdd8ebe14d18102d267 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 3 Jan 2021 20:21:35 +0100 Subject: [PATCH] Added option for message classification --- .../faircode/email/FragmentOptionsMisc.java | 31 ++++++++++++++++++- .../eu/faircode/email/MessageClassifier.java | 9 +++++- .../main/res/layout/fragment_options_misc.xml | 23 +++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 13cdad40bd..098a53b474 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -81,6 +81,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swExternalSearch; private SwitchCompat swShortcuts; private SwitchCompat swFts; + private SwitchCompat swClassification; + private ImageButton ibClassification; private TextView tvFtsIndexed; private TextView tvFtsPro; private Spinner spLanguage; @@ -118,7 +120,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private final static long MIN_FILE_SIZE = 1024 * 1024L; private final static String[] RESET_OPTIONS = new String[]{ - "shortcuts", "fts", "language", "watchdog", "updates", + "shortcuts", "fts", "classification", "language", "watchdog", "updates", "experiments", "query_threads", "crash_reports", "cleanup_attachments", "protocol", "debug", "auth_plain", "auth_login", "auth_sasl" }; @@ -161,6 +163,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swExternalSearch = view.findViewById(R.id.swExternalSearch); swShortcuts = view.findViewById(R.id.swShortcuts); swFts = view.findViewById(R.id.swFts); + swClassification = view.findViewById(R.id.swClassification); + ibClassification = view.findViewById(R.id.ibClassification); tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed); tvFtsPro = view.findViewById(R.id.tvFtsPro); spLanguage = view.findViewById(R.id.spLanguage); @@ -254,6 +258,30 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc Helper.linkPro(tvFtsPro); + swClassification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + private int count = 0; + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean checked) { + prefs.edit().putBoolean("classification", checked).apply(); + if (!checked) { + count++; + if (count >= 3) { + count = 0; + MessageClassifier.clear(buttonView.getContext()); + ToastEx.makeText(buttonView.getContext(), R.string.title_reset, Toast.LENGTH_LONG).show(); + } + } + } + }); + + ibClassification.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Helper.viewFAQ(v.getContext(), 125); + } + }); + spLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { @@ -721,6 +749,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class)); swShortcuts.setChecked(prefs.getBoolean("shortcuts", true)); swFts.setChecked(prefs.getBoolean("fts", false)); + swClassification.setChecked(prefs.getBoolean("classification", false)); int selected = -1; String language = prefs.getString("language", null); diff --git a/app/src/main/java/eu/faircode/email/MessageClassifier.java b/app/src/main/java/eu/faircode/email/MessageClassifier.java index e05dd496ca..2a21fe29c8 100644 --- a/app/src/main/java/eu/faircode/email/MessageClassifier.java +++ b/app/src/main/java/eu/faircode/email/MessageClassifier.java @@ -312,9 +312,16 @@ public class MessageClassifier { Log.i("Classifier loaded"); } + static synchronized void clear(Context context) { + Log.i("Classifier clear"); + classMessages.clear(); + wordClassFrequency.clear(); + dirty = true; + } + static boolean isEnabled(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - return prefs.getBoolean("experiments", false); + return prefs.getBoolean("classification", false); } static boolean canClassify(String folderType) { diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index f3a98108ca..4491507c1f 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -112,6 +112,27 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvFtsIndexed" /> + + + + + app:layout_constraintTop_toBottomOf="@id/ibClassification" /> Detect message text language Build search index %1$d / %2$d messages indexed (%3$s) + Classify messages Language System Periodically check if FairEmail is still active