diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
index 30b2b65e26..50e9efd61d 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
@@ -44,6 +44,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
+import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@@ -61,6 +62,7 @@ import androidx.preference.PreferenceManager;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -82,6 +84,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swShortcuts;
private SwitchCompat swFts;
private SwitchCompat swClassification;
+ private TextView tvClassMinChance;
+ private SeekBar sbClassMinChance;
+ private TextView tvClassMinDifference;
+ private SeekBar sbClassMinDifference;
private ImageButton ibClassification;
private TextView tvFtsIndexed;
private TextView tvFtsPro;
@@ -117,10 +123,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Group grpDebug;
+ private NumberFormat NF = NumberFormat.getNumberInstance();
+
private final static long MIN_FILE_SIZE = 1024 * 1024L;
private final static String[] RESET_OPTIONS = new String[]{
- "shortcuts", "fts", "classification", "language", "watchdog", "updates",
+ "shortcuts", "fts",
+ "classification", "class_min_chance", "class_min_difference",
+ "language", "watchdog", "updates",
"experiments", "query_threads", "crash_reports", "cleanup_attachments",
"protocol", "debug", "auth_plain", "auth_login", "auth_sasl"
};
@@ -165,6 +175,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swFts = view.findViewById(R.id.swFts);
swClassification = view.findViewById(R.id.swClassification);
ibClassification = view.findViewById(R.id.ibClassification);
+ tvClassMinChance = view.findViewById(R.id.tvClassMinChance);
+ sbClassMinChance = view.findViewById(R.id.sbClassMinChance);
+ tvClassMinDifference = view.findViewById(R.id.tvClassMinDifference);
+ sbClassMinDifference = view.findViewById(R.id.sbClassMinDifference);
tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed);
tvFtsPro = view.findViewById(R.id.tvFtsPro);
spLanguage = view.findViewById(R.id.spLanguage);
@@ -282,6 +296,40 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
+ sbClassMinChance.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ prefs.edit().putInt("class_min_chance", progress).apply();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+ });
+
+ sbClassMinDifference.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ prefs.edit().putInt("class_min_difference", progress).apply();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // Do nothing
+ }
+ });
+
spLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> adapterView, View view, int position, long id) {
@@ -749,8 +797,17 @@ 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 class_min_chance = prefs.getInt("class_min_chance", 20);
+ tvClassMinChance.setText(getString(R.string.title_advanced_class_min_chance, NF.format(class_min_chance)));
+ sbClassMinChance.setProgress(class_min_chance);
+
+ int class_min_difference = prefs.getInt("class_min_difference", 50);
+ tvClassMinDifference.setText(getString(R.string.title_advanced_class_min_difference, NF.format(class_min_difference)));
+ sbClassMinDifference.setProgress(class_min_difference);
+
int selected = -1;
String language = prefs.getString("language", null);
List display = new ArrayList<>();
diff --git a/app/src/main/java/eu/faircode/email/MessageClassifier.java b/app/src/main/java/eu/faircode/email/MessageClassifier.java
index 33c1a7ce97..71a0216dfd 100644
--- a/app/src/main/java/eu/faircode/email/MessageClassifier.java
+++ b/app/src/main/java/eu/faircode/email/MessageClassifier.java
@@ -249,13 +249,22 @@ public class MessageClassifier {
}
});
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ double class_min_chance = prefs.getInt("class_min_chance", 20) / 100.0;
+ double class_min_difference = prefs.getInt("class_min_difference", 50) / 100.0;
+
// Select best class
String classification = null;
- if (chances.get(0).chance > CHANCE_MINIMUM &&
- chances.get(0).chance / chances.get(1).chance >= CHANCE_THRESHOLD)
+ double c0 = chances.get(0).chance;
+ double c1 = chances.get(1).chance;
+ if (c0 > class_min_chance && c1 < c0 * class_min_difference)
classification = chances.get(0).clazz;
- Log.i("Classifier current=" + currentClass + " classified=" + classification);
+ Log.i("Classifier current=" + currentClass +
+ " c0=" + Math.round(c0 * 100 * 100) / 100.0 + ">" + Math.round(class_min_chance * 100 * 100) / 100.0 + "%" +
+ " c1=" + Math.round(c1 * 100 * 100) / 100.0 + "<" + Math.round(c0 * class_min_difference * 100 * 100) / 100.0 + "%" +
+ " (" + class_min_difference + "%)" +
+ " classified=" + classification);
return classification;
}
diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml
index 4491507c1f..8a92365346 100644
--- a/app/src/main/res/layout/fragment_options_misc.xml
+++ b/app/src/main/res/layout/fragment_options_misc.xml
@@ -133,6 +133,52 @@
app:layout_constraintTop_toBottomOf="@id/swClassification"
app:srcCompat="@drawable/twotone_info_24" />
+
+
+
+
+
+
+
+
+ app:layout_constraintTop_toBottomOf="@id/sbClassMinDifference" />
Build search index
%1$d / %2$d messages indexed (%3$s)
Classify messages
+ Minimum class chance: %1$s %%
+ Minimum class difference: %1$s %%
Language
System
Periodically check if FairEmail is still active