Hook up editing to the layout and menus
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
c199827b58
commit
af8e013e33
@ -1,6 +1,7 @@
|
||||
package com.wireguard.android;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
@ -20,7 +21,9 @@ public class ProfileDetailActivity extends ProfileActivity {
|
||||
|
||||
@Override
|
||||
public void onMenuEdit(MenuItem item) {
|
||||
|
||||
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
||||
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,13 +34,22 @@ public class ProfileListActivity extends ProfileActivity {
|
||||
transaction.remove(detailFragment);
|
||||
}
|
||||
transaction.commit();
|
||||
onProfileSelected(getCurrentProfile());
|
||||
if (isEditing())
|
||||
onMenuEdit(null);
|
||||
else
|
||||
onProfileSelected(getCurrentProfile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuEdit(MenuItem item) {
|
||||
setIsEditing(true);
|
||||
|
||||
if (isSplitLayout) {
|
||||
updateLayout(getCurrentProfile());
|
||||
} else {
|
||||
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
||||
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,10 +73,26 @@ public class ProfileListActivity extends ProfileActivity {
|
||||
|
||||
public void updateLayout(String profile) {
|
||||
final Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container);
|
||||
if (profile != null) {
|
||||
if (isEditing() && profile == null)
|
||||
throw new IllegalStateException();
|
||||
if (isEditing()) {
|
||||
if (fragment instanceof ProfileEditFragment) {
|
||||
final ProfileEditFragment editFragment = (ProfileEditFragment) fragment;
|
||||
if (!profile.equals(editFragment.getProfile()))
|
||||
editFragment.setProfile(profile);
|
||||
} else {
|
||||
final ProfileEditFragment editFragment = new ProfileEditFragment();
|
||||
editFragment.setProfile(profile);
|
||||
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.addToBackStack(null);
|
||||
transaction.replace(R.id.fragment_container, editFragment, TAG_EDIT);
|
||||
transaction.commit();
|
||||
}
|
||||
} else if (profile != null) {
|
||||
if (fragment instanceof ProfileDetailFragment) {
|
||||
final ProfileDetailFragment detailFragment = (ProfileDetailFragment) fragment;
|
||||
detailFragment.setProfile(profile);
|
||||
if (!profile.equals(detailFragment.getProfile()))
|
||||
detailFragment.setProfile(profile);
|
||||
} else {
|
||||
final ProfileDetailFragment detailFragment = new ProfileDetailFragment();
|
||||
detailFragment.setProfile(profile);
|
||||
|
Loading…
Reference in New Issue
Block a user