diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
4 files changed, 82 insertions, 34 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java index e5d06ccbb..fd3d4ed00 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java @@ -80,7 +80,7 @@ public abstract class OperationResults { } }; - public void displayToast(final Activity activity) { + public void displayNotify(final Activity activity) { int resultType = getResult(); @@ -130,6 +130,7 @@ public abstract class OperationResults { } } + // TODO: externalize into Notify class? boolean button = getLog() != null && !getLog().isEmpty(); SuperCardToast toast = new SuperCardToast(activity, button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 3f330ee94..b6a95a517 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -17,6 +17,8 @@ package org.sufficientlysecure.keychain.ui; +import android.app.ProgressDialog; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -27,7 +29,6 @@ import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v7.app.ActionBarActivity; -import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -43,12 +44,17 @@ import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.service.KeychainIntentService; +import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; +import org.sufficientlysecure.keychain.service.OperationResults; +import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsArrayAdapter; import org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment; +import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; import org.sufficientlysecure.keychain.util.Log; @@ -260,8 +266,6 @@ public class EditKeyFragment extends LoaderFragment implements String newPassphrase = data .getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE); -// updatePassphraseButtonText(); -// somethingChanged(); mSaveKeyringParcel.newPassphrase = newPassphrase; } } @@ -270,14 +274,6 @@ public class EditKeyFragment extends LoaderFragment implements // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); - // set title based on isPassphraseSet() -// int title; -// if (isPassphraseSet()) { -// title = R.string.title_change_passphrase; -// } else { -// title = R.string.title_set_passphrase; -// } - SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance( messenger, R.string.title_change_passphrase); @@ -356,8 +352,73 @@ public class EditKeyFragment extends LoaderFragment implements } private void save() { - getActivity().finish(); - // TODO + String passphrase = PassphraseCacheService.getCachedPassphrase(getActivity(), + mSaveKeyringParcel.mMasterKeyId); + if (passphrase == null) { + PassphraseDialogFragment.show(getActivity(), mSaveKeyringParcel.mMasterKeyId, + new Handler() { + @Override + public void handleMessage(Message message) { + if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { + saveFinal(); + } + } + } + ); + + } + } -} + private void saveFinal() { + // Message is received after importing is done in KeychainIntentService + KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler( + getActivity(), + getString(R.string.progress_saving), + ProgressDialog.STYLE_HORIZONTAL) { + public void handleMessage(Message message) { + // handle messages by standard KeychainIntentServiceHandler first + super.handleMessage(message); + + if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { + // get returned data bundle + Bundle returnData = message.getData(); + if (returnData == null) { + return; + } + final OperationResults.SaveKeyringResult result = + returnData.getParcelable(KeychainIntentService.RESULT); + if (result == null) { + return; + } + + // if good -> finish, return result to showkey and display there! + // if bad -> display here! + +// result.displayNotify(ImportKeysActivity.this); + +// getActivity().finish(); + } + } + }; + + // Send all information needed to service to import key in other thread + Intent intent = new Intent(getActivity(), KeychainIntentService.class); + intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); + + // fill values for this action + Bundle data = new Bundle(); + data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, mSaveKeyringParcel); + intent.putExtra(KeychainIntentService.EXTRA_DATA, data); + + // Create a new Messenger for the communication back + Messenger messenger = new Messenger(saveHandler); + intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); + + // show progress dialog + saveHandler.showProgressDialog(getActivity()); + + // start service with intent + getActivity().startService(intent); + } +}
\ No newline at end of file diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 0d8c8233a..3ff3b56bf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -18,7 +18,6 @@ package org.sufficientlysecure.keychain.ui; import android.annotation.TargetApi; -import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.net.Uri; @@ -37,11 +36,6 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import com.github.johnpersano.supertoasts.SuperCardToast; -import com.github.johnpersano.supertoasts.SuperToast; -import com.github.johnpersano.supertoasts.util.OnClickWrapper; -import com.github.johnpersano.supertoasts.util.Style; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.OtherHelper; @@ -55,6 +49,7 @@ import org.sufficientlysecure.keychain.service.OperationResults.ImportResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Notify; import java.util.ArrayList; import java.util.Locale; @@ -382,11 +377,7 @@ public class ImportKeysActivity extends ActionBarActivity { private boolean isFingerprintValid(String fingerprint) { if (fingerprint == null || fingerprint.length() < 40) { - SuperCardToast toast = SuperCardToast.create(this, - getString(R.string.import_qr_code_too_short_fingerprint), - SuperToast.Duration.LONG); - toast.setBackground(SuperToast.Background.RED); - toast.show(); + Notify.showNotify(this, R.string.import_qr_code_too_short_fingerprint, Notify.Style.ERROR); return false; } else { return true; @@ -460,7 +451,7 @@ public class ImportKeysActivity extends ActionBarActivity { return; } - result.displayToast(ImportKeysActivity.this); + result.displayNotify(ImportKeysActivity.this); } } }; @@ -546,11 +537,7 @@ public class ImportKeysActivity extends ActionBarActivity { startService(intent); } else { - SuperCardToast toast = SuperCardToast.create(this, - getString(R.string.error_nothing_import), - SuperToast.Duration.LONG); - toast.setBackground(SuperToast.Background.RED); - toast.show(); + Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 8cc587b10..a9cd0976b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui; import android.annotation.TargetApi; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; @@ -358,7 +357,7 @@ public class ViewKeyActivity extends ActionBarActivity implements if (resultCode == Activity.RESULT_OK) { ImportResult result = data.getParcelableExtra(ImportKeysActivity.EXTRA_RESULT); if (result != null) { - result.displayToast(this); + result.displayNotify(this); } } break; |