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;
|
package com.wireguard.android;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
@ -20,7 +21,9 @@ public class ProfileDetailActivity extends ProfileActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMenuEdit(MenuItem item) {
|
public void onMenuEdit(MenuItem item) {
|
||||||
|
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
||||||
|
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
||||||
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,13 +34,22 @@ public class ProfileListActivity extends ProfileActivity {
|
|||||||
transaction.remove(detailFragment);
|
transaction.remove(detailFragment);
|
||||||
}
|
}
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
onProfileSelected(getCurrentProfile());
|
if (isEditing())
|
||||||
|
onMenuEdit(null);
|
||||||
|
else
|
||||||
|
onProfileSelected(getCurrentProfile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMenuEdit(MenuItem item) {
|
public void onMenuEdit(MenuItem item) {
|
||||||
setIsEditing(true);
|
setIsEditing(true);
|
||||||
|
if (isSplitLayout) {
|
||||||
|
updateLayout(getCurrentProfile());
|
||||||
|
} else {
|
||||||
|
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
||||||
|
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,10 +73,26 @@ public class ProfileListActivity extends ProfileActivity {
|
|||||||
|
|
||||||
public void updateLayout(String profile) {
|
public void updateLayout(String profile) {
|
||||||
final Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container);
|
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) {
|
if (fragment instanceof ProfileDetailFragment) {
|
||||||
final ProfileDetailFragment detailFragment = (ProfileDetailFragment) fragment;
|
final ProfileDetailFragment detailFragment = (ProfileDetailFragment) fragment;
|
||||||
detailFragment.setProfile(profile);
|
if (!profile.equals(detailFragment.getProfile()))
|
||||||
|
detailFragment.setProfile(profile);
|
||||||
} else {
|
} else {
|
||||||
final ProfileDetailFragment detailFragment = new ProfileDetailFragment();
|
final ProfileDetailFragment detailFragment = new ProfileDetailFragment();
|
||||||
detailFragment.setProfile(profile);
|
detailFragment.setProfile(profile);
|
||||||
|
Loading…
Reference in New Issue
Block a user