mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 15:46:34 +02:00
Manage connectivity on no connection
This commit is contained in:
@@ -482,14 +482,14 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
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.setAction(R.string.title_fix, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
context.startActivity(
|
||||
new Intent(context, ActivitySetup.class)
|
||||
.putExtra("tab", "connection"));
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else if (ex instanceof IllegalArgumentException)
|
||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||
|
||||
@@ -5,7 +5,6 @@ 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,15 +304,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,14 +344,14 @@ public class FragmentFolders extends FragmentBase {
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
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.setAction(R.string.title_fix, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getContext().startActivity(
|
||||
new Intent(getContext(), ActivitySetup.class)
|
||||
.putExtra("tab", "connection"));
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else if (ex instanceof IllegalArgumentException)
|
||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||
|
||||
@@ -896,14 +896,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
|
||||
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.setAction(R.string.title_fix, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getContext().startActivity(
|
||||
new Intent(getContext(), ActivitySetup.class)
|
||||
.putExtra("tab", "connection"));
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else if (ex instanceof IllegalArgumentException)
|
||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||
@@ -2730,14 +2730,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
|
||||
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.setAction(R.string.title_fix, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getContext().startActivity(
|
||||
new Intent(getContext(), ActivitySetup.class)
|
||||
.putExtra("tab", "connection"));
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else if (ex instanceof IllegalArgumentException)
|
||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||
|
||||
@@ -63,7 +63,9 @@ public class FragmentOptions extends FragmentBase {
|
||||
tabLayout.setupWithViewPager(pager);
|
||||
|
||||
String tab = getActivity().getIntent().getStringExtra("tab");
|
||||
if ("display".equals(tab))
|
||||
if ("connection".equals(tab))
|
||||
pager.setCurrentItem(3);
|
||||
else if ("display".equals(tab))
|
||||
pager.setCurrentItem(4);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -121,8 +123,11 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
}
|
||||
});
|
||||
|
||||
final Intent manage = ConnectionHelper.getSettingsIntent(getContext());
|
||||
btnManage.setVisibility(manage == null ? View.GONE : View.VISIBLE);
|
||||
final Intent manage = getIntentConnectivity();
|
||||
btnManage.setVisibility(
|
||||
manage.resolveActivity(getContext().getPackageManager()) == null
|
||||
? View.GONE : View.VISIBLE);
|
||||
|
||||
btnManage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -215,6 +220,13 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
|
||||
swRlah.setChecked(prefs.getBoolean("rlah", true));
|
||||
}
|
||||
|
||||
private static Intent getIntentConnectivity() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||
return new Intent(Settings.ACTION_WIRELESS_SETTINGS);
|
||||
else
|
||||
return new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
|
||||
}
|
||||
|
||||
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
|
||||
@Override
|
||||
public void onAvailable(@NonNull Network network) {
|
||||
|
||||
Reference in New Issue
Block a user