Added option to resolve connectivity

This commit is contained in:
M66B 2019-06-13 08:09:01 +02:00
parent c86ad5339a
commit a7ea56b5a0
5 changed files with 65 additions and 8 deletions

View File

@ -439,7 +439,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
long fid = args.getLong("folder");
if (!ConnectionHelper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
throw new IllegalStateException(context.getString(R.string.title_no_internet));
boolean now = true;
@ -473,7 +473,18 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
final Intent intent = ConnectionHelper.getSettingsIntent(context);
if (intent != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(intent);
}
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(context, owner, ex);

View File

@ -245,7 +245,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
try {
// Check connectivity
if (!ConnectionHelper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
throw new IllegalStateException(context.getString(R.string.title_no_internet));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.BETA_RELEASE);

View File

@ -5,6 +5,7 @@ import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.Network;
@ -305,4 +306,15 @@ public class ConnectionHelper {
return Settings.System.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
static Intent getSettingsIntent(Context context) {
Intent intent;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
else
intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
if (intent.resolveActivity(context.getPackageManager()) == null)
return null;
return intent;
}
}

View File

@ -299,7 +299,7 @@ public class FragmentFolders extends FragmentBase {
long aid = args.getLong("account");
if (!ConnectionHelper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
throw new IllegalStateException(context.getString(R.string.title_no_internet));
boolean now = true;
@ -342,7 +342,18 @@ public class FragmentFolders extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
final Intent intent = ConnectionHelper.getSettingsIntent(getContext());
if (intent != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View view) {
getContext().startActivity(intent);
}
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);

View File

@ -851,7 +851,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
long fid = args.getLong("folder");
if (!ConnectionHelper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
throw new IllegalStateException(context.getString(R.string.title_no_internet));
boolean now = true;
@ -893,7 +893,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
protected void onException(Bundle args, Throwable ex) {
manual = false;
swipeRefresh.setRefreshing(false);
if (ex instanceof IllegalArgumentException)
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
final Intent intent = ConnectionHelper.getSettingsIntent(getContext());
if (intent != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View view) {
getContext().startActivity(intent);
}
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
@ -2715,7 +2727,18 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
public void onError(Throwable ex) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
if (ex instanceof IllegalArgumentException)
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
final Intent intent = ConnectionHelper.getSettingsIntent(getContext());
if (intent != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View view) {
getContext().startActivity(intent);
}
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())