mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Add helper methods to shorten code
This commit is contained in:
parent
fd99c279e5
commit
6def0be158
@ -82,28 +82,28 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
setStatusImageAndTextColor(context, resultEncryptionIcon, resultEncryptionText, CryptoState.ENCRYPTED);
|
setEncryptionImageAndTextColor(CryptoState.ENCRYPTED);
|
||||||
resultEncryptionText.setText(R.string.openpgp_result_encrypted);
|
resultEncryptionText.setText(R.string.openpgp_result_encrypted);
|
||||||
} else {
|
} else {
|
||||||
setStatusImageAndTextColor(context, resultEncryptionIcon, resultEncryptionText, CryptoState.NOT_ENCRYPTED);
|
setEncryptionImageAndTextColor(CryptoState.NOT_ENCRYPTED);
|
||||||
resultEncryptionText.setText(R.string.openpgp_result_not_encrypted);
|
resultEncryptionText.setText(R.string.openpgp_result_not_encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signatureResult == null) {
|
if (signatureResult == null) {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText, CryptoState.NOT_SIGNED);
|
setSignatureImageAndTextColor(CryptoState.NOT_SIGNED);
|
||||||
resultSignatureText.setText(R.string.openpgp_result_no_signature);
|
resultSignatureText.setText(R.string.openpgp_result_no_signature);
|
||||||
resultSignatureLayout.setVisibility(View.GONE);
|
resultSignatureLayout.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
switch (signatureResult.getStatus()) {
|
switch (signatureResult.getStatus()) {
|
||||||
case OpenPgpSignatureResult.SIGNATURE_ERROR: {
|
case OpenPgpSignatureResult.SIGNATURE_ERROR: {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText, CryptoState.INVALID);
|
setSignatureImageAndTextColor(CryptoState.INVALID);
|
||||||
resultSignatureText.setText(R.string.openpgp_result_invalid_signature);
|
resultSignatureText.setText(R.string.openpgp_result_invalid_signature);
|
||||||
|
|
||||||
resultSignatureLayout.setVisibility(View.GONE);
|
resultSignatureLayout.setVisibility(View.GONE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: {
|
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText, CryptoState.VERIFIED);
|
setSignatureImageAndTextColor(CryptoState.VERIFIED);
|
||||||
resultSignatureText.setText(R.string.openpgp_result_signature_certified);
|
resultSignatureText.setText(R.string.openpgp_result_signature_certified);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -116,8 +116,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING: {
|
case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING: {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText,
|
setSignatureImageAndTextColor(CryptoState.UNKNOWN_KEY);
|
||||||
CryptoState.UNKNOWN_KEY);
|
|
||||||
resultSignatureText.setText(R.string.openpgp_result_signature_missing_key);
|
resultSignatureText.setText(R.string.openpgp_result_signature_missing_key);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -130,8 +129,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: {
|
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText,
|
setSignatureImageAndTextColor(CryptoState.UNVERIFIED);
|
||||||
CryptoState.UNVERIFIED);
|
|
||||||
resultSignatureText.setText(R.string.openpgp_result_signature_uncertified);
|
resultSignatureText.setText(R.string.openpgp_result_signature_uncertified);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -144,7 +142,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED: {
|
case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED: {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText, CryptoState.EXPIRED);
|
setSignatureImageAndTextColor(CryptoState.EXPIRED);
|
||||||
resultSignatureText.setText(R.string.openpgp_result_signature_expired_key);
|
resultSignatureText.setText(R.string.openpgp_result_signature_expired_key);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -157,7 +155,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED: {
|
case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED: {
|
||||||
setStatusImageAndTextColor(context, resultSignatureIcon, resultSignatureText, CryptoState.REVOKED);
|
setSignatureImageAndTextColor(CryptoState.REVOKED);
|
||||||
resultSignatureText.setText(R.string.openpgp_result_signature_revoked_key);
|
resultSignatureText.setText(R.string.openpgp_result_signature_revoked_key);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -191,9 +189,15 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusImageAndTextColor(Context context, ImageView statusIcon, TextView statusText,
|
private void setEncryptionImageAndTextColor(CryptoState state) {
|
||||||
CryptoState state) {
|
setStatusImageAndTextColor(resultEncryptionIcon, resultEncryptionText, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSignatureImageAndTextColor(CryptoState state) {
|
||||||
|
setStatusImageAndTextColor(resultSignatureIcon, resultSignatureText, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setStatusImageAndTextColor(ImageView statusIcon, TextView statusText, CryptoState state) {
|
||||||
Drawable statusImageDrawable = context.getResources().getDrawable(state.getDrawableId());
|
Drawable statusImageDrawable = context.getResources().getDrawable(state.getDrawableId());
|
||||||
statusIcon.setImageDrawable(statusImageDrawable);
|
statusIcon.setImageDrawable(statusImageDrawable);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user