Merge pull request #760 from mar-v-in/fix-encrypt-intent

Fix encrypt intent
This commit is contained in:
Dominik Schürmann 2014-08-13 13:20:21 +02:00
commit e4c8674792
3 changed files with 20 additions and 49 deletions

View File

@ -81,10 +81,6 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
PagerTabStripAdapter mTabsAdapterContent; PagerTabStripAdapter mTabsAdapterContent;
// tabs // tabs
Bundle mAsymmetricFragmentBundle = new Bundle();
Bundle mSymmetricFragmentBundle = new Bundle();
Bundle mMessageFragmentBundle = new Bundle();
Bundle mFileFragmentBundle = new Bundle();
int mSwitchToMode = PAGER_MODE_ASYMMETRIC; int mSwitchToMode = PAGER_MODE_ASYMMETRIC;
int mSwitchToContent = PAGER_CONTENT_MESSAGE; int mSwitchToContent = PAGER_CONTENT_MESSAGE;
@ -93,7 +89,7 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
private static final int PAGER_CONTENT_MESSAGE = 0; private static final int PAGER_CONTENT_MESSAGE = 0;
private static final int PAGER_CONTENT_FILE = 1; private static final int PAGER_CONTENT_FILE = 1;
// model used by message and file fragments // model used by fragments
private long mEncryptionKeyIds[] = null; private long mEncryptionKeyIds[] = null;
private String mEncryptionUserIds[] = null; private String mEncryptionUserIds[] = null;
private long mSigningKeyId = Constants.key.none; private long mSigningKeyId = Constants.key.none;
@ -503,16 +499,12 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
// Handle intent actions // Handle intent actions
handleActions(getIntent()); handleActions(getIntent());
mTabsAdapterMode.addTab(EncryptAsymmetricFragment.class, mTabsAdapterMode.addTab(EncryptAsymmetricFragment.class, null, getString(R.string.label_asymmetric));
mAsymmetricFragmentBundle, getString(R.string.label_asymmetric)); mTabsAdapterMode.addTab(EncryptSymmetricFragment.class, null, getString(R.string.label_symmetric));
mTabsAdapterMode.addTab(EncryptSymmetricFragment.class,
mSymmetricFragmentBundle, getString(R.string.label_symmetric));
mViewPagerMode.setCurrentItem(mSwitchToMode); mViewPagerMode.setCurrentItem(mSwitchToMode);
mTabsAdapterContent.addTab(EncryptMessageFragment.class, mTabsAdapterContent.addTab(EncryptMessageFragment.class, null, getString(R.string.label_message));
mMessageFragmentBundle, getString(R.string.label_message)); mTabsAdapterContent.addTab(EncryptFileFragment.class, null, getString(R.string.label_files));
mTabsAdapterContent.addTab(EncryptFileFragment.class,
mFileFragmentBundle, getString(R.string.label_files));
mViewPagerContent.setCurrentItem(mSwitchToContent); mViewPagerContent.setCurrentItem(mSwitchToContent);
mUseArmor = Preferences.getPreferences(this).getDefaultAsciiArmor(); mUseArmor = Preferences.getPreferences(this).getDefaultAsciiArmor();
@ -604,14 +596,10 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
String textData = extras.getString(EXTRA_TEXT); String textData = extras.getString(EXTRA_TEXT);
long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID); mSigningKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
// preselect keys given by intent // preselect keys given by intent
mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS,
encryptionKeyIds);
mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID,
signatureKeyId);
mSwitchToMode = PAGER_MODE_ASYMMETRIC; mSwitchToMode = PAGER_MODE_ASYMMETRIC;
/** /**
@ -619,11 +607,11 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
*/ */
if (ACTION_ENCRYPT.equals(action) && textData != null) { if (ACTION_ENCRYPT.equals(action) && textData != null) {
// encrypt text based on given extra // encrypt text based on given extra
mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData); mMessage = textData;
mSwitchToContent = PAGER_CONTENT_MESSAGE; mSwitchToContent = PAGER_CONTENT_MESSAGE;
} else if (ACTION_ENCRYPT.equals(action) && uris != null && !uris.isEmpty()) { } else if (ACTION_ENCRYPT.equals(action) && uris != null && !uris.isEmpty()) {
// encrypt file based on Uri // encrypt file based on Uri
mFileFragmentBundle.putParcelableArrayList(EncryptFileFragment.ARG_URIS, uris); mInputUris = uris;
mSwitchToContent = PAGER_CONTENT_FILE; mSwitchToContent = PAGER_CONTENT_FILE;
} else if (ACTION_ENCRYPT.equals(action)) { } else if (ACTION_ENCRYPT.equals(action)) {
Log.e(Constants.TAG, Log.e(Constants.TAG,

View File

@ -123,14 +123,10 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
long signatureKeyId = getArguments().getLong(ARG_SIGNATURE_KEY_ID);
long[] encryptionKeyIds = getArguments().getLongArray(ARG_ENCRYPTION_KEY_IDS);
mProviderHelper = new ProviderHelper(getActivity()); mProviderHelper = new ProviderHelper(getActivity());
// preselect keys given by arguments (given by Intent to EncryptActivity) // preselect keys given
preselectKeys(signatureKeyId, encryptionKeyIds, mProviderHelper); preselectKeys();
getLoaderManager().initLoader(1, null, new LoaderManager.LoaderCallbacks<Cursor>() { getLoaderManager().initLoader(1, null, new LoaderManager.LoaderCallbacks<Cursor>() {
@Override @Override
@ -187,19 +183,15 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
/** /**
* If an Intent gives a signatureMasterKeyId and/or encryptionMasterKeyIds, preselect those! * If an Intent gives a signatureMasterKeyId and/or encryptionMasterKeyIds, preselect those!
*
* @param preselectedSignatureKeyId
* @param preselectedEncryptionKeyIds
*/ */
private void preselectKeys(long preselectedSignatureKeyId, long[] preselectedEncryptionKeyIds, private void preselectKeys() {
ProviderHelper providerHelper) {
// TODO all of this works under the assumption that the first suitable subkey is always used! // TODO all of this works under the assumption that the first suitable subkey is always used!
// not sure if we need to distinguish between different subkeys here? // not sure if we need to distinguish between different subkeys here?
if (preselectedSignatureKeyId != 0) { long signatureKey = mEncryptInterface.getSignatureKey();
if (signatureKey != Constants.key.none) {
try { try {
CachedPublicKeyRing keyring = CachedPublicKeyRing keyring = mProviderHelper.getCachedPublicKeyRing(
providerHelper.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingUri(signatureKey));
KeyRings.buildUnifiedKeyRingUri(preselectedSignatureKeyId));
if(keyring.hasAnySecret()) { if(keyring.hasAnySecret()) {
setSignatureKeyId(keyring.getMasterKeyId()); setSignatureKeyId(keyring.getMasterKeyId());
} }
@ -208,10 +200,11 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
} }
} }
if (preselectedEncryptionKeyIds != null) { long[] encryptionKeyIds = mEncryptInterface.getEncryptionKeys();
for (long preselectedId : preselectedEncryptionKeyIds) { if (encryptionKeyIds != null) {
for (long preselectedId : encryptionKeyIds) {
try { try {
CachedPublicKeyRing ring = providerHelper.getCachedPublicKeyRing( CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(preselectedId)); KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(preselectedId));
mEncryptKeyView.addObject(mEncryptKeyView.new EncryptionKey(ring)); mEncryptKeyView.addObject(mEncryptKeyView.new EncryptionKey(ring));
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {

View File

@ -111,8 +111,6 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
addInputUris(getArguments().<Uri>getParcelableArrayList(ARG_URIS));
} }
private void addInputUri() { private void addInputUri() {
@ -125,14 +123,6 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
} }
} }
private void addInputUris(List<Uri> uris) {
if (uris != null) {
for (Uri uri : uris) {
addInputUri(uri);
}
}
}
private void addInputUri(Uri inputUri) { private void addInputUri(Uri inputUri) {
if (inputUri == null) { if (inputUri == null) {
return; return;