summaryrefslogtreecommitdiffhomepage
path: root/app/src
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-04 12:39:56 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-04 12:39:56 -0500
commit93e304ba2df55a89fb94c9540c16314440f054b8 (patch)
tree80a521d1fe788b70d07b0264fe80724f0f33bf24 /app/src
parent81ab643d2bf17b7ac5c70efa6f33e0737969cf85 (diff)
ProfileList: Extract service management into a base class
It will be shared with other fragments. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileActivityFragment.java37
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileListFragment.java27
2 files changed, 39 insertions, 25 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java b/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java
new file mode 100644
index 00000000..da394204
--- /dev/null
+++ b/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java
@@ -0,0 +1,37 @@
+package com.wireguard.android;
+
+import android.app.Fragment;
+import android.content.Context;
+
+/**
+ * Base class for fragments that are part of a ProfileActivity.
+ */
+
+public class ProfileActivityFragment extends Fragment implements ServiceConnectionListener {
+ private ProfileActivity activity;
+ protected ProfileServiceInterface service;
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ activity = (ProfileActivity) context;
+ activity.addServiceConnectionListener(this);
+ service = activity.getService();
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ activity.removeServiceConnectionListener(this);
+ }
+
+ @Override
+ public void onServiceConnected(ProfileServiceInterface service) {
+ this.service = service;
+ }
+
+ @Override
+ public void onServiceDisconnected() {
+ service = null;
+ }
+}
diff --git a/app/src/main/java/com/wireguard/android/ProfileListFragment.java b/app/src/main/java/com/wireguard/android/ProfileListFragment.java
index 1dfa9b77..f794e54f 100644
--- a/app/src/main/java/com/wireguard/android/ProfileListFragment.java
+++ b/app/src/main/java/com/wireguard/android/ProfileListFragment.java
@@ -1,7 +1,5 @@
package com.wireguard.android;
-import android.app.Fragment;
-import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -16,18 +14,8 @@ import com.wireguard.config.Profile;
* Fragment containing the list of available WireGuard profiles. Must be part of a ProfileActivity.
*/
-public class ProfileListFragment extends Fragment implements ServiceConnectionListener {
- private ProfileActivity activity;
+public class ProfileListFragment extends ProfileActivityFragment {
private ProfileListFragmentBinding binding;
- private ProfileServiceInterface service;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- activity = (ProfileActivity) context;
- activity.addServiceConnectionListener(this);
- service = activity.getService();
- }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
@@ -58,19 +46,8 @@ public class ProfileListFragment extends Fragment implements ServiceConnectionLi
}
@Override
- public void onDetach() {
- super.onDetach();
- activity.removeServiceConnectionListener(this);
- }
-
- @Override
public void onServiceConnected(ProfileServiceInterface service) {
- this.service = service;
+ super.onServiceConnected(service);
binding.setProfiles(service.getProfiles());
}
-
- @Override
- public void onServiceDisconnected() {
- service = null;
- }
}