android: Add menu option to copy a profile
authorTobias Brunner <tobias@strongswan.org>
Tue, 5 Mar 2019 15:40:20 +0000 (16:40 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 5 Mar 2019 15:40:20 +0000 (16:40 +0100)
Some users requests something like that to use different server IPs.
Interestingly, it's actually also possible to configure multiple
hostnames/IPs, separated by commas, as server address in the profile, which
are then tried one after another.

It's also useful when testing stuff to quickly compare the behavior with
some setting changed between two otherwise identical profiles.

src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileListFragment.java
src/frontends/android/app/src/main/res/menu/profile_list_context.xml
src/frontends/android/app/src/main/res/values-de/strings.xml
src/frontends/android/app/src/main/res/values-pl/strings.xml
src/frontends/android/app/src/main/res/values-ru/strings.xml
src/frontends/android/app/src/main/res/values-ua/strings.xml
src/frontends/android/app/src/main/res/values-zh-rCN/strings.xml
src/frontends/android/app/src/main/res/values-zh-rTW/strings.xml
src/frontends/android/app/src/main/res/values/strings.xml

index 4a3ed9f..904b434 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2018 Tobias Brunner
+ * Copyright (C) 2012-2019 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
  * HSR Hochschule fuer Technik Rapperswil
@@ -49,6 +49,7 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.UUID;
 
 public class VpnProfileListFragment extends Fragment
 {
@@ -230,11 +231,13 @@ public class VpnProfileListFragment extends Fragment
 
        private final MultiChoiceModeListener mVpnProfileSelected = new MultiChoiceModeListener() {
                private MenuItem mEditProfile;
+               private MenuItem mCopyProfile;
 
                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu)
                {
                        mEditProfile.setEnabled(mSelected.size() == 1);
+                       mCopyProfile.setEnabled(mEditProfile.isEnabled());
                        return true;
                }
 
@@ -250,6 +253,7 @@ public class VpnProfileListFragment extends Fragment
                        MenuInflater inflater = mode.getMenuInflater();
                        inflater.inflate(R.menu.profile_list_context, menu);
                        mEditProfile = menu.findItem(R.id.edit_profile);
+                       mCopyProfile = menu.findItem(R.id.copy_profile);
                        mode.setTitle(R.string.select_profiles);
                        return true;
                }
@@ -268,6 +272,24 @@ public class VpnProfileListFragment extends Fragment
                                        startActivityForResult(connectionIntent, EDIT_REQUEST);
                                        break;
                                }
