mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-26 00:48:51 -05:00
Automatically select newly created key in api accounts
This commit is contained in:
parent
ddfb7e10e8
commit
ecca54d4d5
@ -17,7 +17,9 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -31,6 +33,7 @@ import android.widget.TextView;
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.remote.AccountSettings;
|
||||
import org.sufficientlysecure.keychain.ui.EditKeyActivity;
|
||||
import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment;
|
||||
@ -40,6 +43,8 @@ import org.sufficientlysecure.keychain.util.AlgorithmNames;
|
||||
public class AccountSettingsFragment extends Fragment implements
|
||||
SelectSecretKeyLayoutFragment.SelectSecretKeyCallback {
|
||||
|
||||
private static final int REQUEST_CODE_CREATE_KEY = 0x00008884;
|
||||
|
||||
// model
|
||||
private AccountSettings mAccSettings;
|
||||
|
||||
@ -64,7 +69,8 @@ public class AccountSettingsFragment extends Fragment implements
|
||||
this.mAccSettings = accountSettings;
|
||||
|
||||
mAccNameView.setText(accountSettings.getAccountName());
|
||||
mSelectKeyFragment.selectKey(accountSettings.getKeyId());
|
||||
Uri keyUri = KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(String.valueOf(accountSettings.getKeyId()));
|
||||
mSelectKeyFragment.selectKey(keyUri);
|
||||
mEncryptionAlgorithm.setSelection(mEncryptionAdapter.getPosition(accountSettings
|
||||
.getEncryptionAlgorithm()));
|
||||
mHashAlgorithm.setSelection(mHashAdapter.getPosition(accountSettings.getHashAlgorithm()));
|
||||
@ -162,7 +168,26 @@ public class AccountSettingsFragment extends Fragment implements
|
||||
intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true);
|
||||
// set default user id to account name TODO: not working currently in EditKey
|
||||
intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, mAccSettings.getAccountName());
|
||||
startActivityForResult(intent, 0);
|
||||
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_CREATE_KEY: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
// select newly created key
|
||||
Uri newKeyUri = data.getData();
|
||||
mSelectKeyFragment.selectKey(newKeyUri);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.pgp.*;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
||||
|
@ -621,7 +621,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
|
||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||
Intent data = new Intent();
|
||||
|
||||
// TODO: remove, now using uri!
|
||||
data.putExtra(RESULT_EXTRA_MASTER_KEY_ID, getMasterKeyId());
|
||||
|
||||
// return uri pointing to new created key
|
||||
Uri uri = KeychainContract.KeyRings.buildPublicKeyRingsByKeyIdUri(
|
||||
String.valueOf(getMasterKeyId()));
|
||||
data.setData(uri);
|
||||
|
||||
ArrayList<String> userIds = null;
|
||||
try {
|
||||
userIds = getUserIds(mUserIdsView);
|
||||
|
@ -40,6 +40,8 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
|
||||
public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
private static final int REQUEST_CODE_SELECT_KEY = 0x00008882;
|
||||
|
||||
private TextView mKeyUserId;
|
||||
private TextView mKeyUserIdRest;
|
||||
private TextView mKeyMasterKeyIdHex;
|
||||
@ -51,14 +53,10 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
||||
|
||||
private SelectSecretKeyCallback mCallback;
|
||||
|
||||
private static final int REQUEST_CODE_SELECT_KEY = 8882;
|
||||
|
||||
private static final int LOADER_ID = 0;
|
||||
|
||||
//The Projection we will retrieve, Master Key ID is for convenience sake,
|
||||
//to avoid having to pass the Key Around
|
||||
final String[] PROJECTION = new String[]{KeychainContract.UserIds.USER_ID
|
||||
, KeychainContract.KeyRings.MASTER_KEY_ID};
|
||||
final String[] PROJECTION = new String[]{
|
||||
KeychainContract.UserIds.USER_ID,
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID
|
||||
};
|
||||
final int INDEX_USER_ID = 0;
|
||||
final int INDEX_MASTER_KEY_ID = 1;
|
||||
|
||||
@ -82,7 +80,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
||||
}
|
||||
|
||||
public void setSelectedKeyData(String userName, String email, String masterKeyHex) {
|
||||
|
||||
mNoKeySelected.setVisibility(View.GONE);
|
||||
|
||||
mKeyUserId.setText(userName);
|
||||
@ -124,11 +121,9 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
||||
return view;
|
||||
}
|
||||
|
||||
//For AppSettingsFragment
|
||||
public void selectKey(long masterKeyId) {
|
||||
Uri buildUri = KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(String.valueOf(masterKeyId));
|
||||
mReceivedUri = buildUri;
|
||||
getActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, this);
|
||||
public void selectKey(Uri keyUri) {
|
||||
mReceivedUri = keyUri;
|
||||
getActivity().getSupportLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
|
||||
private void startSelectKeyActivity() {
|
||||
@ -188,13 +183,13 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
|
||||
// Secret Key Fragment.Intent contains the passed Uri
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode & 0xFFFF) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_SELECT_KEY: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
mReceivedUri = data.getData();
|
||||
|
||||
//Must be restartLoader() or the data will not be updated on selecting a new key
|
||||
getActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, this);
|
||||
getActivity().getSupportLoaderManager().restartLoader(0, null, this);
|
||||
|
||||
mKeyUserId.setError(null);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user