From: Tobias Brunner Date: Tue, 5 Mar 2019 15:40:20 +0000 (+0100) Subject: android: Add menu option to copy a profile X-Git-Tag: 5.8.0dr2~12^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=94cb3b4ddd7a035be7fbe38bc0aa8ddb7d156c67;p=thirdparty%2Fstrongswan.git android: Add menu option to copy a profile 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. --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileListFragment.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileListFragment.java index 4a3ed9f194..904b4341c1 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileListFragment.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileListFragment.java @@ -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 profiles = new ArrayList<>(); diff --git a/src/frontends/android/app/src/main/res/menu/profile_list_context.xml b/src/frontends/android/app/src/main/res/menu/profile_list_context.xml index 8957c74134..0018988426 100644 --- a/src/frontends/android/app/src/main/res/menu/profile_list_context.xml +++ b/src/frontends/android/app/src/main/res/menu/profile_list_context.xml @@ -1,6 +1,6 @@