mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 23:56:07 +02:00
Added option to limit unmetered data usage
This commit is contained in:
@@ -1722,21 +1722,25 @@ class Core {
|
||||
long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE);
|
||||
if (maxSize == 0)
|
||||
maxSize = Long.MAX_VALUE;
|
||||
boolean download_limited = prefs.getBoolean("download_limited", false);
|
||||
boolean download_eml = prefs.getBoolean("download_eml", false);
|
||||
|
||||
if (!message.content)
|
||||
if (state.getNetworkState().isUnmetered() || (message.size != null && message.size < maxSize))
|
||||
if ((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(message.size != null && message.size < maxSize))
|
||||
async = true;
|
||||
|
||||
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if (!attachment.available)
|
||||
if (state.getNetworkState().isUnmetered() || (attachment.size != null && attachment.size < maxSize))
|
||||
if ((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(attachment.size != null && attachment.size < maxSize))
|
||||
async = true;
|
||||
|
||||
if (download_eml &&
|
||||
(message.raw == null || !message.raw) &&
|
||||
(state.getNetworkState().isUnmetered() || (message.total != null && message.total < maxSize)))
|
||||
((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(message.total != null && message.total < maxSize)))
|
||||
async = true;
|
||||
}
|
||||
|
||||
@@ -5350,19 +5354,22 @@ class Core {
|
||||
long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE);
|
||||
if (maxSize == 0)
|
||||
maxSize = Long.MAX_VALUE;
|
||||
boolean download_limited = prefs.getBoolean("download_limited", false);
|
||||
boolean download_eml = prefs.getBoolean("download_eml", false);
|
||||
|
||||
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
||||
|
||||
boolean fetch = false;
|
||||
if (!message.content)
|
||||
if (state.getNetworkState().isUnmetered() || (message.size != null && message.size < maxSize))
|
||||
if ((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(message.size != null && message.size < maxSize))
|
||||
fetch = true;
|
||||
|
||||
if (!fetch)
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if (!attachment.available)
|
||||
if (state.getNetworkState().isUnmetered() || (attachment.size != null && attachment.size < maxSize)) {
|
||||
if ((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(attachment.size != null && attachment.size < maxSize)) {
|
||||
fetch = true;
|
||||
break;
|
||||
}
|
||||
@@ -5391,7 +5398,7 @@ class Core {
|
||||
MessageHelper.MessageParts parts = helper.getMessageParts();
|
||||
|
||||
if (!message.content) {
|
||||
if (state.getNetworkState().isUnmetered() ||
|
||||
if ((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(message.size != null && message.size < maxSize)) {
|
||||
String body = parts.getHtml(context);
|
||||
File file = message.getFile(context);
|
||||
@@ -5421,7 +5428,7 @@ class Core {
|
||||
if (!attachment.available &&
|
||||
attachment.subsequence == null &&
|
||||
TextUtils.isEmpty(attachment.error))
|
||||
if (state.getNetworkState().isUnmetered() ||
|
||||
if ((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(attachment.size != null && attachment.size < maxSize))
|
||||
try {
|
||||
parts.downloadAttachment(context, attachment, folder);
|
||||
@@ -5435,7 +5442,8 @@ class Core {
|
||||
|
||||
if (download_eml &&
|
||||
(message.raw == null || !message.raw) &&
|
||||
(state.getNetworkState().isUnmetered() || (message.total != null && message.total < maxSize))) {
|
||||
((!download_limited && state.getNetworkState().isUnmetered()) ||
|
||||
(message.total != null && message.total < maxSize))) {
|
||||
File file = message.getRawFile(context);
|
||||
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
imessage.writeTo(os);
|
||||
|
||||
@@ -7165,6 +7165,7 @@ public class FragmentMessages extends FragmentBase
|
||||
boolean expand_all = prefs.getBoolean("expand_all", false);
|
||||
boolean autoclose_send = prefs.getBoolean("autoclose_send", false);
|
||||
long download = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE);
|
||||
boolean download_limited = prefs.getBoolean("download_limited", false);
|
||||
boolean dup_msgids = prefs.getBoolean("dup_msgids", false);
|
||||
|
||||
if (autoclose_send) {
|
||||
@@ -7304,8 +7305,9 @@ public class FragmentMessages extends FragmentBase
|
||||
expand = firstMessage;
|
||||
}
|
||||
|
||||
if (expand != null &&
|
||||
(expand.content || unmetered || (expand.size != null && expand.size < download))) {
|
||||
if (expand != null && (expand.content ||
|
||||
(!download_limited && unmetered) ||
|
||||
(expand.size != null && expand.size < download))) {
|
||||
iProperties.setExpanded(expand, true, false);
|
||||
for (int pos = 0; pos < messages.size(); pos++) {
|
||||
TupleMessageEx message = messages.get(pos);
|
||||
|
||||
@@ -81,6 +81,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
private ImageButton ibHelp;
|
||||
private SwitchCompat swMetered;
|
||||
private Spinner spDownload;
|
||||
private SwitchCompat swDownloadLimited;
|
||||
private SwitchCompat swRoaming;
|
||||
private SwitchCompat swRlah;
|
||||
private SwitchCompat swDownloadHeaders;
|
||||
@@ -118,7 +119,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
private Group grpValidated;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"metered", "download", "roaming", "rlah",
|
||||
"metered", "download", "download_limited", "roaming", "rlah",
|
||||
"download_headers", "download_eml", "download_plain",
|
||||
"require_validated", "require_validated_captive", "vpn_only",
|
||||
"timeout", "prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive",
|
||||
@@ -139,6 +140,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
ibHelp = view.findViewById(R.id.ibHelp);
|
||||
swMetered = view.findViewById(R.id.swMetered);
|
||||
spDownload = view.findViewById(R.id.spDownload);
|
||||
swDownloadLimited = view.findViewById(R.id.swDownloadLimited);
|
||||
swRoaming = view.findViewById(R.id.swRoaming);
|
||||
swRlah = view.findViewById(R.id.swRlah);
|
||||
swDownloadHeaders = view.findViewById(R.id.swDownloadHeaders);
|
||||
@@ -211,6 +213,13 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
}
|
||||
});
|
||||
|
||||
swDownloadLimited.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("download_limited", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swRoaming.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -655,6 +664,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
break;
|
||||
}
|
||||
|
||||
swDownloadLimited.setChecked(prefs.getBoolean("download_limited", false));
|
||||
|
||||
swRoaming.setChecked(prefs.getBoolean("roaming", true));
|
||||
swRlah.setChecked(prefs.getBoolean("rlah", true));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user