summaryrefslogtreecommitdiffhomepage
path: root/app/src
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-07-31 21:30:51 -0500
committerSamuel Holland <samuel@sholland.org>2017-07-31 21:30:51 -0500
commit411b0716f2747b6607c7394f5871a2f19824da8d (patch)
treeaa17703141e89fab2d0aac990d64262ecfd46e81 /app/src
parentb6653fd7f0d28e411c544353194cdfb63016516e (diff)
ProfileList: Toggle connection state on click
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileListActivity.java18
-rw-r--r--app/src/main/res/layout/profile_list_activity.xml1
2 files changed, 19 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileListActivity.java b/app/src/main/java/com/wireguard/android/ProfileListActivity.java
index 9094efaf..f56092e8 100644
--- a/app/src/main/java/com/wireguard/android/ProfileListActivity.java
+++ b/app/src/main/java/com/wireguard/android/ProfileListActivity.java
@@ -8,8 +8,12 @@ import android.content.ServiceConnection;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.IBinder;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListView;
import com.wireguard.android.databinding.ProfileListActivityBinding;
+import com.wireguard.config.Profile;
public class ProfileListActivity extends Activity {
private final ServiceConnection connection = new ProfileServiceConnection();
@@ -23,6 +27,20 @@ public class ProfileListActivity extends Activity {
// Ensure the long-running service is started. This only needs to happen once.
Intent intent = new Intent(this, ProfileService.class);
startService(intent);
+
+ ListView listView = findViewById(R.id.profile_list);
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Profile profile = (Profile) parent.getItemAtPosition(position);
+ if (profile == null || service == null)
+ return;
+ if (profile.getIsConnected())
+ service.disconnectProfile(profile);
+ else
+ service.connectProfile(profile);
+ }
+ });
}
@Override
diff --git a/app/src/main/res/layout/profile_list_activity.xml b/app/src/main/res/layout/profile_list_activity.xml
index 4e7b251f..29ce62e7 100644
--- a/app/src/main/res/layout/profile_list_activity.xml
+++ b/app/src/main/res/layout/profile_list_activity.xml
@@ -10,6 +10,7 @@
</data>
<ListView
+ android:id="@+id/profile_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:items="@{profiles}"