diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-10 01:05:20 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-10 01:05:20 -0500 |
commit | de53a1b50a27b4a05937a613dd3f8cf492910a65 (patch) | |
tree | e031515683a5a20a980c98b8bd6dd856426ad377 /app/src/main/java | |
parent | 87d3200b29d43ec5ee93de18d016c483cb3cb239 (diff) |
ProfileEdit: Finish writing code-behind
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/ProfileEditActivity.java | 10 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/ProfileEditFragment.java | 51 |
2 files changed, 61 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileEditActivity.java b/app/src/main/java/com/wireguard/android/ProfileEditActivity.java index 92d68904..34620279 100644 --- a/app/src/main/java/com/wireguard/android/ProfileEditActivity.java +++ b/app/src/main/java/com/wireguard/android/ProfileEditActivity.java @@ -1,6 +1,8 @@ package com.wireguard.android; +import android.app.Fragment; import android.content.Intent; +import android.os.Bundle; import android.view.MenuItem; /** @@ -9,6 +11,14 @@ import android.view.MenuItem; public class ProfileEditActivity extends ProfileActivity { @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.profile_edit_activity); + Fragment editFragment = getFragmentManager().findFragmentByTag(TAG_EDIT); + ((ProfileEditFragment) editFragment).setProfile(getCurrentProfile()); + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_action_edit: diff --git a/app/src/main/java/com/wireguard/android/ProfileEditFragment.java b/app/src/main/java/com/wireguard/android/ProfileEditFragment.java index b2a7168b..2249a8a7 100644 --- a/app/src/main/java/com/wireguard/android/ProfileEditFragment.java +++ b/app/src/main/java/com/wireguard/android/ProfileEditFragment.java @@ -1,8 +1,59 @@ package com.wireguard.android; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; + +import com.wireguard.android.databinding.ProfileEditFragmentBinding; +import com.wireguard.config.Profile; + /** * Fragment for editing a WireGuard profile. */ public class ProfileEditFragment extends ProfileFragment { + private ProfileEditFragmentBinding binding; + private Profile copy; + + @Override + protected void onCachedProfileChanged(Profile cachedProfile) { + copy = cachedProfile != null ? cachedProfile.copy() : null; + if (binding != null) + binding.setProfile(copy); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.profile_edit, menu); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { + binding = ProfileEditFragmentBinding.inflate(inflater, parent, false); + binding.setProfile(copy); + return binding.getRoot(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_action_save: + final ProfileServiceInterface service = getService(); + if (service != null) + service.saveProfile(getProfile(), copy); + return true; + default: + return false; + } + } } |