add expiry date info to key status card

This commit is contained in:
Vincent Breitmoser
2017-04-24 18:59:43 +02:00
parent 1e8d5bdad3
commit 0db22b55e1
5 changed files with 61 additions and 8 deletions

View File

@@ -18,12 +18,15 @@
package org.sufficientlysecure.keychain.ui.widget;
import java.util.Date;
import android.content.Context;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -52,6 +55,8 @@ public class KeyHealthCardView extends CardView implements KeyHealthMvpView, OnC
private final View vInsecureLayout;
private final TextView vInsecureProblem;
private final TextView vInsecureSolution;
private final View vExpiryLayout;
private final TextView vExpiryText;
private KeyHealthClickListener keyHealthClickListener;
@@ -74,6 +79,9 @@ public class KeyHealthCardView extends CardView implements KeyHealthMvpView, OnC
vInsecureLayout = view.findViewById(R.id.key_insecure_layout);
vInsecureProblem = (TextView) view.findViewById(R.id.key_insecure_problem);
vInsecureSolution = (TextView) view.findViewById(R.id.key_insecure_solution);
vExpiryLayout = view.findViewById(R.id.key_expiry_layout);
vExpiryText = (TextView) view.findViewById(R.id.key_expiry_text);
}
private enum KeyHealthDisplayStatus {
@@ -147,6 +155,10 @@ public class KeyHealthCardView extends CardView implements KeyHealthMvpView, OnC
@Override
public void setPrimarySecurityProblem(KeySecurityProblem securityProblem) {
if (securityProblem == null) {
vInsecureLayout.setVisibility(View.GONE);
return;
}
vInsecureLayout.setVisibility(View.VISIBLE);
if (securityProblem instanceof InsecureBitStrength) {
@@ -165,6 +177,18 @@ public class KeyHealthCardView extends CardView implements KeyHealthMvpView, OnC
}
@Override
public void setPrimaryExpiryDate(Date expiry) {
if (expiry == null) {
vExpiryLayout.setVisibility(View.GONE);
return;
}
vExpiryLayout.setVisibility(View.VISIBLE);
String expiryText = DateFormat.getMediumDateFormat(getContext()).format(expiry);
vExpiryText.setText(getResources().getString(R.string.key_expiry_text, expiryText));
}
@Override
public void onClick(View view) {
if (keyHealthClickListener != null) {

View File

@@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.widget;
import java.util.Comparator;
import java.util.Date;
import android.content.Context;
import android.os.Bundle;
@@ -97,6 +98,7 @@ public class KeyHealthPresenter implements LoaderCallbacks<KeySubkeyStatus> {
KeyHealthStatus keyHealthStatus = determineKeyHealthStatus(subkeyStatus);
boolean isInsecure = keyHealthStatus == KeyHealthStatus.INSECURE;
boolean isExpired = keyHealthStatus == KeyHealthStatus.EXPIRED;
if (isInsecure) {
boolean primaryKeySecurityProblem = subkeyStatus.keyCertify.mSecurityProblem != null;
if (primaryKeySecurityProblem) {
@@ -108,10 +110,13 @@ public class KeyHealthPresenter implements LoaderCallbacks<KeySubkeyStatus> {
view.setShowExpander(false);
displayExpandedInfo(false);
}
} else if (isExpired) {
view.setKeyStatus(keyHealthStatus);
view.setPrimaryExpiryDate(subkeyStatus.keyCertify.mExpiry);
view.setShowExpander(false);
} else {
view.setKeyStatus(keyHealthStatus);
view.setShowExpander(
keyHealthStatus != KeyHealthStatus.EXPIRED && keyHealthStatus != KeyHealthStatus.REVOKED);
view.setShowExpander(keyHealthStatus != KeyHealthStatus.REVOKED);
}
}
@@ -253,6 +258,7 @@ public class KeyHealthPresenter implements LoaderCallbacks<KeySubkeyStatus> {
interface KeyHealthMvpView {
void setKeyStatus(KeyHealthStatus keyHealthStatus);
void setPrimarySecurityProblem(KeySecurityProblem securityProblem);
void setPrimaryExpiryDate(Date expiry);
void setShowExpander(boolean showExpander);
void showExpandedState(KeyDisplayStatus certifyStatus, KeyDisplayStatus signStatus,
@@ -260,6 +266,7 @@ public class KeyHealthPresenter implements LoaderCallbacks<KeySubkeyStatus> {
void hideExpandedInfo();
void setOnHealthClickListener(KeyHealthClickListener keyHealthClickListener);
}
interface KeyStatusMvpView {

View File

@@ -143,6 +143,7 @@ class SubkeyStatusLoader extends AsyncTaskLoader<KeySubkeyStatus> {
final Date mCreation;
final SecretKeyType mSecretKeyType;
final boolean mIsRevoked, mIsExpired;
final Date mExpiry;
final boolean mCanCertify, mCanSign, mCanEncrypt;
final KeySecurityProblem mSecurityProblem;
@@ -155,11 +156,8 @@ class SubkeyStatusLoader extends AsyncTaskLoader<KeySubkeyStatus> {
mSecretKeyType = SecretKeyType.fromNum(cursor.getInt(INDEX_HAS_SECRET));
mIsRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
Date expiryDate = null;
if (!cursor.isNull(INDEX_EXPIRY)) {
expiryDate = new Date(cursor.getLong(INDEX_EXPIRY) * 1000);
}
mIsExpired = expiryDate != null && expiryDate.before(new Date());
mExpiry = cursor.isNull(INDEX_EXPIRY) ? null : new Date(cursor.getLong(INDEX_EXPIRY) * 1000);
mIsExpired = mExpiry != null && mExpiry.before(new Date());
mCanCertify = cursor.getInt(INDEX_CAN_CERTIFY) > 0;
mCanSign = cursor.getInt(INDEX_CAN_SIGN) > 0;

View File

@@ -89,7 +89,7 @@
android:paddingRight="8dp"
android:id="@+id/key_insecure_layout"
android:visibility="gone"
tools:visibility="visible">
tools:visibility="gone">
<TextView
android:layout_width="wrap_content"
@@ -125,6 +125,28 @@
tools:text="@string/key_insecure_bitstrength_2048_solution" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:id="@+id/key_expiry_layout"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/key_expiry_text"
android:textAppearance="?android:textAppearanceSmall"
tools:text="@string/key_expiry_text"
/>
</LinearLayout>
<org.sufficientlysecure.keychain.ui.widget.KeyStatusList
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -1861,4 +1861,6 @@
<string name="key_insecure_unknown_curve_problem">"This key uses the <b>%1$s</b> algorithm, which is not whitelisted."</string>
<string name="key_insecure_unknown_curve_solution">"This key can\'t be upgraded. For secure communication, the owner must generate a new key."</string>
<string name="key_expiry_text">"This key expired on <b>%1$s</b>."</string>
</resources>