mirror of https://github.com/M66B/FairEmail.git
Small improvements
This commit is contained in:
parent
7fc720a520
commit
40347cd3ff
|
@ -79,7 +79,10 @@ public class DnsBlockList {
|
|||
|
||||
static void setEnabled(Context context, BlockList blocklist, boolean enabled) {
|
||||
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) {
|
||||
cache.clear();
|
||||
|
@ -91,6 +94,18 @@ public class DnsBlockList {
|
|||
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) {
|
||||
List<String> names = new ArrayList<>();
|
||||
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)
|
||||
.setTitle(R.string.title_setup_defaults)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
|
@ -360,6 +360,9 @@ public class FragmentOptions extends FragmentBase {
|
|||
editor.remove(option);
|
||||
editor.apply();
|
||||
|
||||
if (confirmed != null)
|
||||
confirmed.run();
|
||||
|
||||
ToastEx.makeText(context, R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -445,7 +445,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -323,7 +323,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -913,8 +913,12 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
setNavigationBarColor(Color.BLACK);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setNavigationBarColor(Color.BLACK);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -386,7 +386,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -886,7 +886,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -570,7 +570,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -394,7 +394,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -489,7 +489,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_default) {
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS);
|
||||
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -85,8 +85,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
|
|||
private SwitchCompat swCheckReply;
|
||||
private SwitchCompat swCheckMx;
|
||||
private SwitchCompat swCheckBlocklist;
|
||||
private RecyclerView rvBlocklist;
|
||||
private SwitchCompat swUseBlocklist;
|
||||
private RecyclerView rvBlocklist;
|
||||
private SwitchCompat swTuneKeepAlive;
|
||||
private Group grpExempted;
|
||||
|
||||
|
@ -143,8 +143,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
|
|||
swCheckReply = view.findViewById(R.id.swCheckReply);
|
||||
swCheckMx = view.findViewById(R.id.swCheckMx);
|
||||
swCheckBlocklist = view.findViewById(R.id.swCheckBlocklist);
|
||||
rvBlocklist = view.findViewById(R.id.rvBlocklist);
|
||||
swUseBlocklist = view.findViewById(R.id.swUseBlocklist);
|
||||
rvBlocklist = view.findViewById(R.id.rvBlocklist);
|
||||
swTuneKeepAlive = view.findViewById(R.id.swTuneKeepAlive);
|
||||
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() {
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
|
@ -411,7 +411,13 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
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 super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -666,17 +666,6 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swCheckBlocklist" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvBlocklist"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCheckBlocklistWarning" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swUseBlocklist"
|
||||
android:layout_width="0dp"
|
||||
|
@ -686,9 +675,20 @@
|
|||
android:text="@string/title_junk_blocklist"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/rvBlocklist"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCheckBlocklistWarning"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvBlocklist"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swUseBlocklist" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swTuneKeepAlive"
|
||||
android:layout_width="0dp"
|
||||
|
@ -698,7 +698,7 @@
|
|||
android:text="@string/title_advanced_tune_keep_alive"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swUseBlocklist"
|
||||
app:layout_constraintTop_toBottomOf="@id/rvBlocklist"
|
||||
app:switchPadding="12dp" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
Loading…
Reference in New Issue