Small improvements

pull/199/head
M66B 3 years ago
parent 7fc720a520
commit 40347cd3ff

@ -79,7 +79,10 @@ public class DnsBlockList {
static void setEnabled(Context context, BlockList blocklist, boolean enabled) { static void setEnabled(Context context, BlockList blocklist, boolean enabled) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("blocklist." + blocklist.name, enabled).apply(); if (blocklist.enabled == enabled)
prefs.edit().remove("blocklist." + blocklist.name).apply();
else
prefs.edit().putBoolean("blocklist." + blocklist.name, enabled).apply();
synchronized (cache) { synchronized (cache) {
cache.clear(); cache.clear();
@ -91,6 +94,18 @@ public class DnsBlockList {
return prefs.getBoolean("blocklist." + blocklist.name, blocklist.enabled); return prefs.getBoolean("blocklist." + blocklist.name, blocklist.enabled);
} }
static void reset(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
for (BlockList blocklist : BLOCKLISTS)
editor.remove("blocklist." + blocklist.name);
editor.apply();
synchronized (cache) {
cache.clear();
}
}
static List<String> getNames(Context context) { static List<String> getNames(Context context) {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (BlockList blocklist : BLOCKLISTS) for (BlockList blocklist : BLOCKLISTS)

@ -348,7 +348,7 @@ public class FragmentOptions extends FragmentBase {
} }
} }
static void reset(Context context, String[] options) { static void reset(Context context, String[] options, Runnable confirmed) {
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle(R.string.title_setup_defaults) .setTitle(R.string.title_setup_defaults)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@ -360,6 +360,9 @@ public class FragmentOptions extends FragmentBase {
editor.remove(option); editor.remove(option);
editor.apply(); editor.apply();
if (confirmed != null)
confirmed.run();
ToastEx.makeText(context, R.string.title_setup_done, Toast.LENGTH_LONG).show(); ToastEx.makeText(context, R.string.title_setup_done, Toast.LENGTH_LONG).show();
} }
}) })

@ -445,7 +445,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -323,7 +323,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -913,8 +913,12 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, new Runnable() {
setNavigationBarColor(Color.BLACK); @Override
public void run() {
setNavigationBarColor(Color.BLACK);
}
});
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -386,7 +386,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -886,7 +886,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -570,7 +570,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -394,7 +394,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -489,7 +489,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -85,8 +85,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private SwitchCompat swCheckReply; private SwitchCompat swCheckReply;
private SwitchCompat swCheckMx; private SwitchCompat swCheckMx;
private SwitchCompat swCheckBlocklist; private SwitchCompat swCheckBlocklist;
private RecyclerView rvBlocklist;
private SwitchCompat swUseBlocklist; private SwitchCompat swUseBlocklist;
private RecyclerView rvBlocklist;
private SwitchCompat swTuneKeepAlive; private SwitchCompat swTuneKeepAlive;
private Group grpExempted; private Group grpExempted;
@ -143,8 +143,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swCheckReply = view.findViewById(R.id.swCheckReply); swCheckReply = view.findViewById(R.id.swCheckReply);
swCheckMx = view.findViewById(R.id.swCheckMx); swCheckMx = view.findViewById(R.id.swCheckMx);
swCheckBlocklist = view.findViewById(R.id.swCheckBlocklist); swCheckBlocklist = view.findViewById(R.id.swCheckBlocklist);
rvBlocklist = view.findViewById(R.id.rvBlocklist);
swUseBlocklist = view.findViewById(R.id.swUseBlocklist); swUseBlocklist = view.findViewById(R.id.swUseBlocklist);
rvBlocklist = view.findViewById(R.id.rvBlocklist);
swTuneKeepAlive = view.findViewById(R.id.swTuneKeepAlive); swTuneKeepAlive = view.findViewById(R.id.swTuneKeepAlive);
grpExempted = view.findViewById(R.id.grpExempted); grpExempted = view.findViewById(R.id.grpExempted);
@ -348,11 +348,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
} }
}); });
rvBlocklist.setHasFixedSize(false);
rvBlocklist.setLayoutManager(new LinearLayoutManager(getContext()));
AdapterBlocklist badapter = new AdapterBlocklist(getContext(), DnsBlockList.BLOCKLISTS);
rvBlocklist.setAdapter(badapter);
swUseBlocklist.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swUseBlocklist.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -360,6 +355,11 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
} }
}); });
rvBlocklist.setHasFixedSize(false);
rvBlocklist.setLayoutManager(new LinearLayoutManager(getContext()));
AdapterBlocklist badapter = new AdapterBlocklist(getContext(), DnsBlockList.BLOCKLISTS);
rvBlocklist.setAdapter(badapter);
swTuneKeepAlive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swTuneKeepAlive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -411,7 +411,13 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_default) { if (item.getItemId() == R.id.menu_default) {
FragmentOptions.reset(getContext(), RESET_OPTIONS); FragmentOptions.reset(getContext(), RESET_OPTIONS, new Runnable() {
@Override
public void run() {
DnsBlockList.reset(getContext());
rvBlocklist.getAdapter().notifyDataSetChanged();
}
});
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

@ -666,28 +666,28 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCheckBlocklist" /> app:layout_constraintTop_toBottomOf="@id/swCheckBlocklist" />
<androidx.recyclerview.widget.RecyclerView <androidx.appcompat.widget.SwitchCompat
android:id="@+id/rvBlocklist" android:id="@+id/swUseBlocklist"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:orientation="vertical" android:text="@string/title_junk_blocklist"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCheckBlocklistWarning" /> app:layout_constraintTop_toBottomOf="@id/tvCheckBlocklistWarning"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.recyclerview.widget.RecyclerView
android:id="@+id/swUseBlocklist" android:id="@+id/rvBlocklist"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_junk_blocklist" android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvBlocklist" app:layout_constraintTop_toBottomOf="@id/swUseBlocklist" />
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTuneKeepAlive" android:id="@+id/swTuneKeepAlive"
@ -698,7 +698,7 @@
android:text="@string/title_advanced_tune_keep_alive" android:text="@string/title_advanced_tune_keep_alive"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swUseBlocklist" app:layout_constraintTop_toBottomOf="@id/rvBlocklist"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

Loading…
Cancel
Save