diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index b3df52726..89af2d683 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -55,6 +55,7 @@ import android.os.Handler; import android.os.Message; import android.os.Messenger; import android.support.v7.app.ActionBarActivity; +import android.support.v4.app.ActivityCompat; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -97,6 +98,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener private String mSavedNewPassPhrase = null; private boolean mIsPassPhraseSet; private boolean mNeedsSaving; + private MenuItem mSaveButton; private BootstrapButton mChangePassPhrase; @@ -109,12 +111,19 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener ExportHelper mExportHelper; - public void somethingChanged() + public boolean needsSaving() { mNeedsSaving = mUserIdsView.needsSaving(); mNeedsSaving |= mKeysView.needsSaving(); mNeedsSaving |= hasPassphraseChanged(); - Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show(); + return mNeedsSaving; + } + + + public void somethingChanged() + { + ActivityCompat.invalidateOptionsMenu(this); + //Toast.makeText(this, "Needs saving: " + Boolean.toString(mNeedsSaving) + "(" + Boolean.toString(mUserIdsView.needsSaving()) + ", " + Boolean.toString(mKeysView.needsSaving()) + ")", Toast.LENGTH_LONG).show(); } public void onDeleted(Editor e, boolean wasNewItem) @@ -133,6 +142,10 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mExportHelper = new ExportHelper(this); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setIcon(android.R.color.transparent); + getSupportActionBar().setHomeButtonEnabled(true); + mUserIds = new Vector(); mKeys = new Vector(); mKeysUsages = new Vector(); @@ -153,20 +166,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener * @param intent */ private void handleActionCreateKey(Intent intent) { - // Inflate a "Done"/"Cancel" custom action bar - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save, - new View.OnClickListener() { - @Override - public void onClick(View v) { - saveClicked(); - } - }, R.string.btn_do_not_save, new View.OnClickListener() { - @Override - public void onClick(View v) { - cancelClicked(); - } - }); - Bundle extras = intent.getExtras(); mCurrentPassPhrase = ""; @@ -255,15 +254,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener * @param intent */ private void handleActionEditKey(Intent intent) { - // Inflate a "Done"/"Cancel" custom action bar - ActionBarHelper.setDoneView(getSupportActionBar(), R.string.btn_save, - new View.OnClickListener() { - @Override - public void onClick(View v) { - saveClicked(); - } - }); - mDataUri = intent.getData(); if (mDataUri == null) { Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); @@ -325,12 +315,17 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.key_edit, menu); + mSaveButton = (MenuItem) menu.findItem(R.id.menu_key_edit_save); + mSaveButton.setEnabled(needsSaving()); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case android.R.id.home: + cancelClicked(); + return true; case R.id.menu_key_edit_cancel: cancelClicked(); return true; @@ -353,6 +348,9 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener mExportHelper.deleteKey(mDataUri, Id.type.secret_key, returnHandler); return true; } + case R.id.menu_key_edit_save: + saveClicked(); + return true; } return super.onOptionsItemSelected(item); } @@ -373,8 +371,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show(); } if (masterKey != null) { + boolean isSet = false; for (String userId : new IterableIterator(masterKey.getUserIDs())) { Log.d(Constants.TAG, "Added userId " + userId); + if (!isSet) { + isSet = true; + String[] parts = PgpKeyHelper.splitUserId(userId); + if (parts[0] != null) + setTitle(parts[0]); + } mUserIds.add(userId); } } @@ -465,7 +470,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener } }); - // disable passphrase when no passphrase checkobox is checked! + // disable passphrase when no passphrase checkbox is checked! mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 072c04f03..21ebff102 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -133,6 +133,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor public void onDeleted(Editor editor, boolean wasNewItem) { oldItemDeleted |= !wasNewItem; this.updateEditorsVisible(); + if (mEditorListener != null) { + mEditorListener.onEdited(); + } } @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index e3747aeb9..b499a429a 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -137,12 +137,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene mOriginalName = result[0]; } if (result[1] != null) { - mComment.setText(result[1]); - mOriginalComment = result[1]; + mEmail.setText(result[1]); + mOriginalEmail = result[1]; } if (result[2] != null) { - mEmail.setText(result[2]); - mOriginalEmail = result[2]; + mComment.setText(result[2]); + mOriginalComment = result[2]; } mOriginallyMainUserID = isMainID; diff --git a/OpenPGP-Keychain/src/main/res/menu/key_edit.xml b/OpenPGP-Keychain/src/main/res/menu/key_edit.xml index 16992affb..ede1d03c0 100644 --- a/OpenPGP-Keychain/src/main/res/menu/key_edit.xml +++ b/OpenPGP-Keychain/src/main/res/menu/key_edit.xml @@ -2,6 +2,12 @@ + +