improve CertifyResult, add custom notify

This commit is contained in:
Vincent Breitmoser 2014-10-04 16:01:24 +02:00
parent 0e0e3d8dd0
commit d004bf236b
15 changed files with 140 additions and 26 deletions

View File

@ -1,7 +1,5 @@
package org.sufficientlysecure.keychain.pgp;
import android.content.Context;
import org.spongycastle.openpgp.PGPException;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@ -10,7 +8,6 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.results.CertifyResult;
import org.sufficientlysecure.keychain.service.results.EditKeyResult;
import org.sufficientlysecure.keychain.service.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.service.results.SaveKeyringResult;
@ -141,6 +138,11 @@ public class PgpCertifyOperation {
}
if (certifyOk == 0) {
log.add(LogType.MSG_CRT_ERROR_NOTHING, 0);
return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError);
}
log.add(LogType.MSG_CRT_SUCCESS, 0);
return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError);

View File

@ -18,7 +18,21 @@
package org.sufficientlysecure.keychain.service.results;
import android.app.Activity;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
public class CertifyResult extends OperationResult {
@ -37,11 +51,15 @@ public class CertifyResult extends OperationResult {
/** Construct from a parcel - trivial because we have no extra data. */
public CertifyResult(Parcel source) {
super(source);
mCertifyOk = source.readInt();
mCertifyError = source.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeInt(mCertifyOk);
dest.writeInt(mCertifyError);
}
public static Creator<CertifyResult> CREATOR = new Creator<CertifyResult>() {
@ -54,4 +72,80 @@ public class CertifyResult extends OperationResult {
}
};
public SuperCardToast createNotify(final Activity activity) {
int resultType = getResult();
String str;
int duration, color;
// Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings;
duration = Duration.EXTRA_LONG;
color = Style.GREEN;
withWarnings = "";
// Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0;
color = Style.ORANGE;
withWarnings += activity.getString(R.string.with_warnings);
}
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0;
color = Style.ORANGE;
withWarnings += activity.getString(R.string.with_cancelled);
}
// New and updated keys
str = activity.getResources().getQuantityString(
R.plurals.certify_keys_ok, mCertifyOk, mCertifyOk, withWarnings);
if (mCertifyError > 0) {
// definitely switch to warning-style message in this case!
duration = 0;
color = Style.RED;
str += " " + activity.getResources().getQuantityString(
R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError);
}
} else {
duration = 0;
color = Style.RED;
str = activity.getResources().getQuantityString(R.plurals.certify_error,
mCertifyError, mCertifyError);
}
boolean button = getLog() != null && !getLog().isEmpty();
SuperCardToast toast = new SuperCardToast(activity,
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(duration);
toast.setIndeterminate(duration == 0);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
}
}

View File

@ -124,12 +124,12 @@ public class ImportKeyResult extends OperationResult {
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0;
color = Style.ORANGE;
withWarnings += activity.getString(R.string.import_with_warnings);
withWarnings += activity.getString(R.string.with_warnings);
}
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0;
color = Style.ORANGE;
withWarnings += activity.getString(R.string.import_with_cancelled);
withWarnings += activity.getString(R.string.with_cancelled);
}
// New and updated keys

View File

@ -521,6 +521,7 @@ public abstract class OperationResult implements Parcelable {
MSG_CRT_CERTIFY_ALL (LogLevel.DEBUG, R.string.msg_crt_certify_all),
MSG_CRT_CERTIFY_SOME (LogLevel.DEBUG, R.plurals.msg_crt_certify_some),
MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found),
MSG_CRT_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_crt_error_nothing),
MSG_CRT_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_crt_error_unlock),
MSG_CRT_FP_MISMATCH (LogLevel.WARN, R.string.msg_crt_fp_mismatch),
MSG_CRT (LogLevel.START, R.string.msg_crt),

View File

@ -329,7 +329,7 @@
<string name="view_log">Zobrazit log</string>
<string name="import_error_nothing">Nic k importu</string>
<string name="import_error_nothing_cancelled">Import zrušen.</string>
<string name="import_with_warnings">, s varováními</string>
<string name="with_warnings">, s varováními</string>
<plurals name="import_error">
<item quantity="one">Import selhal!</item>
<item quantity="few">Import %d klíčů selhal!</item>

