save
This commit is contained in:
@@ -38,9 +38,11 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
|||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.Editor;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
|
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.SectionView;
|
import org.sufficientlysecure.keychain.ui.widget.SectionView;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
|
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
@@ -67,7 +69,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
|
|
||||||
public class EditKeyActivity extends ActionBarActivity {
|
public class EditKeyActivity extends ActionBarActivity implements EditorListener {
|
||||||
|
|
||||||
// Actions for internal use only:
|
// Actions for internal use only:
|
||||||
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
|
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
|
||||||
@@ -106,6 +108,15 @@ public class EditKeyActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
ExportHelper mExportHelper;
|
ExportHelper mExportHelper;
|
||||||
|
|
||||||
|
public void onDeleted(Editor e, boolean wasNewItem)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEdited()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|||||||
@@ -91,10 +91,15 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDeleted(Editor editor) {
|
public void onDeleted(Editor editor, boolean wasNewItem) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEdited() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
KeyServerEditor view = (KeyServerEditor) mInflater.inflate(R.layout.key_server_editor,
|
KeyServerEditor view = (KeyServerEditor) mInflater.inflate(R.layout.key_server_editor,
|
||||||
mEditors, false);
|
mEditors, false);
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ package org.sufficientlysecure.keychain.ui.widget;
|
|||||||
|
|
||||||
public interface Editor {
|
public interface Editor {
|
||||||
public interface EditorListener {
|
public interface EditorListener {
|
||||||
public void onDeleted(Editor editor);
|
public void onDeleted(Editor editor, boolean wasNewItem);
|
||||||
|
public void onEdited();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEditorListener(EditorListener listener);
|
public void setEditorListener(EditorListener listener);
|
||||||
|
public boolean needsSaving();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import java.util.Vector;
|
|||||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.spongycastle.openpgp.PGPPublicKey;
|
import org.spongycastle.openpgp.PGPPublicKey;
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Choice;
|
import org.sufficientlysecure.keychain.util.Choice;
|
||||||
@@ -39,11 +38,9 @@ import android.util.AttributeSet;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TableLayout;
|
import android.widget.TableLayout;
|
||||||
import android.widget.TableRow;
|
import android.widget.TableRow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -62,11 +59,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
TextView mCreationDate;
|
TextView mCreationDate;
|
||||||
BootstrapButton mExpiryDateButton;
|
BootstrapButton mExpiryDateButton;
|
||||||
GregorianCalendar mExpiryDate;
|
GregorianCalendar mExpiryDate;
|
||||||
|
GregorianCalendar mOriginalExpiryDate = null;
|
||||||
CheckBox mChkCertify;
|
CheckBox mChkCertify;
|
||||||
CheckBox mChkSign;
|
CheckBox mChkSign;
|
||||||
CheckBox mChkEncrypt;
|
CheckBox mChkEncrypt;
|
||||||
CheckBox mChkAuthenticate;
|
CheckBox mChkAuthenticate;
|
||||||
int mUsage;
|
int mUsage;
|
||||||
|
int mOriginalUsage;
|
||||||
|
boolean mIsNewKey;
|
||||||
|
|
||||||
private int mDatePickerResultCount = 0;
|
private int mDatePickerResultCount = 0;
|
||||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||||
@@ -190,10 +190,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
||||||
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
||||||
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
||||||
|
mIsNewKey = isNewKey;
|
||||||
if (isNewKey)
|
if (isNewKey)
|
||||||
mUsage = usage;
|
mUsage = usage;
|
||||||
else
|
else {
|
||||||
mUsage = PgpKeyHelper.getKeyUsage(key);
|
mUsage = PgpKeyHelper.getKeyUsage(key);
|
||||||
|
mOriginalUsage = mUsage;
|
||||||
|
}
|
||||||
|
|
||||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||||
cal.setTime(PgpKeyHelper.getCreationDate(key));
|
cal.setTime(PgpKeyHelper.getCreationDate(key));
|
||||||
@@ -205,6 +208,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
} else {
|
} else {
|
||||||
cal.setTime(PgpKeyHelper.getExpiryDate(key));
|
cal.setTime(PgpKeyHelper.getExpiryDate(key));
|
||||||
setExpiryDate(cal);
|
setExpiryDate(cal);
|
||||||
|
mOriginalExpiryDate = cal; // TODO: ensure time doesn't matter when selecting the same date as before
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -218,7 +222,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
if (v == mDeleteButton) {
|
if (v == mDeleteButton) {
|
||||||
parent.removeView(this);
|
parent.removeView(this);
|
||||||
if (mEditorListener != null) {
|
if (mEditorListener != null) {
|
||||||
mEditorListener.onDeleted(this);
|
mEditorListener.onDeleted(this, mIsNewKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,4 +254,27 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
return mUsage;
|
return mUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean needsSaving()
|
||||||
|
{
|
||||||
|
if (mIsNewKey)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
boolean retval = (getUsage() != mOriginalUsage);
|
||||||
|
|
||||||
|
boolean dateChanged;
|
||||||
|
boolean mOEDNull = (mOriginalExpiryDate == null);
|
||||||
|
boolean mEDNull = (mExpiryDate == null);
|
||||||
|
if (mOEDNull != mEDNull) {
|
||||||
|
dateChanged = true;
|
||||||
|
} else {
|
||||||
|
if(mOEDNull) //both null, no change
|
||||||
|
dateChanged = false;
|
||||||
|
else
|
||||||
|
dateChanged = ((mExpiryDate.compareTo(mOriginalExpiryDate)) != 0);
|
||||||
|
}
|
||||||
|
retval |= dateChanged;
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class KeyServerEditor extends LinearLayout implements Editor, OnClickList
|
|||||||
if (v == mDeleteButton) {
|
if (v == mDeleteButton) {
|
||||||
parent.removeView(this);
|
parent.removeView(this);
|
||||||
if (mEditorListener != null) {
|
if (mEditorListener != null) {
|
||||||
mEditorListener.onDeleted(this);
|
mEditorListener.onDeleted(this, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,21 +50,27 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
|
|
||||||
public class SectionView extends LinearLayout implements OnClickListener, EditorListener {
|
public class SectionView extends LinearLayout implements OnClickListener, EditorListener, Editor {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private BootstrapButton mPlusButton;
|
private BootstrapButton mPlusButton;
|
||||||
private ViewGroup mEditors;
|
private ViewGroup mEditors;
|
||||||
private TextView mTitle;
|
private TextView mTitle;
|
||||||
private int mType = 0;
|
private int mType = 0;
|
||||||
|
private EditorListener mEditorListener = null;
|
||||||
|
|
||||||
private Choice mNewKeyAlgorithmChoice;
|
private Choice mNewKeyAlgorithmChoice;
|
||||||
private int mNewKeySize;
|
private int mNewKeySize;
|
||||||
private boolean canEdit = true;
|
private boolean canEdit = true;
|
||||||
|
private boolean oldItemDeleted = false;
|
||||||
|
|
||||||
private ActionBarActivity mActivity;
|
private ActionBarActivity mActivity;
|
||||||
|
|
||||||
private ProgressDialogFragment mGeneratingDialog;
|
private ProgressDialogFragment mGeneratingDialog;
|
||||||
|
|
||||||
|
public void setEditorListener(EditorListener listener) {
|
||||||
|
mEditorListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
public SectionView(Context context) {
|
public SectionView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mActivity = (ActionBarActivity) context;
|
mActivity = (ActionBarActivity) context;
|
||||||
@@ -124,15 +130,34 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void onDeleted(Editor editor) {
|
public void onDeleted(Editor editor, boolean wasNewItem) {
|
||||||
|
oldItemDeleted |= !wasNewItem;
|
||||||
this.updateEditorsVisible();
|
this.updateEditorsVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEdited() {
|
||||||
|
if (mEditorListener != null) {
|
||||||
|
mEditorListener.onEdited();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateEditorsVisible() {
|
protected void updateEditorsVisible() {
|
||||||
final boolean hasChildren = mEditors.getChildCount() > 0;
|
final boolean hasChildren = mEditors.getChildCount() > 0;
|
||||||
mEditors.setVisibility(hasChildren ? View.VISIBLE : View.GONE);
|
mEditors.setVisibility(hasChildren ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean needsSaving()
|
||||||
|
{
|
||||||
|
//check each view for needs saving, take account of deleted items
|
||||||
|
boolean ret = oldItemDeleted;
|
||||||
|
for (int i = 0; i < mEditors.getChildCount(); ++i) {
|
||||||
|
Editor editor = (Editor) mEditors.getChildAt(i);
|
||||||
|
ret |= editor.needsSaving();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (canEdit) {
|
if (canEdit) {
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
|||||||
boolean wasMainUserId = mIsMainUserId.isChecked();
|
boolean wasMainUserId = mIsMainUserId.isChecked();
|
||||||
parent.removeView(this);
|
parent.removeView(this);
|
||||||
if (mEditorListener != null) {
|
if (mEditorListener != null) {
|
||||||
mEditorListener.onDeleted(this);
|
mEditorListener.onDeleted(this, false);
|
||||||
}
|
}
|
||||||
if (wasMainUserId && parent.getChildCount() > 0) {
|
if (wasMainUserId && parent.getChildCount() > 0) {
|
||||||
UserIdEditor editor = (UserIdEditor) parent.getChildAt(0);
|
UserIdEditor editor = (UserIdEditor) parent.getChildAt(0);
|
||||||
@@ -204,4 +204,9 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
|||||||
public void setEditorListener(EditorListener listener) {
|
public void setEditorListener(EditorListener listener) {
|
||||||
mEditorListener = listener;
|
mEditorListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean needsSaving() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user