aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-15 17:36:11 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-15 17:36:11 -0500
commit61d6b89bbeeefd56af4886579db741ece0d88dc8 (patch)
treefad8e18ef9848df131c87261e72f8c6a3f761581 /app/src/main/java/com/wireguard/android/ConfigEditFragment.java
parentBaseConfigActivity: Set initial config when service available (diff)
downloadwireguard-android-61d6b89bbeeefd56af4886579db741ece0d88dc8.tar.xz
wireguard-android-61d6b89bbeeefd56af4886579db741ece0d88dc8.zip
ConfigAddActivity: Add an standalone config-creating activity
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/ConfigEditFragment.java')
-rw-r--r--app/src/main/java/com/wireguard/android/ConfigEditFragment.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/src/main/java/com/wireguard/android/ConfigEditFragment.java b/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
index 488d7915..7cbcfddd 100644
--- a/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
+++ b/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
@@ -12,6 +12,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
+import android.widget.Toast;
import com.wireguard.android.databinding.ConfigEditFragmentBinding;
import com.wireguard.config.Config;
@@ -73,7 +74,15 @@ public class ConfigEditFragment extends BaseConfigFragment {
private void saveConfig() {
// FIXME: validate input
- VpnService.getInstance().update(getCurrentConfig().getName(), localConfig);
+ try {
+ if (getCurrentConfig() != null)
+ VpnService.getInstance().update(getCurrentConfig().getName(), localConfig);
+ else
+ VpnService.getInstance().add(localConfig);
+ } catch (final IllegalStateException e) {
+ Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
+ return;
+ }
// Hide the keyboard; it rarely goes away on its own.
final BaseConfigActivity activity = (BaseConfigActivity) getActivity();
final View focusedView = activity.getCurrentFocus();
@@ -83,7 +92,7 @@ public class ConfigEditFragment extends BaseConfigFragment {
inputManager.hideSoftInputFromWindow(focusedView.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
- // Tell the activity to go back to the detail view.
+ // Tell the activity to finish itself or go back to the detail view.
activity.setCurrentConfig(localConfig);
}
}