Added option to limit unmetered data usage

pull/214/head
M66B 9 months ago
parent e90e84b562
commit e4831098cc

@ -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));

@ -134,6 +134,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownload" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDownloadLimited"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_download_limited"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spDownload"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swRoaming"
android:layout_width="0dp"
@ -143,7 +155,7 @@
android:text="@string/title_advanced_roaming"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spDownload"
app:layout_constraintTop_toBottomOf="@id/swDownloadLimited"
app:switchPadding="12dp" />
<TextView

@ -502,6 +502,7 @@
<string name="title_advanced_metered">Use metered connections</string>
<string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string>
<string name="title_advanced_download_limited">Apply to unmetered connections too</string>
<string name="title_advanced_roaming">Download messages and attachments while roaming</string>
<string name="title_advanced_rlah">Roam like at home</string>
<string name="title_advanced_download_headers">Download all message headers</string>

Loading…
Cancel
Save