mirror of https://github.com/M66B/FairEmail.git
Skip downloading messages when roaming
This commit is contained in:
parent
37de0f0112
commit
a018704ac8
|
@ -1417,6 +1417,9 @@ class Core {
|
|||
Context context,
|
||||
EntityFolder folder, IMAPFolder ifolder,
|
||||
IMAPMessage imessage, long id, State state) throws MessagingException, IOException {
|
||||
if (state.getNetworkState().isRoaming())
|
||||
return;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message == null)
|
||||
|
|
|
@ -68,6 +68,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
private TextView tvScheduleEnd;
|
||||
|
||||
private TextView tvConnectionType;
|
||||
private TextView tvConnectionRoaming;
|
||||
private SwitchCompat swMetered;
|
||||
private Spinner spDownload;
|
||||
|
||||
|
@ -151,6 +152,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
tvScheduleEnd = view.findViewById(R.id.tvScheduleEnd);
|
||||
|
||||
tvConnectionType = view.findViewById(R.id.tvConnectionType);
|
||||
tvConnectionRoaming = view.findViewById(R.id.tvConnectionRoaming);
|
||||
swMetered = view.findViewById(R.id.swMetered);
|
||||
spDownload = view.findViewById(R.id.spDownload);
|
||||
|
||||
|
@ -789,6 +791,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
|
||||
tvConnectionType.setText(networkState.isUnmetered() ? R.string.title_legend_unmetered : R.string.title_legend_metered);
|
||||
tvConnectionType.setVisibility(networkState.isConnected() ? View.VISIBLE : View.GONE);
|
||||
tvConnectionRoaming.setVisibility(networkState.isRoaming() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -780,6 +780,7 @@ public class Helper {
|
|||
private Boolean connected = null;
|
||||
private Boolean suitable = null;
|
||||
private Boolean unmetered = null;
|
||||
private Boolean roaming = null;
|
||||
|
||||
boolean isConnected() {
|
||||
return (connected != null && connected);
|
||||
|
@ -793,6 +794,10 @@ public class Helper {
|
|||
return (unmetered != null && unmetered);
|
||||
}
|
||||
|
||||
boolean isRoaming() {
|
||||
return (roaming != null && roaming);
|
||||
}
|
||||
|
||||
public void update(NetworkState newState) {
|
||||
connected = newState.connected;
|
||||
unmetered = newState.unmetered;
|
||||
|
@ -809,6 +814,23 @@ public class Helper {
|
|||
state.connected = (isMetered != null);
|
||||
state.unmetered = (isMetered != null && !isMetered);
|
||||
state.suitable = (isMetered != null && (metered || !isMetered));
|
||||
|
||||
if (state.connected) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
NetworkInfo ani = cm.getActiveNetworkInfo();
|
||||
if (ani != null)
|
||||
state.roaming = ani.isRoaming();
|
||||
} else {
|
||||
Network active = cm.getActiveNetwork();
|
||||
if (active != null) {
|
||||
NetworkCapabilities caps = cm.getNetworkCapabilities(active);
|
||||
if (caps != null)
|
||||
state.roaming = !caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,6 +149,19 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/vSeparatorConnection" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvConnectionRoaming"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:text="@string/title_legend_roaming"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvConnectionType" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swMetered"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -158,7 +171,7 @@
|
|||
android:layout_marginEnd="12dp"
|
||||
android:text="@string/title_advanced_metered"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvConnectionType"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvConnectionRoaming"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -550,6 +550,7 @@
|
|||
|
||||
<string name="title_legend_metered">Connection is metered</string>
|
||||
<string name="title_legend_unmetered">Connection is unmetered</string>
|
||||
<string name="title_legend_roaming">Roaming</string>
|
||||
|
||||
<string name="title_legend_expander">Expander</string>
|
||||
<string name="title_legend_avatar">Avatar</string>
|
||||
|
|
Loading…
Reference in New Issue