View File

@ -369,8 +369,8 @@
<string name="view_log">Log ansehen</string>
<string name="import_error_nothing">Nichts zu importieren.</string>
<string name="import_error_nothing_cancelled">Import abgebrochen.</string>
<string name="import_with_warnings">, mit Warnungen</string>
<string name="import_with_cancelled">. bis abgebrochen wurde</string>
<string name="with_warnings">, mit Warnungen</string>
<string name="with_cancelled">. bis abgebrochen wurde</string>
<plurals name="import_error">
<item quantity="one">Importieren fehlgeschlagen!</item>
<item quantity="other">Importieren von %d Schlüsseln fehlgeschlagen!</item>

View File

@ -357,8 +357,8 @@
<string name="view_log">Ver registro (log)</string>
<string name="import_error_nothing">No hay nada que importar.</string>
<string name="import_error_nothing_cancelled">Importación cancelada.</string>
<string name="import_with_warnings">, con advertencias</string>
<string name="import_with_cancelled">, hasta que este cancelada</string>
<string name="with_warnings">, con advertencias</string>
<string name="with_cancelled">, hasta que este cancelada</string>
<!--Intent labels-->
<string name="intent_decrypt_file">Descifrar archivo con OpenKeychain</string>
<string name="intent_import_key">Importar clave con OpenKeychain</string>

View File

@ -357,8 +357,8 @@
<string name="view_log">Consulter le journal</string>
<string name="import_error_nothing">Rien à importer.</string>
<string name="import_error_nothing_cancelled">Importation annulée.</string>
<string name="import_with_warnings">, avec des avertissements</string>
<string name="import_with_cancelled">, jusqu\'à l\'annulation</string>
<string name="with_warnings">, avec des avertissements</string>
<string name="with_cancelled">, jusqu\'à l\'annulation</string>
<!--Intent labels-->
<string name="intent_decrypt_file">Déchiffrer le fichier avec OpenKeychain</string>
<string name="intent_import_key">Importer la clef avec OpenKeychain</string>

View File

@ -362,7 +362,7 @@ Non potrai annullare!</string>
<string name="view_log">Mostra registro</string>
<string name="import_error_nothing">Niente da importare</string>
<string name="import_error_nothing_cancelled">Importazione cancellata.</string>
<string name="import_with_warnings">, con avvisi</string>
<string name="with_warnings">, con avvisi</string>
<!--Intent labels-->
<string name="intent_decrypt_file">Decodifica File con OpenKeychain</string>
<string name="intent_import_key">Importa Chiave con OpenKeychain</string>

View File

@ -371,8 +371,8 @@
<string name="view_log">ログを見る</string>
<string name="import_error_nothing">インポートするものがありません。</string>
<string name="import_error_nothing_cancelled">インポートをキャンセルしました。</string>
<string name="import_with_warnings">、とワーニング</string>
<string name="import_with_cancelled">、キャンセルされるまで</string>
<string name="with_warnings">、とワーニング</string>
<string name="with_cancelled">、キャンセルされるまで</string>
<plurals name="import_error">
<item quantity="other">%d 個の鍵のインポート失敗!</item>
</plurals>

View File

@ -311,7 +311,7 @@
</plurals>
<string name="view_log">Смотреть журнал</string>
<string name="import_error_nothing">Нет данных для импорта.</string>
<string name="import_with_warnings">, с предупреждениями</string>
<string name="with_warnings">, с предупреждениями</string>
<!--Intent labels-->
<string name="intent_decrypt_file">OpenKeychain: Расшифровать файл</string>
<string name="intent_import_key">OpenKeychain: Импортировать ключ</string>

View File

