display keyserver status on card

This commit is contained in:
Vincent Breitmoser 2017-05-20 21:46:47 +02:00
parent d75d400453
commit 00e411b1e3
19 changed files with 521 additions and 1 deletions

View File

@ -40,6 +40,8 @@ import org.sufficientlysecure.keychain.ui.keyview.presenter.ViewKeyMvpView;
import org.sufficientlysecure.keychain.ui.keyview.view.IdentitiesCardView;
import org.sufficientlysecure.keychain.ui.keyview.view.KeyHealthView;
import org.sufficientlysecure.keychain.ui.keyview.view.SystemContactCardView;
import org.sufficientlysecure.keychain.ui.keyview.view.KeyserverStatusCardView;
import org.sufficientlysecure.keychain.ui.keyview.presenter.KeyserverStatusPresenter;
public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
@ -51,6 +53,7 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
private static final int LOADER_IDENTITIES = 1;
private static final int LOADER_ID_LINKED_CONTACT = 2;
private static final int LOADER_ID_SUBKEY_STATUS = 3;
private static final int LOADER_ID_KEYSERVER_STATUS = 4;
private IdentitiesCardView mIdentitiesCardView;
private IdentitiesPresenter mIdentitiesPresenter;
@ -62,6 +65,9 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
KeyHealthPresenter mKeyHealthPresenter;
KeyserverStatusCardView mKeyserverStatusCard;
KeyserverStatusPresenter mKeyserverStatusPresenter;
/**
* Creates new instance of this fragment
*/
@ -85,6 +91,7 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
mSystemContactCard = (SystemContactCardView) view.findViewById(R.id.linked_system_contact_card);
mKeyStatusHealth = (KeyHealthView) view.findViewById(R.id.key_status_health);
mKeyserverStatusCard = (KeyserverStatusCardView) view.findViewById(R.id.keyserver_status_card);
return root;
}
@ -107,6 +114,10 @@ public class ViewKeyFragment extends LoaderFragment implements ViewKeyMvpView {
mKeyHealthPresenter = new KeyHealthPresenter(
getContext(), mKeyStatusHealth, LOADER_ID_SUBKEY_STATUS, masterKeyId, mIsSecret);
mKeyHealthPresenter.startLoader(getLoaderManager());
mKeyserverStatusPresenter = new KeyserverStatusPresenter(
getContext(), mKeyserverStatusCard, LOADER_ID_KEYSERVER_STATUS, masterKeyId, mIsSecret);
mKeyserverStatusPresenter.startLoader(getLoaderManager());
}
@Override

View File

