mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-06 17:25:05 -05:00
save
This commit is contained in:
parent
6d40bc3c0c
commit
8d7cc67553
@ -38,9 +38,11 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||
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.SectionView;
|
||||
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.Log;
|
||||
|
||||
@ -67,7 +69,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
|
||||
public class EditKeyActivity extends ActionBarActivity {
|
||||
public class EditKeyActivity extends ActionBarActivity implements EditorListener {
|
||||
|
||||
// Actions for internal use only:
|
||||
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
|
||||
@ -106,6 +108,15 @@ public class EditKeyActivity extends ActionBarActivity {
|
||||
|
||||
ExportHelper mExportHelper;
|
||||
|
||||
public void onDeleted(Editor e, boolean wasNewItem)
|
||||
{
|
||||
}
|
||||
|
||||
public void onEdited()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle 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
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEdited() {
|
||||
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
KeyServerEditor view = (KeyServerEditor) mInflater.inflate(R.layout.key_server_editor,
|
||||
mEditors, false);
|
||||
|
@ -18,8 +18,10 @@ package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
public interface Editor {
|
||||
public interface EditorListener {
|
||||
public void onDeleted(Editor editor);
|
||||
public void onDeleted(Editor editor, boolean wasNewItem);
|
||||
public void onEdited();
|
||||
}
|
||||
|
||||
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.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.sufficientlysecure.keychain.Id;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.util.Choice;
|
||||
@ -39,11 +38,9 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
@ -62,11 +59,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
TextView mCreationDate;
|
||||
BootstrapButton mExpiryDateButton;
|
||||
GregorianCalendar mExpiryDate;
|
||||
GregorianCalendar mOriginalExpiryDate = null;
|
||||
CheckBox mChkCertify;
|
||||
CheckBox mChkSign;
|
||||
CheckBox mChkEncrypt;
|
||||
CheckBox mChkAuthenticate;
|
||||
int mUsage;
|
||||
int mOriginalUsage;
|
||||
boolean mIsNewKey;
|
||||
|
||||
private int mDatePickerResultCount = 0;
|
||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||
@ -190,10 +190,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
||||
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
||||
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
||||
mIsNewKey = isNewKey;
|
||||
if (isNewKey)
|
||||
mUsage = usage;
|
||||
else
|
||||
else {
|
||||
mUsage = PgpKeyHelper.getKeyUsage(key);
|
||||
mOriginalUsage = mUsage;
|
||||
}
|
||||
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
cal.setTime(PgpKeyHelper.getCreationDate(key));
|
||||
@ -205,6 +208,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
} else {
|
||||
cal.setTime(PgpKeyHelper.getExpiryDate(key));
|
||||
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) {
|
||||
parent.removeView(this);
|
||||
if (mEditorListener != null) {
|
||||
mEditorListener.onDeleted(this);
|
||||
mEditorListener.onDeleted(this, mIsNewKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -250,4 +254,27 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
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) {
|
||||
parent.removeView(this);
|
||||
if (mEditorListener != null) {
|
||||
mEditorListener.onDeleted(this);
|
||||
mEditorListener.onDeleted(this, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,21 +50,27 @@ import android.widget.TextView;
|
||||
|
||||
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 BootstrapButton mPlusButton;
|
||||
private ViewGroup mEditors;
|
||||
private TextView mTitle;
|
||||
private int mType = 0;
|
||||
private EditorListener mEditorListener = null;
|
||||
|
||||
private Choice mNewKeyAlgorithmChoice;
|
||||
private int mNewKeySize;
|
||||
private boolean canEdit = true;
|
||||
private boolean oldItemDeleted = false;
|
||||
|
||||
private ActionBarActivity mActivity;
|
||||
|
||||
private ProgressDialogFragment mGeneratingDialog;
|
||||
|
||||
public void setEditorListener(EditorListener listener) {
|
||||
mEditorListener = listener;
|
||||
}
|
||||
|
||||
public SectionView(Context context) {
|
||||
super(context);
|
||||
mActivity = (ActionBarActivity) context;
|
||||
@ -124,15 +130,34 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void onDeleted(Editor editor) {
|
||||
public void onDeleted(Editor editor, boolean wasNewItem) {
|
||||
oldItemDeleted |= !wasNewItem;
|
||||
this.updateEditorsVisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEdited() {
|
||||
if (mEditorListener != null) {
|
||||
mEditorListener.onEdited();
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateEditorsVisible() {
|
||||
final boolean hasChildren = mEditors.getChildCount() > 0;
|
||||
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} */
|
||||
public void onClick(View v) {
|
||||
if (canEdit) {
|
||||
|
@ -175,7 +175,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
||||
boolean wasMainUserId = mIsMainUserId.isChecked();
|
||||
parent.removeView(this);
|
||||
if (mEditorListener != null) {
|
||||
mEditorListener.onDeleted(this);
|
||||
mEditorListener.onDeleted(this, false);
|
||||
}
|
||||
if (wasMainUserId && parent.getChildCount() > 0) {
|
||||
UserIdEditor editor = (UserIdEditor) parent.getChildAt(0);
|
||||
@ -204,4 +204,9 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
||||
public void setEditorListener(EditorListener listener) {
|
||||
mEditorListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsSaving() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user