aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-07-09 17:29:24 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-09 17:29:35 +0200
commit67f17fbcf76ac726486f5e88a016fd055bc3bede (patch)
treee54b363ebca71d24e21be89b04ca655ce2c9d82d
parentRequest VPN permissions on activation (diff)
downloadwireguard-android-67f17fbcf76ac726486f5e88a016fd055bc3bede.tar.xz
wireguard-android-67f17fbcf76ac726486f5e88a016fd055bc3bede.zip
BaseFragment: in the event no view is available, use toast
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/BaseFragment.java15
1 files changed, 7 insertions, 8 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java b/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java
index 510b1ca..e1d4c87 100644
--- a/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java
@@ -15,6 +15,7 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;
+import android.widget.Toast;
import com.wireguard.android.Application;
import com.wireguard.android.R;
@@ -109,16 +110,14 @@ public abstract class BaseFragment extends Fragment implements OnSelectedTunnelC
tunnel.setState(State.of(checked)).whenComplete((state, throwable) -> {
if (throwable == null)
return;
- final View view = getView();
- if (view == null) {
- Log.e(TAG, "setTunnelStateWithPermissionsResult() with no view");
- return;
- }
- final Context context = view.getContext();
final String error = ExceptionLoggers.unwrapMessage(throwable);
final int messageResId = checked ? R.string.error_up : R.string.error_down;
- final String message = context.getString(messageResId, error);
- Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
+ final String message = getContext().getString(messageResId, error);
+ final View view = getView();
+ if (view != null)
+ Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
+ else
+ Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
Log.e(TAG, message, throwable);
});
}