fix NPE in EncryptModeAsymmetricFragment

This commit is contained in:
Vincent Breitmoser
2018-07-02 13:44:26 +02:00
parent 6789aee8d1
commit 799eed1ca2

View File

@@ -28,6 +28,7 @@ import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -53,7 +54,7 @@ import timber.log.Timber;
public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
KeyRepository mKeyRepository;
KeyRepository keyRepository;
private KeySpinner mSignKeySpinner;
private ChipsInput mEncryptKeyView;
@@ -73,6 +74,13 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
return frag;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
keyRepository = KeyRepository.create(requireContext());
}
/**
* Inflate the layout for this fragment
*/
@@ -184,7 +192,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
*/
private void preselectKeys(Long signatureKeyId, long[] encryptionKeyIds) {
if (signatureKeyId != null) {
UnifiedKeyInfo unifiedKeyInfo = mKeyRepository.getUnifiedKeyInfo(signatureKeyId);
UnifiedKeyInfo unifiedKeyInfo = keyRepository.getUnifiedKeyInfo(signatureKeyId);
if (unifiedKeyInfo == null) {
String beautifyKeyId = KeyFormattingUtils.beautifyKeyId(signatureKeyId);
Notify.create(getActivity(), getString(R.string.error_preselect_sign_key, beautifyKeyId), Style.ERROR).show();
@@ -197,7 +205,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
for (long preselectedId : encryptionKeyIds) {
try {
CanonicalizedPublicKeyRing ring =
mKeyRepository.getCanonicalizedPublicKeyRing(preselectedId);
keyRepository.getCanonicalizedPublicKeyRing(preselectedId);
Chip infooo = new Chip(ring.getMasterKeyId(), ring.getPrimaryUserIdWithFallback(), "infooo");
mEncryptKeyView.addChip(infooo);
} catch (NotFoundException e) {