mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-21 13:47:04 +00:00
Auto classify depends on download
This commit is contained in:
parent
bce800a855
commit
8d5268877f
5 changed files with 41 additions and 30 deletions
|
@ -282,20 +282,20 @@ public interface DaoFolder {
|
|||
", unified = :unified" +
|
||||
", navigation = :navigation" +
|
||||
", notify = :notify" +
|
||||
", auto_classify = :auto_classify" +
|
||||
", hide = :hide" +
|
||||
", synchronize = :synchronize" +
|
||||
", poll = :poll" +
|
||||
", poll_factor = :poll_factor" +
|
||||
", download = :download" +
|
||||
", auto_classify = :auto_classify" +
|
||||
", `sync_days` = :sync_days" +
|
||||
", `keep_days` = :keep_days" +
|
||||
", auto_delete = :auto_delete" +
|
||||
" WHERE id = :id")
|
||||
int setFolderProperties(
|
||||
long id, String rename,
|
||||
String display, Integer color, boolean unified, boolean navigation, boolean notify, boolean auto_classify, boolean hide,
|
||||
boolean synchronize, boolean poll, int poll_factor, boolean download,
|
||||
String display, Integer color, boolean unified, boolean navigation, boolean notify, boolean hide,
|
||||
boolean synchronize, boolean poll, int poll_factor, boolean download, boolean auto_classify,
|
||||
int sync_days, int keep_days, boolean auto_delete);
|
||||
|
||||
@Query("UPDATE folder" +
|
||||
|
|
|
@ -89,6 +89,8 @@ public class EntityFolder extends EntityOrder implements Serializable {
|
|||
public Integer poll_count = 0;
|
||||
@NonNull
|
||||
public Boolean download = true;
|
||||
@NonNull
|
||||
public Boolean auto_classify = false;
|
||||
public Boolean subscribed;
|
||||
@NonNull
|
||||
public Integer sync_days;
|
||||
|
@ -108,8 +110,6 @@ public class EntityFolder extends EntityOrder implements Serializable {
|
|||
public Boolean navigation = false;
|
||||
@NonNull
|
||||
public Boolean notify = false;
|
||||
@NonNull
|
||||
public Boolean auto_classify = false;
|
||||
|
||||
public Integer total; // messages on server
|
||||
public String[] keywords;
|
||||
|
|
|
@ -64,12 +64,12 @@ public class FragmentFolder extends FragmentBase {
|
|||
private CheckBox cbUnified;
|
||||
private CheckBox cbNavigation;
|
||||
private CheckBox cbNotify;
|
||||
private CheckBox cbAutoClassify;
|
||||
private CheckBox cbSynchronize;
|
||||
private CheckBox cbPoll;
|
||||
private EditText etPoll;
|
||||
private TextView tvPoll;
|
||||
private CheckBox cbDownload;
|
||||
private CheckBox cbAutoClassify;
|
||||
private Button btnInfo;
|
||||
private EditText etSyncDays;
|
||||
private EditText etKeepDays;
|
||||
|
@ -125,12 +125,12 @@ public class FragmentFolder extends FragmentBase {
|
|||
cbUnified = view.findViewById(R.id.cbUnified);
|
||||
cbNavigation = view.findViewById(R.id.cbNavigation);
|
||||
cbNotify = view.findViewById(R.id.cbNotify);
|
||||
cbAutoClassify = view.findViewById(R.id.cbAutoClassify);
|
||||
cbSynchronize = view.findViewById(R.id.cbSynchronize);
|
||||
cbPoll = view.findViewById(R.id.cbPoll);
|
||||
etPoll = view.findViewById(R.id.etPoll);
|
||||
tvPoll = view.findViewById(R.id.tvPoll);
|
||||
cbDownload = view.findViewById(R.id.cbDownload);
|
||||
cbAutoClassify = view.findViewById(R.id.cbAutoClassify);
|
||||
btnInfo = view.findViewById(R.id.btnInfo);
|
||||
etSyncDays = view.findViewById(R.id.etSyncDays);
|
||||
etKeepDays = view.findViewById(R.id.etKeepDays);
|
||||
|
@ -160,8 +160,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
cbAutoClassify.setVisibility(MessageClassifier.isEnabled(getContext()) ? View.VISIBLE : View.GONE);
|
||||
|
||||
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
|
@ -179,6 +177,15 @@ public class FragmentFolder extends FragmentBase {
|
|||
}
|
||||
});
|
||||
|
||||
cbDownload.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
cbAutoClassify.setEnabled(isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
cbAutoClassify.setVisibility(MessageClassifier.isEnabled(getContext()) ? View.VISIBLE : View.GONE);
|
||||
|
||||
btnInfo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -284,12 +291,12 @@ public class FragmentFolder extends FragmentBase {
|
|||
cbUnified.setChecked(folder == null ? false : folder.unified);
|
||||
cbNavigation.setChecked(folder == null ? false : folder.navigation);
|
||||
cbNotify.setChecked(folder == null ? false : folder.notify);
|
||||
cbAutoClassify.setChecked(folder == null ? false : folder.auto_classify);
|
||||
cbSynchronize.setChecked(folder == null || folder.synchronize);
|
||||
cbPoll.setChecked(folder == null ? true : folder.poll);
|
||||
etPoll.setText(folder == null ? null : Integer.toString(folder.poll_factor));
|
||||
tvPoll.setText(getString(R.string.title_factor_minutes, interval));
|
||||
cbDownload.setChecked(folder == null ? true : folder.download);
|
||||
cbAutoClassify.setChecked(folder == null ? false : folder.auto_classify);
|
||||
etSyncDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_SYNC : folder.sync_days));
|
||||
if (folder != null && folder.keep_days == Integer.MAX_VALUE)
|
||||
cbKeepAll.setChecked(true);
|
||||
|
@ -317,6 +324,7 @@ public class FragmentFolder extends FragmentBase {
|
|||
etPoll.setEnabled(cbSynchronize.isChecked() && always);
|
||||
tvPoll.setEnabled(cbSynchronize.isChecked() && always);
|
||||
grpPoll.setVisibility(imap && cbPoll.isEnabled() && cbPoll.isChecked() ? View.VISIBLE : View.GONE);
|
||||
cbAutoClassify.setEnabled(cbDownload.isChecked());
|
||||
etKeepDays.setEnabled(!cbKeepAll.isChecked());
|
||||
cbAutoDelete.setEnabled(!cbKeepAll.isChecked());
|
||||
btnSave.setEnabled(true);
|
||||
|
@ -416,11 +424,11 @@ public class FragmentFolder extends FragmentBase {
|
|||
args.putBoolean("unified", cbUnified.isChecked());
|
||||
args.putBoolean("navigation", cbNavigation.isChecked());
|
||||
args.putBoolean("notify", cbNotify.isChecked());
|
||||
args.putBoolean("auto_classify", cbAutoClassify.isChecked());
|
||||
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
||||
args.putBoolean("poll", cbPoll.isChecked());
|
||||
args.putString("factor", etPoll.getText().toString());
|
||||
args.putBoolean("download", cbDownload.isChecked());
|
||||
args.putBoolean("auto_classify", cbAutoClassify.isChecked());
|
||||
args.putString("sync", etSyncDays.getText().toString());
|
||||
args.putString("keep", cbKeepAll.isChecked()
|
||||
? Integer.toString(Integer.MAX_VALUE)
|
||||
|
@ -459,11 +467,11 @@ public class FragmentFolder extends FragmentBase {
|
|||
boolean unified = args.getBoolean("unified");
|
||||
boolean navigation = args.getBoolean("navigation");
|
||||
boolean notify = args.getBoolean("notify");
|
||||
boolean auto_classify = args.getBoolean("auto_classify");
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
boolean poll = args.getBoolean("poll");
|
||||
String factor = args.getString("factor");
|
||||
boolean download = args.getBoolean("download");
|
||||
boolean auto_classify = args.getBoolean("auto_classify");
|
||||
String sync = args.getString("sync");
|
||||
String keep = args.getString("keep");
|
||||
boolean auto_delete = args.getBoolean("auto_delete");
|
||||
|
@ -513,8 +521,6 @@ public class FragmentFolder extends FragmentBase {
|
|||
return true;
|
||||
if (!Objects.equals(folder.notify, notify))
|
||||
return true;
|
||||
if (!Objects.equals(folder.auto_classify, auto_classify))
|
||||
return true;
|
||||
if (!Objects.equals(folder.hide, hide))
|
||||
return true;
|
||||
if (!Objects.equals(folder.synchronize, synchronize))
|
||||
|
@ -526,6 +532,8 @@ public class FragmentFolder extends FragmentBase {
|
|||
return true;
|
||||
if (!Objects.equals(folder.download, download))
|
||||
return true;
|
||||
if (!Objects.equals(folder.auto_classify, auto_classify))
|
||||
return true;
|
||||
if (!Objects.equals(folder.sync_days, sync_days))
|
||||
return true;
|
||||
if (!Objects.equals(folder.keep_days, keep_days))
|
||||
|
@ -564,12 +572,12 @@ public class FragmentFolder extends FragmentBase {
|
|||
create.unified = unified;
|
||||
create.navigation = navigation;
|
||||
create.notify = notify;
|
||||
create.auto_classify = auto_classify;
|
||||
create.hide = hide;
|
||||
create.synchronize = synchronize;
|
||||
create.poll = poll;
|
||||
create.poll_factor = poll_factor;
|
||||
create.download = download;
|
||||
create.auto_classify = auto_classify;
|
||||
create.sync_days = sync_days;
|
||||
create.keep_days = keep_days;
|
||||
create.auto_delete = auto_delete;
|
||||
|
@ -588,8 +596,8 @@ public class FragmentFolder extends FragmentBase {
|
|||
Log.i("Updating folder=" + folder.name);
|
||||
db.folder().setFolderProperties(id,
|
||||
folder.name.equals(name) ? null : name,
|
||||
display, color, unified, navigation, notify, auto_classify, hide,
|
||||
synchronize, poll, poll_factor, download,
|
||||
display, color, unified, navigation, notify, hide,
|
||||
synchronize, poll, poll_factor, download, auto_classify,
|
||||
sync_days, keep_days, auto_delete);
|
||||
db.folder().setFolderError(id, null);
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import java.util.Map;
|
|||
|
||||
public class MessageClassifier {
|
||||
private static boolean loaded = false;
|
||||
private static boolean dirty = false;
|
||||
private static Map<Long, Map<String, Integer>> classMessages = new HashMap<>();
|
||||
private static Map<Long, Map<String, Map<String, Integer>>> wordClassFrequency = new HashMap<>();
|
||||
|
||||
|
@ -106,9 +107,11 @@ public class MessageClassifier {
|
|||
}
|
||||
Log.i("Classifier classify=" + folder.name + " messages=" + classMessages.get(account.id).get(folder.name));
|
||||
|
||||
dirty = true;
|
||||
|
||||
if (classified != null) {
|
||||
EntityFolder f = db.folder().getFolderByName(account.id, classified);
|
||||
if (f != null && f.auto_classify && !f.id.equals(folder.id))
|
||||
if (f != null && f.download && f.auto_classify && !f.id.equals(folder.id))
|
||||
EntityOperation.queue(context, message, EntityOperation.MOVE, f.id);
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +223,7 @@ public class MessageClassifier {
|
|||
}
|
||||
|
||||
static synchronized void save(Context context) throws JSONException, IOException {
|
||||
if (!loaded)
|
||||
if (!dirty)
|
||||
return;
|
||||
if (!isEnabled(context))
|
||||
return;
|
||||
|
|
|
@ -136,15 +136,6 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbNavigation" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbAutoClassify"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_auto_classify"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbNotify" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbSynchronize"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -152,7 +143,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_synchronize_folder"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbAutoClassify" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbNotify" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbPoll"
|
||||
|
@ -206,6 +197,15 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etPoll" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbAutoClassify"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_auto_classify"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbDownload" />
|
||||
|
||||
<!-- after -->
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
|
@ -216,7 +216,7 @@
|
|||
android:text="@string/title_sync_days"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbDownload" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbAutoClassify" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvSyncDaysRemark"
|
||||
|
|
Loading…
Reference in a new issue