From 42af314c7913766574d8a529317b3795f724aac6 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 29 Dec 2023 10:06:54 +0100 Subject: [PATCH] Prepare Adguard download --- .../email/FragmentOptionsPrivacy.java | 25 ++++++++++-- .../res/layout/fragment_options_privacy.xml | 39 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index 59167b42b4..658c5c9680 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -55,6 +55,7 @@ import androidx.webkit.WebViewFeature; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.Locale; @@ -64,6 +65,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer private SwitchCompat swConfirmLinks; private SwitchCompat swSanitizeLinks; private SwitchCompat swAdguard; + private Button btnAdguard; + private TextView tvAdguardTime; private SwitchCompat swCheckLinksDbl; private SwitchCompat swConfirmFiles; private SwitchCompat swConfirmImages; @@ -134,6 +137,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swConfirmLinks = view.findViewById(R.id.swConfirmLinks); swSanitizeLinks = view.findViewById(R.id.swSanitizeLinks); swAdguard = view.findViewById(R.id.swAdguard); + btnAdguard = view.findViewById(R.id.btnAdguard); + tvAdguardTime = view.findViewById(R.id.tvAdguardTime); swCheckLinksDbl = view.findViewById(R.id.swCheckLinksDbl); swConfirmFiles = view.findViewById(R.id.swConfirmFiles); swConfirmImages = view.findViewById(R.id.swConfirmImages); @@ -218,6 +223,13 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer } }); + btnAdguard.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + prefs.edit().putLong("adguard_last", new Date().getTime()).apply(); + } + }); + swCheckLinksDbl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -609,6 +621,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer if (view == null || getContext() == null) return; + DateFormat DF = SimpleDateFormat.getDateTimeInstance(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); swConfirmLinks.setChecked(prefs.getBoolean("confirm_links", true)); @@ -616,6 +629,11 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swSanitizeLinks.setEnabled(swConfirmLinks.isChecked()); swAdguard.setChecked(prefs.getBoolean("adguard", false)); swAdguard.setEnabled(swConfirmLinks.isChecked()); + + long adguard_last = prefs.getLong("adguard_last", -1); + tvAdguardTime.setText(adguard_last < 0 ? null : DF.format(adguard_last)); + tvAdguardTime.setVisibility(adguard_last < 0 ? View.GONE : View.VISIBLE); + swCheckLinksDbl.setChecked(prefs.getBoolean("check_links_dbl", BuildConfig.PLAY_STORE_RELEASE)); swCheckLinksDbl.setEnabled(swConfirmLinks.isChecked()); swConfirmFiles.setChecked(prefs.getBoolean("confirm_files", true)); @@ -660,10 +678,9 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swSafeBrowsing.setChecked(prefs.getBoolean("safe_browsing", false)); swLoadEmoji.setChecked(prefs.getBoolean("load_emoji", true)); - long time = prefs.getLong("disconnect_last", -1); - DateFormat DF = SimpleDateFormat.getDateTimeInstance(); - tvDisconnectBlacklistTime.setText(time < 0 ? null : DF.format(time)); - tvDisconnectBlacklistTime.setVisibility(time < 0 ? View.GONE : View.VISIBLE); + long disconnect_last = prefs.getLong("disconnect_last", -1); + tvDisconnectBlacklistTime.setText(disconnect_last < 0 ? null : DF.format(disconnect_last)); + tvDisconnectBlacklistTime.setVisibility(disconnect_last < 0 ? View.GONE : View.VISIBLE); swDisconnectAutoUpdate.setChecked(prefs.getBoolean("disconnect_auto_update", false)); swDisconnectLinks.setChecked(prefs.getBoolean("disconnect_links", true)); diff --git a/app/src/main/res/layout/fragment_options_privacy.xml b/app/src/main/res/layout/fragment_options_privacy.xml index 645e2258ec..c0fd63997a 100644 --- a/app/src/main/res/layout/fragment_options_privacy.xml +++ b/app/src/main/res/layout/fragment_options_privacy.xml @@ -132,13 +132,48 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:layout_marginTop="12dp" - android:checked="true" android:text="@string/title_advanced_adguard" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvSanitizeLinksHint" app:switchPadding="12dp" /> +