+                               case R.id.copy_profile:
+                               {
+                                       int position = mSelected.iterator().next();
+                                       VpnProfile profile = (VpnProfile)mListView.getItemAtPosition(position);
+                                       profile = profile.clone();
+                                       profile.setUUID(UUID.randomUUID());
+                                       profile.setName(String.format(getString(R.string.copied_name), profile.getName()));
+                                       mDataSource.insertProfile(profile);
+
+                                       Intent intent = new Intent(Constants.VPN_PROFILES_CHANGED);
+                                       intent.putExtra(Constants.VPN_PROFILES_SINGLE, profile.getId());
+                                       LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
+
+                                       Intent connectionIntent = new Intent(getActivity(), VpnProfileDetailActivity.class);
+                                       connectionIntent.putExtra(VpnProfileDataSource.KEY_ID, profile.getId());
+                                       startActivityForResult(connectionIntent, EDIT_REQUEST);
+                                       break;
+                               }
                                case R.id.delete_profile:
                                {
                                        ArrayList<VpnProfile> profiles = new ArrayList<>();
index 8957c74..0018988 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Tobias Brunner
+    Copyright (C) 2012-2019 Tobias Brunner
     HSR Hochschule fuer Technik Rapperswil
 
     This program is free software; you can redistribute it and/or modify it
@@ -18,6 +18,9 @@
     <item android:id="@+id/edit_profile"
         android:title="@string/edit_profile" />
 
+    <item android:id="@+id/copy_profile"
+        android:title="@string/copy_profile" />
+
     <item android:id="@+id/delete_profile"
         android:title="@string/delete_profile" />
 
index ee9bbcb..8f1e99a 100644 (file)
@@ -47,6 +47,8 @@
     <string name="no_profiles">Keine VPN Profile vorhanden.</string>
     <string name="add_profile">Profil hinzufügen</string>
     <string name="edit_profile">Bearbeiten</string>
+    <string name="copy_profile">Kopieren</string>
+    <string name="copied_name">%1$s (Kopie)</string>
     <string name="delete_profile">Löschen</string>
     <string name="select_profiles">Profile auswählen</string>
     <string name="profiles_deleted">Ausgewählte Profile gelöscht</string>
index 6297cec..bd80077 100644 (file)
@@ -47,6 +47,8 @@
     <string name="no_profiles">Brak profilu VPN</string>
     <string name="add_profile">Dodaj profil VPN</string>
     <string name="edit_profile">Edytuj</string>
+    <string name="copy_profile">Copy</string>
+    <string name="copied_name">%1$s (Copy)</string>
     <string name="delete_profile">Usuń</string>
     <string name="select_profiles">Wybierz profile</string>
     <string name="profiles_deleted">Wybrane profile usunięte</string>
index b26ca1e..5f796bd 100644 (file)
@@ -44,6 +44,8 @@
     <string name="no_profiles">VPN профили не обнаружены.</string>
     <string name="add_profile">Добавить VPN профиль</string>
     <string name="edit_profile">Редактировать</string>
+    <string name="copy_profile">Copy</string>
+    <string name="copied_name">%1$s (Copy)</string>
     <string name="delete_profile">Удалить</string>
     <string name="select_profiles">Выбрать профили</string>
     <string name="profiles_deleted">Выбранные профили удалены</string>
index 53eb2ba..e385df5 100644 (file)
@@ -45,6 +45,8 @@
     <string name="no_profiles">Немає VPN профілів</string>
     <string name="add_profile">Додати VPN профіль</string>
     <string name="edit_profile">Редагувати</string>
+    <string name="copy_profile">Copy</string>
+    <string name="copied_name">%1$s (Copy)</string>
     <string name="delete_profile">Видалити</string>
     <string name="select_profiles">Обрати профіль</string>
     <string name="profiles_deleted">Обрані профілі видалено</string>
index 85d536f..bb6e70d 100644 (file)
@@ -44,6 +44,8 @@
     <string name="no_profiles">无配置.</string>
     <string name="add_profile">添加VPN配置</string>
     <string name="edit_profile">编辑</string>
+    <string name="copy_profile">Copy</string>
+    <string name="copied_name">%1$s (Copy)</string>
     <string name="delete_profile">删除</string>
     <string name="select_profiles">选择配置</string>
     <string name="profiles_deleted">所选配置已删除</string>
index 9299d24..a1777b6 100644 (file)
@@ -44,6 +44,8 @@
     <string name="no_profiles">沒有設定檔</string>
     <string name="add_profile">新增VPN設定檔</string>
     <string name="edit_profile">編輯</string>
+    <string name="copy_profile">Copy</string>
+    <string name="copied_name">%1$s (Copy)</string>
     <string name="delete_profile">刪除</string>
     <string name="select_profiles">選擇設定檔</string>
     <string name="profiles_deleted">選擇的設定檔已經刪除</string>
index fb8cf85..9797f57 100644 (file)
@@ -47,6 +47,8 @@
     <string name="no_profiles">No VPN profiles.</string>
     <string name="add_profile">Add VPN profile</string>
     <string name="edit_profile">Edit</string>
+    <string name="copy_profile">Copy</string>
+    <string name="copied_name">%1$s (Copy)</string>
     <string name="delete_profile">Delete</string>
     <string name="select_profiles">Select profiles</string>
     <string name="profiles_deleted">Selected profiles deleted</string>