summaryrefslogtreecommitdiff
path: root/remoteExample/src/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-10-04 04:18:35 +0200
committerArne Schwabe <arne@rfc2549.org>2021-10-04 04:18:35 +0200
commitd54ba7a09d0fd1301f0122070005b914ef70d128 (patch)
treeb8c5ae4b686601c9b58f276f6969a4ff0e25eaa4 /remoteExample/src/main
parent650e238b7676393cd426a7cdb86fcc4fd2d87a6d (diff)
Add check to start profile when importing to remote Example
Diffstat (limited to 'remoteExample/src/main')
-rw-r--r--remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java25
-rw-r--r--remoteExample/src/main/res/layout/fragment_main.xml12
-rw-r--r--remoteExample/src/main/res/values/strings.xml1
3 files changed, 22 insertions, 16 deletions
diff --git a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java
index 46699434..14fa3887 100644
--- a/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java
+++ b/remoteExample/src/main/java/de/blinkt/openvpn/remote/MainFragment.java
@@ -20,6 +20,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
@@ -80,7 +81,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
- private void startEmbeddedProfile(boolean addNew, boolean editable)
+ private void startEmbeddedProfile(boolean addNew, boolean editable, boolean startAfterAdd)
{
try {
InputStream conf;
@@ -105,7 +106,9 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
if (addNew) {
String name = editable ? "Profile from remote App" : "Non editable profile";
- mService.addNewVPNProfile(name, editable, config.toString());
+ APIVpnProfile profile = mService.addNewVPNProfile(name, editable, config.toString());
+ mService.startProfile(profile.mUUID);
+
} else
mService.startVPN(config.toString());
} catch (IOException | RemoteException e) {
@@ -276,21 +279,14 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
break;
case R.id.addNewProfile:
- try {
- prepareStartProfile(PROFILE_ADD_NEW);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
case R.id.addNewProfileEdit:
+ int action = (v.getId() == R.id.addNewProfile) ? PROFILE_ADD_NEW : PROFILE_ADD_NEW_EDIT;
try {
- prepareStartProfile(PROFILE_ADD_NEW_EDIT);
+ prepareStartProfile(action);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
default:
break;
}
@@ -310,7 +306,7 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if(requestCode==START_PROFILE_EMBEDDED)
- startEmbeddedProfile(false, false);
+ startEmbeddedProfile(false, false, false);
if(requestCode==START_PROFILE_BYUUID)
try {
mService.startProfile(mStartUUID);
@@ -326,11 +322,12 @@ public class MainFragment extends Fragment implements View.OnClickListener, Hand
}
}
+ CheckBox startCB = getView().findViewById(R.id.startafterAdding);
if (requestCode == PROFILE_ADD_NEW) {
- startEmbeddedProfile(true, false);
+ startEmbeddedProfile(true, false, startCB.isSelected());
}
else if (requestCode == PROFILE_ADD_NEW_EDIT) {
- startEmbeddedProfile(true, true);
+ startEmbeddedProfile(true, true, startCB.isSelected());
}
}
};
diff --git a/remoteExample/src/main/res/layout/fragment_main.xml b/remoteExample/src/main/res/layout/fragment_main.xml
index 0cc953f6..6b8102e2 100644
--- a/remoteExample/src/main/res/layout/fragment_main.xml
+++ b/remoteExample/src/main/res/layout/fragment_main.xml
@@ -47,12 +47,12 @@
android:layout_alignParentLeft="true"
tools:text="TextView" />
- <Button
+ <Button
android:id="@+id/getMyIP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
android:layout_below="@+id/startVPN"
+ android:layout_alignParentLeft="true"
android:text="@string/show_my_ip" />
<Button
@@ -92,4 +92,12 @@
android:layout_toRightOf="@+id/addNewProfile"
android:text="@string/addNewEdit" />
+ <CheckBox
+ android:id="@+id/startafterAdding"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/startembedded"
+ android:layout_marginTop="4dp"
+ android:text="@string/start_profile_after_adding" />
+
</RelativeLayout>
diff --git a/remoteExample/src/main/res/values/strings.xml b/remoteExample/src/main/res/values/strings.xml
index 5bb63fc3..971f7de5 100644
--- a/remoteExample/src/main/res/values/strings.xml
+++ b/remoteExample/src/main/res/values/strings.xml
@@ -17,6 +17,7 @@
<string name="start_embedded">Start embedded profile</string>
<string name="addNew">Add new Profile</string>
<string name="addNewEdit">Add editable profile</string>
+ <string name="start_profile_after_adding">Start profile after adding</string>
</resources>