ProfileServiceInterface: Update for map-based collection

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-07 20:19:29 -05:00
parent 01524c0dbf
commit 3076fd8c41
3 changed files with 31 additions and 32 deletions

View File

@ -36,9 +36,9 @@ public class ProfileListFragment extends ProfileActivityFragment {
if (profile == null || service == null) if (profile == null || service == null)
return false; return false;
if (profile.getIsConnected()) if (profile.getIsConnected())
service.disconnectProfile(profile); service.disconnectProfile(profile.getName());
else else
service.connectProfile(profile); service.connectProfile(profile.getName());
return true; return true;
} }
}); });

View File

@ -215,26 +215,23 @@ public class ProfileService extends Service {
private class ProfileServiceBinder extends Binder implements ProfileServiceInterface { private class ProfileServiceBinder extends Binder implements ProfileServiceInterface {
@Override @Override
public void connectProfile(Profile profile) { public void connectProfile(String name) {
if (profiles.get(profile.getName()) != profile) final Profile profile = profiles.get(name);
return; if (profile == null || profile.getIsConnected())
if (profile.getIsConnected())
return; return;
new ProfileConnecter(profile).execute(); new ProfileConnecter(profile).execute();
} }
@Override @Override
public Profile copyProfileForEditing(Profile profile) { public Profile copyProfileForEditing(String name) {
if (profiles.get(profile.getName()) != profile) final Profile profile = profiles.get(name);
return null; return profile != null ? profile.copy() : null;
return profile.copy();
} }
@Override @Override
public void disconnectProfile(Profile profile) { public void disconnectProfile(String name) {
if (profiles.get(profile.getName()) != profile) final Profile profile = profiles.get(name);
return; if (profile == null || !profile.getIsConnected())
if (!profile.getIsConnected())
return; return;
new ProfileDisconnecter(profile).execute(); new ProfileDisconnecter(profile).execute();
} }
@ -245,8 +242,9 @@ public class ProfileService extends Service {
} }
@Override @Override
public void removeProfile(Profile profile) { public void removeProfile(String name) {
if (profiles.get(profile.getName()) != profile) final Profile profile = profiles.get(name);
if (profile == null)
return; return;
if (profile.getIsConnected()) if (profile.getIsConnected())
new ProfileDisconnecter(profile).execute(); new ProfileDisconnecter(profile).execute();
@ -254,9 +252,10 @@ public class ProfileService extends Service {
} }
@Override @Override
public void saveProfile(Profile oldProfile, Profile newProfile) { public void saveProfile(String oldName, Profile newProfile) {
if (oldProfile != null) { if (oldName != null) {
if (profiles.get(oldProfile.getName()) != oldProfile) final Profile oldProfile = profiles.get(oldName);
if (oldProfile == null)
return; return;
final boolean wasConnected = oldProfile.getIsConnected(); final boolean wasConnected = oldProfile.getIsConnected();
if (wasConnected) if (wasConnected)

View File

@ -14,35 +14,35 @@ public interface ProfileServiceInterface {
* will be updated if connection is successful. If this profile is already connected, or it is * will be updated if connection is successful. If this profile is already connected, or it is
* not a known profile, no changes will be made. * not a known profile, no changes will be made.
* *
* @param profile The profile (in the list of known profiles) to use for this connection. * @param name The profile (in the list of known profiles) to use for this connection.
*/ */
void connectProfile(Profile profile); void connectProfile(String name);
/** /**
* Creates a deep copy of an existing profile that can be modified and then passed to * Creates a deep copy of an existing profile that can be modified and then passed to
* saveProfile. If the given profile is not a known profile, or the profile cannot be copied, * saveProfile. If the given profile is not a known profile, or the profile cannot be copied,
* this function returns null. * this function returns null.
* *
* @param profile The existing profile (in the list of known profiles) to copy. * @param name The existing profile (in the list of known profiles) to copy.
* @return A copy of the profile that can be freely modified. * @return A copy of the profile that can be freely modified.
*/ */
Profile copyProfileForEditing(Profile profile); Profile copyProfileForEditing(String name);
/** /**
* Attempt to disable and tear down an interface for this profile. The profile's connection * Attempt to disable and tear down an interface for this profile. The profile's connection
* state will be updated if disconnection is successful. If this profile is already * state will be updated if disconnection is successful. If this profile is already
* disconnected, or it is not a known profile, no changes will be made. * disconnected, or it is not a known profile, no changes will be made.
* *
* @param profile The profile (in the list of known profiles) to disconnect. * @param name The profile (in the list of known profiles) to disconnect.
*/ */
void disconnectProfile(Profile profile); void disconnectProfile(String name);
/** /**
* Retrieve a list of profiles known and managed by this service. Profiles in this list must not * Retrieve the set of profiles known and managed by this service. Profiles in this list must
* be modified directly. If a profile is to be updated, first create a copy of it by calling * not be modified directly. If a profile is to be updated, first create a copy of it by calling
* copyProfileForEditing(). * copyProfileForEditing().
* *
* @return The list of known profiles. * @return The set of known profiles.
*/ */
ObservableArrayMap<String, Profile> getProfiles(); ObservableArrayMap<String, Profile> getProfiles();
@ -52,9 +52,9 @@ public interface ProfileServiceInterface {
* will be removed from persistent storage. If the profile is not a known profile, no changes * will be removed from persistent storage. If the profile is not a known profile, no changes
* will be made. * will be made.
* *
* @param profile The profile (in the list of known profiles) to remove. * @param name The profile (in the list of known profiles) to remove.
*/ */
void removeProfile(Profile profile); void removeProfile(String name);
/** /**
* Replace the given profile, or add a new profile if oldProfile is null. * Replace the given profile, or add a new profile if oldProfile is null.
@ -63,8 +63,8 @@ public interface ProfileServiceInterface {
* it will be set to the disconnected state. If successful, configuration for this profile will * it will be set to the disconnected state. If successful, configuration for this profile will
* be saved to persistent storage. * be saved to persistent storage.
* *
* @param oldProfile The existing profile to replace, or null to add the new profile. * @param oldName The existing profile to replace, or null to add the new profile.
* @param newProfile The profile to add, or a copy of the profile to replace. * @param newProfile The profile to add, or a copy of the profile to replace.
*/ */
void saveProfile(Profile oldProfile, Profile newProfile); void saveProfile(String oldName, Profile newProfile);
} }