ProfileList: Extract service management into a base class

It will be shared with other fragments.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland
2017-08-04 12:39:56 -05:00
parent 81ab643d2b
commit 93e304ba2d
2 changed files with 39 additions and 25 deletions
@@ -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;
}
}