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
public void onError(Throwable ex) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex))
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.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.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.sun.mail.iap.Argument;
import com.sun.mail.iap.Response;
@ -154,6 +156,13 @@ public class ViewModelBrowse extends ViewModel {
EntityAccount account = db.account().getAccount(folder.account);
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);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);

Loading…
Cancel
Save