@ -0,0 +1,136 @@
/*
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.keyview.loader;
import java.util.Date;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusLoader.KeyserverStatus;
public class KeyserverStatusLoader extends AsyncTaskLoader<KeyserverStatus> {
public static final String[] PROJECTION = new String[] {
UpdatedKeys.LAST_UPDATED,
UpdatedKeys.SEEN_ON_KEYSERVERS
};
private static final int INDEX_LAST_UPDATED = 0;
private static final int INDEX_SEEN_ON_KEYSERVERS = 1;
private final ContentResolver contentResolver;
private final long masterKeyId;
private KeyserverStatus cachedResult;
public KeyserverStatusLoader(Context context, ContentResolver contentResolver, long masterKeyId) {
super(context);
this.contentResolver = contentResolver;
this.masterKeyId = masterKeyId;
}
@Override
public KeyserverStatus loadInBackground() {
Cursor cursor = contentResolver.query(UpdatedKeys.CONTENT_URI, PROJECTION,
UpdatedKeys.MASTER_KEY_ID + " = ?", new String[] { Long.toString(masterKeyId) }, null);
if (cursor == null) {
Log.e(Constants.TAG, "Error loading key items!");
return null;
}
try {
if (cursor.moveToFirst()) {
boolean isPublished = cursor.getInt(INDEX_SEEN_ON_KEYSERVERS) != 0;
Date lastUpdated = cursor.isNull(INDEX_LAST_UPDATED) ?
null : new Date(cursor.getLong(INDEX_LAST_UPDATED) * 1000);
return new KeyserverStatus(masterKeyId, isPublished, lastUpdated);
}
return new KeyserverStatus(masterKeyId);
} finally {
cursor.close();
}
}
@Override
public void deliverResult(KeyserverStatus keySubkeyStatus) {
cachedResult = keySubkeyStatus;
if (isStarted()) {
super.deliverResult(keySubkeyStatus);
}
}
@Override
protected void onStartLoading() {
if (cachedResult != null) {
deliverResult(cachedResult);
}
if (takeContentChanged() || cachedResult == null) {
forceLoad();
}
}
public static class KeyserverStatus {
private final long masterKeyId;
private final boolean isPublished;
private final Date lastUpdated;
KeyserverStatus(long masterKeyId, boolean isPublished, Date lastUpdated) {
this.masterKeyId = masterKeyId;
this.isPublished = isPublished;
this.lastUpdated = lastUpdated;
}
KeyserverStatus(long masterKeyId) {
this.masterKeyId = masterKeyId;
this.isPublished = false;
this.lastUpdated = null;
}
long getMasterKeyId() {
return masterKeyId;
}
public boolean hasBeenUpdated() {
return lastUpdated != null;
}
public boolean isPublished() {
if (lastUpdated == null) {
throw new IllegalStateException("Cannot get publication state if key has never been updated!");
}
return isPublished;
}
public Date getLastUpdated() {
return lastUpdated;
}
}
}

View File

@ -0,0 +1,103 @@
/*
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.keyview.presenter;
import java.util.Date;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusLoader;
import org.sufficientlysecure.keychain.ui.keyview.loader.KeyserverStatusLoader.KeyserverStatus;
public class KeyserverStatusPresenter implements LoaderCallbacks<KeyserverStatus> {
private final Context context;
private final KeyserverStatusMvpView view;
private final int loaderId;
private final long masterKeyId;
private final boolean isSecret;
public KeyserverStatusPresenter(Context context, KeyserverStatusMvpView view, int loaderId, long masterKeyId,
boolean isSecret) {
this.context = context;
this.view = view;
this.loaderId = loaderId;
this.masterKeyId = masterKeyId;
this.isSecret = isSecret;
view.setOnKeyserverClickListener(new KeyserverStatusClickListener() {
@Override
public void onKeyRefreshClick() {
KeyserverStatusPresenter.this.onKeyRefreshClick();
}
});
}
public void startLoader(LoaderManager loaderManager) {
loaderManager.restartLoader(loaderId, null, this);
}
@Override
public Loader<KeyserverStatus> onCreateLoader(int id, Bundle args) {
return new KeyserverStatusLoader(context, context.getContentResolver(), masterKeyId);
}
@Override
public void onLoadFinished(Loader<KeyserverStatus> loader, KeyserverStatus keyserverStatus) {
if (keyserverStatus.hasBeenUpdated()) {
if (keyserverStatus.isPublished()) {
view.setDisplayStatusPublished();
} else {
view.setDisplayStatusNotPublished();
}
view.setLastUpdated(keyserverStatus.getLastUpdated());
} else {
view.setDisplayStatusUnknown();
}
}
@Override
public void onLoaderReset(Loader loader) {
}
private void onKeyRefreshClick() {
}
public interface KeyserverStatusMvpView {
void setOnKeyserverClickListener(KeyserverStatusClickListener keyserverStatusClickListener);
void setDisplayStatusPublished();
void setDisplayStatusNotPublished();
void setLastUpdated(Date lastUpdated);
void setDisplayStatusUnknown();
}
public interface KeyserverStatusClickListener {
void onKeyRefreshClick();
}
}

View File

@ -0,0 +1,124 @@
/*
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.keyview.view;
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;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.keyview.presenter.KeyserverStatusPresenter.KeyserverStatusClickListener;
import org.sufficientlysecure.keychain.ui.keyview.presenter.KeyserverStatusPresenter.KeyserverStatusMvpView;
public class KeyserverStatusCardView extends CardView implements KeyserverStatusMvpView, OnClickListener {
private final View vLayout;
private final TextView vTitle;
private final TextView vSubtitle;
private final ImageView vIcon;
private KeyserverStatusClickListener keyHealthClickListener;
public KeyserverStatusCardView(Context context, AttributeSet attrs) {
super(context, attrs);
View view = LayoutInflater.from(context).inflate(R.layout.key_keyserver_card_content, this, true);
vLayout = view.findViewById(R.id.key_health_layout);
vTitle = (TextView) view.findViewById(R.id.keyserver_status_title);
vSubtitle = (TextView) view.findViewById(R.id.keyserver_status_subtitle);
vIcon = (ImageView) view.findViewById(R.id.keyserver_icon);
// vExpander = (ImageView) view.findViewById(R.id.key_health_expander);
}
private enum KeyserverDisplayStatus {
PUBLISHED (R.string.keyserver_title_published, R.drawable.ic_cloud_black_24dp, R.color.md_grey_900),
NOT_PUBLISHED (R.string.keyserver_title_not_published, R.drawable.ic_cloud_off_24dp, R.color.md_grey_900),
UNKNOWN (R.string.keyserver_title_unknown, R.drawable.ic_cloud_unknown_24dp, R.color.md_grey_900);
@StringRes
private final int title;
@DrawableRes
private final int icon;
@ColorRes
private final int iconColor;
KeyserverDisplayStatus(@StringRes int title, @DrawableRes int icon, @ColorRes int iconColor) {
this.title = title;
this.icon = icon;
this.iconColor = iconColor;
}
}
@Override
public void onClick(View view) {
if (keyHealthClickListener != null) {
keyHealthClickListener.onKeyRefreshClick();
}
}
@Override
public void setOnKeyserverClickListener(KeyserverStatusClickListener keyHealthClickListener) {
this.keyHealthClickListener = keyHealthClickListener;
vLayout.setClickable(keyHealthClickListener != null);
}
@Override
public void setDisplayStatusPublished() {
setDisplayStatus(KeyserverDisplayStatus.PUBLISHED);
}
@Override
public void setDisplayStatusNotPublished() {
setDisplayStatus(KeyserverDisplayStatus.NOT_PUBLISHED);
}
@Override
public void setDisplayStatusUnknown() {
setDisplayStatus(KeyserverDisplayStatus.UNKNOWN);
vSubtitle.setVisibility(View.GONE);
}
@Override
public void setLastUpdated(Date lastUpdated) {
String lastUpdatedText = DateFormat.getMediumDateFormat(getContext()).format(lastUpdated);
vSubtitle.setText(getResources().getString(R.string.keyserver_last_updated, lastUpdatedText));
}
private void setDisplayStatus(KeyserverDisplayStatus displayStatus) {
vTitle.setText(displayStatus.title);
vIcon.setImageResource(displayStatus.icon);
vIcon.setColorFilter(ContextCompat.getColor(getContext(), displayStatus.iconColor));
setVisibility(View.VISIBLE);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,78 @@
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/CardViewHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keyserver Status" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/key_health_layout"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:background="?selectableItemBackground"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/keyserver_icon"
tools:src="@drawable/ic_cloud_black_24dp"
tools:tint="@color/android_green_light"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/keyserver_status_title"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="@string/keyserver_title_published" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/keyserver_status_subtitle"
tools:text="Last updated: 2017-05-20" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/key_health_expander"
android:src="@drawable/ic_expand_more_black_24dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:visibility="gone"
tools:visibility="visible"
/>
</LinearLayout>
</LinearLayout>
</merge>

View File

@ -1842,6 +1842,11 @@
<string name="key_health_partial_stripped_title">"Healthy (Partially Stripped)"</string>
<string name="key_health_partial_stripped_subtitle">"Click for details"</string>
<string name="keyserver_title_published">"Published"</string>
<string name="keyserver_title_not_published">"Not Published"</string>
<string name="keyserver_title_unknown">"Unknown"</string>
<string name="keyserver_last_updated">"Last updated: %s"</string>
<string name="key_insecure_bitstrength_2048_problem">"This key uses the <b>%1$s</b> algorithm with a strength of <b>%2$s bits</b>. A secure key should have a strength of 2048 bits."</string>
<string name="key_insecure_bitstrength_2048_solution">"This key can\'t be upgraded. For secure communication, the owner must generate a new key."</string>

View File

@ -0,0 +1,4 @@
<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M19.35 10.04C18.67 6.59 15.64 4 12 4c-1.48 0-2.85.43-4.01 1.17l1.46 1.46C10.21 6.23 11.08 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 1.13-.64 2.11-1.56 2.62l1.45 1.45C23.16 18.16 24 16.68 24 15c0-2.64-2.05-4.78-4.65-4.96zM3 5.27l2.75 2.74C2.56 8.15 0 10.77 0 14c0 3.31 2.69 6 6 6h11.73l2 2L21 20.73 4.27 4 3 5.27zM7.73 10l8 8H6c-2.21 0-4-1.79-4-4s1.79-4 4-4h1.73z"/>
</svg>

After

Width:  |  Height:  |  Size: 541 B

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="190.282px" height="190.282px" viewBox="0 0 190.282 190.282" style="enable-background:new 0 0 190.282 190.282;"
xml:space="preserve">
<g>
<g id="_x31_48_28_">
<g>
<rect x="161.592" y="134.46" width="15.346" height="14.609"/>
<path d="M189.068,105.211c-0.711-1.793-1.833-3.438-3.355-4.941c-1.523-1.492-3.515-2.722-5.973-3.687
c-2.457-0.96-5.479-1.437-9.074-1.437c-3.636,0-6.723,0.548-9.252,1.655c-2.533,1.106-4.615,2.544-6.23,4.312
c-1.63,1.777-2.828,3.782-3.615,6.012c-0.782,2.239-1.255,4.515-1.402,6.83h15.417c-0.147-1.63,0.147-3.077,0.884-4.352
c0.736-1.28,1.99-1.92,3.763-1.92c2.849,0,4.275,1.249,4.275,3.763c0,0.838-0.243,1.549-0.736,2.138
c-0.497,0.59-1.097,1.098-1.812,1.514c-0.711,0.416-1.457,0.797-2.249,1.143c-0.793,0.351-1.473,0.665-2.067,0.965
c-1.422,0.782-2.498,1.772-3.245,2.945c-0.736,1.183-1.249,2.387-1.549,3.615c-0.294,1.229-0.441,2.433-0.441,3.61
c0,1.133,0.025,2.062,0.081,2.798h13.645c0-0.827,0.062-1.568,0.178-2.209c0.122-0.64,0.335-1.203,0.63-1.695
c0.3-0.493,0.716-0.96,1.254-1.402c0.544-0.446,1.229-0.889,2.062-1.33c1.224-0.64,2.438-1.265,3.61-1.879
c1.188-0.614,2.254-1.392,3.209-2.325c0.955-0.93,1.731-2.098,2.325-3.504c0.584-1.401,0.884-3.229,0.884-5.495
C190.186,108.709,189.785,107.009,189.068,105.211z"/>
<path d="M176.42,73.035c1.193,0,2.376,0.099,3.555,0.178c0.167-1.176,0.299-2.356,0.36-3.547
c-1.158-21.498-16.463-36.785-37.942-37.945c-12.604-0.675-23.115,5.759-29.859,15.168C105.8,38.02,95.317,32.408,82.655,31.72
c-21.439-1.152-36.869,18.199-37.933,37.945c-0.122,2.536,0.041,4.977,0.437,7.335c-1.343-0.19-2.709-0.32-4.103-0.398
c-23.176-1.249-39.852,19.672-41.002,41c-1.181,21.805,17.266,37.851,37.222,40.628v0.381h101.679
c-8.389-9.095-13.558-21.205-13.558-34.561C125.391,95.877,148.242,73.035,176.42,73.035z"/>
</g>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -22,7 +22,7 @@ SRC_DIR=./drawables/
#inkscape -w 512 -h 512 -e "$PLAY_DIR/$NAME.png" $NAME.svg
for NAME in "broken_heart" "ic_cloud_search" "ic_action_encrypt_file" "ic_action_encrypt_text" "ic_action_verified_cutout" "ic_action_encrypt_copy" "ic_action_encrypt_paste" "ic_action_encrypt_save" "ic_action_encrypt_share" "status_lock_closed" "status_lock_error" "status_lock_open" "status_signature_expired_cutout" "status_signature_invalid_cutout" "status_signature_revoked_cutout" "status_signature_unknown_cutout" "status_signature_unverified_cutout" "status_signature_verified_cutout" "key_flag_authenticate" "key_flag_certify" "key_flag_encrypt" "key_flag_sign" "yubi_icon" "ic_stat_notify" "status_signature_verified_inner" "link" "octo_link"
for NAME in "ic_cloud_unknown" "ic_cloud_off" "broken_heart" "ic_cloud_search" "ic_action_encrypt_file" "ic_action_encrypt_text" "ic_action_verified_cutout" "ic_action_encrypt_copy" "ic_action_encrypt_paste" "ic_action_encrypt_save" "ic_action_encrypt_share" "status_lock_closed" "status_lock_error" "status_lock_open" "status_signature_expired_cutout" "status_signature_invalid_cutout" "status_signature_revoked_cutout" "status_signature_unknown_cutout" "status_signature_unverified_cutout" "status_signature_verified_cutout" "key_flag_authenticate" "key_flag_certify" "key_flag_encrypt" "key_flag_sign" "yubi_icon" "ic_stat_notify" "status_signature_verified_inner" "link" "octo_link"
do
echo $NAME
inkscape -w 24 -h 24 -e "$MDPI_DIR/${NAME}_24dp.png" "$SRC_DIR/$NAME.svg"