summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java
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
commitb997a2581b9a1254584f4dbfdcfe00248bf09a30 (patch)
treee54b363ebca71d24e21be89b04ca655ce2c9d82d /app/src/main/java
parentd7ea078cdf323946cea8bfcf8762f6a5a81f455c (diff)
BaseFragment: in the event no view is available, use toast
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java')
-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 510b1cae..e1d4c87b 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);
});
}