ProfileEdit: Finish writing code-behind
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
87d3200b29
commit
de53a1b50a
@ -1,6 +1,8 @@
|
||||
package com.wireguard.android;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
@ -8,6 +10,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()) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
app/src/main/res/layout/profile_edit_activity.xml
Normal file
6
app/src/main/res/layout/profile_edit_activity.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="com.wireguard.android.ProfileEditFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:tag="edit" />
|
38
app/src/main/res/layout/profile_edit_fragment.xml
Normal file
38
app/src/main/res/layout/profile_edit_fragment.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="profile"
|
||||
type="com.wireguard.config.Profile" />
|
||||
</data>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/profile_name_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:labelFor="@+id/profile_name_text"
|
||||
android:text="@string/profile_name" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/profile_name_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/profile_name_label"
|
||||
android:inputType="textCapWords"
|
||||
android:text="@={profile.name}" />
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
</layout>
|
Loading…
Reference in New Issue
Block a user