diff --git a/app/src/main/java/com/wireguard/android/ProfileDetailFragment.java b/app/src/main/java/com/wireguard/android/ProfileDetailFragment.java index 4af7fb25..2aa40c06 100644 --- a/app/src/main/java/com/wireguard/android/ProfileDetailFragment.java +++ b/app/src/main/java/com/wireguard/android/ProfileDetailFragment.java @@ -10,22 +10,15 @@ import android.view.ViewGroup; import com.wireguard.android.databinding.ProfileDetailFragmentBinding; /** - * Fragment for viewing and editing a WireGuard profile. + * Fragment for viewing information about a WireGuard profile. */ -public class ProfileDetailFragment extends ServiceClientFragment { +public class ProfileDetailFragment extends ProfileFragment { private ProfileDetailFragmentBinding binding; - private String name; - - public ProfileDetailFragment() { - super(); - setArguments(new Bundle()); - } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - name = getArguments().getString(ProfileActivity.KEY_PROFILE_NAME); setHasOptionsMenu(true); } @@ -37,20 +30,20 @@ public class ProfileDetailFragment extends ServiceClientFragment { + private Profile cachedProfile; + private String profile; + + protected Profile getCachedProfile() { + return cachedProfile; + } + + public String getProfile() { + return profile; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Restore the saved profile if there is one; otherwise grab it from the arguments. + if (savedInstanceState != null) + profile = savedInstanceState.getString(ProfileActivity.KEY_PROFILE_NAME); + else if (getArguments() != null) + profile = getArguments().getString(ProfileActivity.KEY_PROFILE_NAME); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString(ProfileActivity.KEY_PROFILE_NAME, profile); + } + + @Override + public void onServiceConnected(ProfileServiceInterface service) { + super.onServiceConnected(service); + cachedProfile = service.getProfiles().get(profile); + } + + public void setProfile(String profile) { + this.profile = profile; + final ProfileServiceInterface service = getService(); + if (service != null) + cachedProfile = service.getProfiles().get(profile); + else + cachedProfile = null; + } +}