Check connectivity on browse

pull/152/head
M66B 6 years ago
parent 794e05df64
commit 39b4715915

@ -1948,11 +1948,14 @@ public class FragmentMessages extends FragmentBase {
@Override @Override
public void onError(Throwable ex) { public void onError(Throwable ex) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) if (ex instanceof IllegalArgumentException)
.setMessage(Helper.formatThrowable(ex)) Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
.setPositiveButton(android.R.string.cancel, null) else
.create() new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.show(); .setMessage(Helper.formatThrowable(ex))
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();
} }
}); });

@ -20,6 +20,8 @@ package eu.faircode.email;
*/ */
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.sun.mail.iap.Argument; import com.sun.mail.iap.Argument;
import com.sun.mail.iap.Response; import com.sun.mail.iap.Response;
@ -154,6 +156,13 @@ public class ViewModelBrowse extends ViewModel {
EntityAccount account = db.account().getAccount(folder.account); EntityAccount account = db.account().getAccount(folder.account);
try { try {
// Check connectivity
ConnectivityManager cm = (ConnectivityManager) state.context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
boolean internet = (ni != null && ni.isConnected());
if (!internet)
throw new IllegalArgumentException(state.context.getString(R.string.title_no_internet));
Properties props = MessageHelper.getSessionProperties(account.auth_type, account.realm, account.insecure); Properties props = MessageHelper.getSessionProperties(account.auth_type, account.realm, account.insecure);
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
isession.setDebug(true); isession.setDebug(true);

Loading…
Cancel
Save