ProfileList: Toggle connection state on click
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
b6653fd7f0
commit
411b0716f2
@ -8,8 +8,12 @@ import android.content.ServiceConnection;
|
|||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
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.android.databinding.ProfileListActivityBinding;
|
||||||
|
import com.wireguard.config.Profile;
|
||||||
|
|
||||||
public class ProfileListActivity extends Activity {
|
public class ProfileListActivity extends Activity {
|
||||||
private final ServiceConnection connection = new ProfileServiceConnection();
|
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.
|
// Ensure the long-running service is started. This only needs to happen once.
|
||||||
Intent intent = new Intent(this, ProfileService.class);
|
Intent intent = new Intent(this, ProfileService.class);
|
||||||
startService(intent);
|
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
|
@Override
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
</data>
|
</data>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
android:id="@+id/profile_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:items="@{profiles}"
|
app:items="@{profiles}"
|
||||||
|
Loading…
Reference in New Issue
Block a user