Added option for message classification

pull/190/head
M66B 4 years ago
parent b1e8b450ba
commit e937719480

@ -81,6 +81,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swExternalSearch; private SwitchCompat swExternalSearch;
private SwitchCompat swShortcuts; private SwitchCompat swShortcuts;
private SwitchCompat swFts; private SwitchCompat swFts;
private SwitchCompat swClassification;
private ImageButton ibClassification;
private TextView tvFtsIndexed; private TextView tvFtsIndexed;
private TextView tvFtsPro; private TextView tvFtsPro;
private Spinner spLanguage; 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 long MIN_FILE_SIZE = 1024 * 1024L;
private final static String[] RESET_OPTIONS = new String[]{ 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", "experiments", "query_threads", "crash_reports", "cleanup_attachments",
"protocol", "debug", "auth_plain", "auth_login", "auth_sasl" "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); swExternalSearch = view.findViewById(R.id.swExternalSearch);
swShortcuts = view.findViewById(R.id.swShortcuts); swShortcuts = view.findViewById(R.id.swShortcuts);
swFts = view.findViewById(R.id.swFts); swFts = view.findViewById(R.id.swFts);
swClassification = view.findViewById(R.id.swClassification);
ibClassification = view.findViewById(R.id.ibClassification);
tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed); tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed);
tvFtsPro = view.findViewById(R.id.tvFtsPro); tvFtsPro = view.findViewById(R.id.tvFtsPro);
spLanguage = view.findViewById(R.id.spLanguage); spLanguage = view.findViewById(R.id.spLanguage);
@ -254,6 +258,30 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
Helper.linkPro(tvFtsPro); 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() { spLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { 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)); swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class));
swShortcuts.setChecked(prefs.getBoolean("shortcuts", true)); swShortcuts.setChecked(prefs.getBoolean("shortcuts", true));
swFts.setChecked(prefs.getBoolean("fts", false)); swFts.setChecked(prefs.getBoolean("fts", false));
swClassification.setChecked(prefs.getBoolean("classification", false));
int selected = -1; int selected = -1;
String language = prefs.getString("language", null); String language = prefs.getString("language", null);

@ -312,9 +312,16 @@ public class MessageClassifier {
Log.i("Classifier loaded"); 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) { static boolean isEnabled(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("experiments", false); return prefs.getBoolean("classification", false);
} }
static boolean canClassify(String folderType) { static boolean canClassify(String folderType) {

@ -112,6 +112,27 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFtsIndexed" /> app:layout_constraintTop_toBottomOf="@id/tvFtsIndexed" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swClassification"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_classification"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFtsPro"
app:switchPadding="12dp" />
<ImageButton
android:id="@+id/ibClassification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swClassification"
app:srcCompat="@drawable/twotone_info_24" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvLanguage" android:id="@+id/tvLanguage"
android:layout_width="0dp" android:layout_width="0dp"
@ -123,7 +144,7 @@
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
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/tvFtsPro" /> app:layout_constraintTop_toBottomOf="@id/ibClassification" />
<Spinner <Spinner
android:id="@+id/spLanguage" android:id="@+id/spLanguage"

@ -516,6 +516,7 @@
<string name="title_advanced_language_detection">Detect message text language</string> <string name="title_advanced_language_detection">Detect message text language</string>
<string name="title_advanced_fts">Build search index</string> <string name="title_advanced_fts">Build search index</string>
<string name="title_advanced_fts_indexed">%1$d / %2$d messages indexed (%3$s)</string> <string name="title_advanced_fts_indexed">%1$d / %2$d messages indexed (%3$s)</string>
<string name="title_advanced_classification">Classify messages</string>
<string name="title_advanced_language">Language</string> <string name="title_advanced_language">Language</string>
<string name="title_advanced_language_system">System</string> <string name="title_advanced_language_system">System</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string> <string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>

Loading…
Cancel
Save