Adguard: auto update

pull/214/head
M66B 2 years ago
parent f45159b13c
commit 766cc727ae

@ -67,6 +67,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private SwitchCompat swAdguard;
private Button btnAdguard;
private TextView tvAdguardTime;
private SwitchCompat swAdguardAutoUpdate;
private SwitchCompat swCheckLinksDbl;
private SwitchCompat swConfirmFiles;
private SwitchCompat swConfirmImages;
@ -112,7 +113,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private final static int BIP39_WORDS = 6;
private final static String[] RESET_OPTIONS = new String[]{
"confirm_links", "sanitize_links", "adguard", "check_links_dbl", "confirm_files",
"confirm_links", "sanitize_links", "adguard", "adguard_auto_update",
"check_links_dbl", "confirm_files",
"confirm_images", "ask_images", "html_always_images", "confirm_html", "ask_html",
"disable_tracking",
"pin", "biometrics", "biometrics_timeout", "autolock", "autolock_nav",
@ -139,6 +141,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
swAdguard = view.findViewById(R.id.swAdguard);
btnAdguard = view.findViewById(R.id.btnAdguard);
tvAdguardTime = view.findViewById(R.id.tvAdguardTime);
swAdguardAutoUpdate = view.findViewById(R.id.swAdguardAutoUpdate);
swCheckLinksDbl = view.findViewById(R.id.swCheckLinksDbl);
swConfirmFiles = view.findViewById(R.id.swConfirmFiles);
swConfirmImages = view.findViewById(R.id.swConfirmImages);
@ -256,6 +259,14 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
}
});
swAdguardAutoUpdate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("adguard_auto_update", checked).apply();
WorkerAutoUpdate.init(compoundButton.getContext());
}
});
swCheckLinksDbl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -660,6 +671,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
tvAdguardTime.setText(adguard_last < 0 ? null : DF.format(adguard_last));
tvAdguardTime.setVisibility(adguard_last < 0 ? View.GONE : View.VISIBLE);
swAdguardAutoUpdate.setChecked(prefs.getBoolean("adguard_auto_update", false));
swCheckLinksDbl.setChecked(prefs.getBoolean("check_links_dbl", BuildConfig.PLAY_STORE_RELEASE));
swCheckLinksDbl.setEnabled(swConfirmLinks.isChecked());
swConfirmFiles.setChecked(prefs.getBoolean("confirm_files", true));

@ -49,22 +49,49 @@ public class WorkerAutoUpdate extends Worker {
public Result doWork() {
Thread.currentThread().setPriority(THREAD_PRIORITY_BACKGROUND);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean adguard_auto_update = prefs.getBoolean("adguard_auto_update", false);
boolean disconnect_auto_update = prefs.getBoolean("disconnect_auto_update", false);
try {
Log.i("Auto updating");
DisconnectBlacklist.download(getApplicationContext());
Throwable adguard = null;
if (adguard_auto_update)
try {
Adguard.download(getApplicationContext());
} catch (Throwable ex) {
Log.e(ex);
adguard = ex;
}
Throwable disconnect = null;
if (disconnect_auto_update)
try {
DisconnectBlacklist.download(getApplicationContext());
} catch (Throwable ex) {
Log.e(ex);
disconnect = ex;
}
if (adguard != null)
throw adguard;
if (disconnect != null)
throw disconnect;
Log.i("Auto updated");
return Result.success();
} catch (Throwable ex) {
Log.e(ex);
return Result.failure();
}
}
static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_update = prefs.getBoolean("disconnect_auto_update", false);
boolean adguard_auto_update = prefs.getBoolean("adguard_auto_update", false);
boolean disconnect_auto_update = prefs.getBoolean("disconnect_auto_update", false);
try {
if (auto_update) {
if (adguard_auto_update || disconnect_auto_update) {
Log.i("Queuing " + getName());
PeriodicWorkRequest.Builder builder =
new PeriodicWorkRequest.Builder(WorkerAutoUpdate.class, UPDATE_INTERVAL, TimeUnit.DAYS)

@ -163,7 +163,7 @@
app:layout_constraintTop_toBottomOf="@id/btnAdguard" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAdguardWeekly"
android:id="@+id/swAdguardAutoUpdate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
@ -183,7 +183,7 @@
android:text="@string/title_advanced_check_links_dbl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAdguardWeekly"
app:layout_constraintTop_toBottomOf="@id/swAdguardAutoUpdate"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

Loading…
Cancel
Save