From b67098f333767bf303b9caa565bde8c621d9ca55 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 10 Mar 2022 08:02:41 +0100 Subject: [PATCH] Added thread range setting --- .../faircode/email/FragmentOptionsMisc.java | 28 ++++++++++++++++++- .../java/eu/faircode/email/MessageHelper.java | 10 +++++-- .../main/res/layout/fragment_options_misc.xml | 25 ++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index ac89e373ae..392f492bd0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -145,6 +145,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SeekBar sbSqliteCache; private TextView tvChunkSize; private SeekBar sbChunkSize; + private TextView tvThreadRange; + private SeekBar sbThreadRange; private ImageButton ibSqliteCache; private SwitchCompat swUndoManager; private SwitchCompat swWebViewLegacy; @@ -198,7 +200,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "protocol", "debug", "log_level", "test1", "test2", "test3", "test4", "test5", "work_manager", // "external_storage", "query_threads", "wal", "sqlite_checkpoints", "sqlite_analyze", "sqlite_cache", - "chunk_size", "undo_manager", "webview_legacy", + "chunk_size", "thread_range", "undo_manager", "webview_legacy", "use_modseq", "uid_command", "perform_expunge", "uid_expunge", "auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", "keep_alive_poll", "empty_pool", "idle_done", "logarithmic_backoff", @@ -301,6 +303,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc ibSqliteCache = view.findViewById(R.id.ibSqliteCache); tvChunkSize = view.findViewById(R.id.tvChunkSize); sbChunkSize = view.findViewById(R.id.sbChunkSize); + tvThreadRange = view.findViewById(R.id.tvThreadRange); + sbThreadRange = view.findViewById(R.id.sbThreadRange); swUndoManager = view.findViewById(R.id.swUndoManager); swWebViewLegacy = view.findViewById(R.id.swWebViewLegacy); swModSeq = view.findViewById(R.id.swModSeq); @@ -938,6 +942,23 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + sbThreadRange.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + prefs.edit().putInt("thread_range", progress).apply(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Do nothing + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Do nothing + } + }); + swProtocol.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1618,6 +1639,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc tvChunkSize.setText(getString(R.string.title_advanced_chunk_size, chunk_size)); sbChunkSize.setProgress(chunk_size); + int thread_range = prefs.getInt("thread_range", MessageHelper.DEFAULT_THREAD_RANGE); + int range = (int) Math.pow(2, thread_range); + tvThreadRange.setText(getString(R.string.title_advanced_thread_range, range)); + sbThreadRange.setProgress(thread_range); + swUndoManager.setChecked(prefs.getBoolean("undo_manager", false)); swWebViewLegacy.setChecked(prefs.getBoolean("webview_legacy", false)); swModSeq.setChecked(prefs.getBoolean("use_modseq", true)); diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index d3002da5c0..26a966fda9 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -141,7 +141,7 @@ public class MessageHelper { static final int DEFAULT_DOWNLOAD_SIZE = 4 * 1024 * 1024; // bytes static final String HEADER_CORRELATION_ID = "X-Correlation-ID"; static final int MAX_SUBJECT_AGE = 48; // hours - static final long MAX_THREAD_RANGE = 180; // days + static final int DEFAULT_THREAD_RANGE = 7; // 2^7 = 128 days static final List RECEIVED_WORDS = Collections.unmodifiableList(Arrays.asList( "from", "by", "via", "with", "id", "for" @@ -1484,8 +1484,12 @@ public class MessageHelper { List all = new ArrayList<>(refs); all.add(msgid); - Long start = (received == 0 ? null : received - MAX_THREAD_RANGE * 24 * 3600L); - Long end = (received == 0 ? null : received + MAX_THREAD_RANGE * 24 * 3600L); + + int thread_range = prefs.getInt("thread_range", MessageHelper.DEFAULT_THREAD_RANGE); + int range = (int) Math.pow(2, thread_range); + Long start = (received == 0 ? null : received - range * 24 * 3600L); + Long end = (received == 0 ? null : received + range * 24 * 3600L); + List infos = (all.size() == 0 ? new ArrayList<>() : db.message().getThreadInfo(account, all, start, end)); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 930215c38d..1a694c9d0a 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -877,6 +877,29 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvChunkSize" /> + + + + sqlite analyze sqlite cache: %1$s %% - %2$s Chunk size: %1$d + Thread range: %1$d days Use Android\'s undo manager Old WebView behavior MODSEQ