Fix Display Key in UploadKeyActivity, Issue #506
This commit is contained in:
@@ -28,6 +28,7 @@ import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
public class CertifyKeyActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_RESULT = "operation_result";
|
||||
// For sending masterKeyIds to MultiUserIdsFragment to display list of keys
|
||||
public static final String EXTRA_KEY_IDS = MultiUserIdsFragment.EXTRA_KEY_IDS ;
|
||||
public static final String EXTRA_CERTIFY_KEY_ID = "certify_key_id";
|
||||
|
||||
|
||||
@@ -74,13 +74,14 @@ public class CertifyKeyFragment
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
if (savedInstanceState == null){
|
||||
if (savedInstanceState == null) {
|
||||
// preselect certify key id if given
|
||||
long certifyKeyId = getActivity().getIntent()
|
||||
.getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none);
|
||||
if (certifyKeyId != Constants.key.none) {
|
||||
try {
|
||||
CachedPublicKeyRing key = (new ProviderHelper(getActivity())).getCachedPublicKeyRing(certifyKeyId);
|
||||
CachedPublicKeyRing key = (new ProviderHelper(getActivity()))
|
||||
.getCachedPublicKeyRing(certifyKeyId);
|
||||
if (key.canCertify()) {
|
||||
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);
|
||||
}
|
||||
@@ -88,7 +89,6 @@ public class CertifyKeyFragment
|
||||
Log.e(Constants.TAG, "certify certify check failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OperationResult result = getActivity().getIntent().getParcelableExtra(CertifyKeyActivity.EXTRA_RESULT);
|
||||
|
||||
@@ -26,12 +26,10 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by durgeshchoudhary on 07/03/16.
|
||||
*/
|
||||
public class MultiUserIdsFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>{
|
||||
public static final String ARG_CHECK_STATES = "check_states";
|
||||
public static final String EXTRA_KEY_IDS = "extra_key_ids";
|
||||
private boolean checkboxVisibility = true;
|
||||
|
||||
ListView mUserIds;
|
||||
private MultiUserIdsAdapter mUserIdsAdapter;
|
||||
@@ -78,7 +76,7 @@ public class MultiUserIdsFragment extends Fragment implements LoaderManager.Load
|
||||
checkedStates = (ArrayList<Boolean>) savedInstanceState.getSerializable(ARG_CHECK_STATES);
|
||||
}
|
||||
|
||||
mUserIdsAdapter = new MultiUserIdsAdapter(getActivity(), null, 0, checkedStates);
|
||||
mUserIdsAdapter = new MultiUserIdsAdapter(getActivity(), null, 0, checkedStates, checkboxVisibility);
|
||||
mUserIds.setAdapter(mUserIdsAdapter);
|
||||
mUserIds.setDividerHeight(0);
|
||||
|
||||
@@ -95,6 +93,10 @@ public class MultiUserIdsFragment extends Fragment implements LoaderManager.Load
|
||||
}
|
||||
|
||||
public ArrayList<CertifyActionsParcel.CertifyAction> getSelectedCertifyActions() {
|
||||
if (!checkboxVisibility) {
|
||||
throw new AssertionError("Item selection not allowed");
|
||||
}
|
||||
|
||||
return mUserIdsAdapter.getSelectedCertifyActions();
|
||||
}
|
||||
|
||||
@@ -214,4 +216,8 @@ public class MultiUserIdsFragment extends Fragment implements LoaderManager.Load
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
mUserIdsAdapter.swapCursor(null);
|
||||
}
|
||||
|
||||
public void setCheckboxVisibility(boolean checkboxVisibility) {
|
||||
this.checkboxVisibility = checkboxVisibility;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,7 @@ import android.widget.Spinner;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
@@ -53,7 +50,6 @@ public class UploadKeyActivity extends BaseActivity
|
||||
|
||||
// CryptoOperationHelper.Callback vars
|
||||
private String mKeyserver;
|
||||
private long mMasterKeyId;
|
||||
private CryptoOperationHelper<UploadKeyringParcel, UploadResult> mUploadOpHelper;
|
||||
|
||||
@Override
|
||||
@@ -63,6 +59,10 @@ public class UploadKeyActivity extends BaseActivity
|
||||
mUploadButton = findViewById(R.id.upload_key_action_upload);
|
||||
mKeyServerSpinner = (Spinner) findViewById(R.id.upload_key_keyserver);
|
||||
|
||||
MultiUserIdsFragment mMultiUserIdsFragment = (MultiUserIdsFragment)
|
||||
getSupportFragmentManager().findFragmentById(R.id.multi_user_ids_fragment);
|
||||
mMultiUserIdsFragment.setCheckboxVisibility(false);
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, Preferences.getPreferences(this)
|
||||
.getKeyServers()
|
||||
@@ -89,15 +89,6 @@ public class UploadKeyActivity extends BaseActivity
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mMasterKeyId = new ProviderHelper(this).getCachedPublicKeyRing(
|
||||
KeyRings.buildUnifiedKeyRingUri(mDataUri)).getMasterKeyId();
|
||||
} catch (PgpKeyNotFoundException e) {
|
||||
Log.e(Constants.TAG, "Intent data pointed to bad key!");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +127,9 @@ public class UploadKeyActivity extends BaseActivity
|
||||
|
||||
@Override
|
||||
public UploadKeyringParcel createOperationInput() {
|
||||
return new UploadKeyringParcel(mKeyserver, mMasterKeyId);
|
||||
long[] masterKeyIds = getIntent().getLongArrayExtra(MultiUserIdsFragment.EXTRA_KEY_IDS);
|
||||
|
||||
return new UploadKeyringParcel(mKeyserver, masterKeyIds[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -455,8 +455,19 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
||||
}
|
||||
|
||||
private void uploadToKeyserver() {
|
||||
long keyId;
|
||||
try {
|
||||
keyId = new ProviderHelper(getActivity())
|
||||
.getCachedPublicKeyRing(mDataUri)
|
||||
.extractOrGetMasterKeyId();
|
||||
} catch (PgpKeyNotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
Notify.create(getActivity(), "key not found", Style.ERROR).show();
|
||||
return;
|
||||
}
|
||||
Intent uploadIntent = new Intent(getActivity(), UploadKeyActivity.class);
|
||||
uploadIntent.setData(mDataUri);
|
||||
uploadIntent.putExtra(MultiUserIdsFragment.EXTRA_KEY_IDS, new long[]{keyId});
|
||||
startActivityForResult(uploadIntent, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.ArrayList;
|
||||
public class MultiUserIdsAdapter extends CursorAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
private final ArrayList<Boolean> mCheckStates;
|
||||
private boolean checkboxVisibility = true;
|
||||
|
||||
public MultiUserIdsAdapter(Context context, Cursor c, int flags, ArrayList<Boolean> preselectStates) {
|
||||
super(context, c, flags);
|
||||
@@ -46,6 +47,11 @@ public class MultiUserIdsAdapter extends CursorAdapter {
|
||||
mCheckStates = preselectStates == null ? new ArrayList<Boolean>() : preselectStates;
|
||||
}
|
||||
|
||||
public MultiUserIdsAdapter(Context context, Cursor c, int flags, ArrayList<Boolean> preselectStates, boolean checkboxVisibility) {
|
||||
this(context,c,flags,preselectStates);
|
||||
this.checkboxVisibility = checkboxVisibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor swapCursor(Cursor newCursor) {
|
||||
if (newCursor != null) {
|
||||
@@ -138,6 +144,7 @@ public class MultiUserIdsAdapter extends CursorAdapter {
|
||||
}
|
||||
});
|
||||
vCheckBox.setClickable(false);
|
||||
vCheckBox.setVisibility(checkboxVisibility?View.VISIBLE:View.GONE);
|
||||
|
||||
View vUidBody = view.findViewById(R.id.user_id_body);
|
||||
vUidBody.setClickable(true);
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:clickable="true"
|
||||
android:layout_marginLeft="8dip"
|
||||
android:layout_marginTop="8dip"/>
|
||||
|
||||
<LinearLayout android:id="@+id/user_id_body"
|
||||
@@ -21,7 +20,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:singleLine="true"
|
||||
android:layout_marginLeft="8dip"
|
||||
android:layout_marginTop="4dip">
|
||||
|
||||
<CheckBox
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginTop="4dp" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/multi_user_ids_fragment"
|
||||
android:name="org.sufficientlysecure.keychain.ui.MultiUserIdsFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/SectionHeader"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user