@ -319,8 +319,8 @@
<string name="view_log">Poglej dnevnik</string>
<string name="import_error_nothing">Nič za uvoziti.</string>
<string name="import_error_nothing_cancelled">Uvoz preklican.</string>
<string name="import_with_warnings">, z opozorilom</string>
<string name="import_with_cancelled"> do preklica</string>
<string name="with_warnings">, z opozorilom</string>
<string name="with_cancelled"> do preklica</string>
<!--Intent labels-->
<string name="intent_decrypt_file">Dešifriraj datoteko z OpenKeychain</string>
<string name="intent_import_key">Uvozi ključ z OpenKeychain</string>

View File

@ -330,8 +330,8 @@
<string name="view_log">Прикажи дневник</string>
<string name="import_error_nothing">Нема ништа за увоз.</string>
<string name="import_error_nothing_cancelled">Увоз је отказан.</string>
<string name="import_with_warnings">, са упозорењима</string>
<string name="import_with_cancelled">, док није отказано</string>
<string name="with_warnings">, са упозорењима</string>
<string name="with_cancelled">, док није отказано</string>
<!--Intent labels-->
<string name="intent_decrypt_file">Дешифруј фајл помоћу Отвореног кључарника</string>
<string name="intent_import_key">Увези кључ у Отворени кључарник</string>

View File

@ -327,7 +327,7 @@
</plurals>
<string name="view_log">Переглянути журнал</string>
<string name="import_error_nothing">Нема що імпортувати.</string>
<string name="import_with_warnings">, із застереженнями</string>
<string name="with_warnings">, із застереженнями</string>
<!--Intent labels-->
<string name="intent_decrypt_file">Розшифрувати файл з OpenKeychain</string>
<string name="intent_import_key">Імпортувати ключ з OpenKeychain</string>

View File

@ -387,6 +387,11 @@
<string name="import_qr_code_too_short_fingerprint">"Fingerprint is too short (&lt; 16 characters)"</string>
<string name="import_qr_code_button">"Scan QR Code…"</string>
<!-- Generic result toast -->
<string name="view_log">"View Log"</string>
<string name="with_warnings">", with warnings"</string>
<string name="with_cancelled">", until cancelled"</string>
<!-- Import result toast -->
<plurals name="import_keys_added_and_updated_1">
<item quantity="one">"Successfully imported key"</item>
@ -408,15 +413,26 @@
<item quantity="one">"Import failed for one key!"</item>
<item quantity="other">"Import failed for %d keys!"</item>
</plurals>
<string name="view_log">"View Log"</string>
<string name="import_error_nothing">"Nothing to import."</string>
<string name="import_error_nothing_cancelled">"Import cancelled."</string>
<string name="import_with_warnings">", with warnings"</string>
<string name="import_with_cancelled">", until cancelled"</string>
<plurals name="import_error">
<item quantity="one">"Import failed!"</item>
<item quantity="other">"Import of %d keys failed!"</item>
</plurals>
<string name="import_error_nothing">"Nothing to import."</string>
<string name="import_error_nothing_cancelled">"Import cancelled."</string>
<!-- Certify result toast -->
<plurals name="certify_keys_ok">
<item quantity="one">"Successfully certified key%2$s."</item>
<item quantity="other">"Successfully certified %1$d keys%2$s."</item>
</plurals>
<plurals name="certify_keys_with_errors">
<item quantity="one">"Certification failed!"</item>
<item quantity="other">"Certification failed for %d keys!"</item>
</plurals>
<plurals name="certify_error">
<item quantity="one">"Certification failed!"</item>
<item quantity="other">"Certification of %d keys failed!"</item>
</plurals>
<!-- Intent labels -->
<string name="intent_decrypt_file">"Decrypt File with OpenKeychain"</string>
@ -882,6 +898,7 @@
<item quantity="other">"Certifying %1$d user ids for key %2$s"</item>
</plurals>
<string name="msg_crt_error_master_not_found">"Master key not found!"</string>
<string name="msg_crt_error_nothing">"No keys certified!"</string>
<string name="msg_crt_error_unlock">"Error unlocking master key!"</string>
<string name="msg_crt_fp_mismatch">"Fingerprint mismatch, not certifying!"</string>
<string name="msg_crt">"Certifying keyrings"</string>