mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-31 15:10:19 -05:00
import-log: use supertoast in ImportKeyActivity
This commit is contained in:
parent
cdc61c4392
commit
d73a3e2fa8
@ -38,7 +38,10 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.devspark.appmsg.AppMsg;
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||
import com.github.johnpersano.supertoasts.util.Style;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@ -47,7 +50,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.BadImportKeyDialogFragment;
|
||||
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -135,6 +138,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
}
|
||||
|
||||
handleActions(savedInstanceState, getIntent());
|
||||
|
||||
}
|
||||
|
||||
protected void handleActions(Bundle savedInstanceState, Intent intent) {
|
||||
@ -331,8 +335,11 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
|
||||
public void loadFromFingerprint(Bundle savedInstanceState, String fingerprint) {
|
||||
if (fingerprint == null || fingerprint.length() < 40) {
|
||||
AppMsg.makeText(this, R.string.import_qr_code_too_short_fingerprint,
|
||||
AppMsg.STYLE_ALERT).show();
|
||||
SuperCardToast toast = SuperCardToast.create(this,
|
||||
getString(R.string.import_qr_code_too_short_fingerprint),
|
||||
SuperToast.Duration.LONG);
|
||||
toast.setBackground(SuperToast.Background.RED);
|
||||
toast.show();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -368,34 +375,84 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||
// get returned data bundle
|
||||
Bundle returnData = message.getData();
|
||||
final ImportResult result =
|
||||
returnData.<ImportResult>getParcelable(KeychainIntentService.RESULT);
|
||||
|
||||
// , make pessimistic assumptions
|
||||
String str = Integer.toString(result.getResult());
|
||||
int duration = 0, color = Style.RED;
|
||||
|
||||
switch(result.getResult()) {
|
||||
case ImportResult.RESULT_OK_NEWKEYS:
|
||||
color = Style.GREEN;
|
||||
duration = SuperToast.Duration.LONG;
|
||||
str = getResources().getQuantityString(
|
||||
R.plurals.keys_added, result.mNewKeys, result.mNewKeys);
|
||||
break;
|
||||
|
||||
case ImportResult.RESULT_OK_UPDATED:
|
||||
color = Style.GREEN;
|
||||
duration = SuperToast.Duration.LONG;
|
||||
str = getResources().getQuantityString(
|
||||
R.plurals.keys_updated, result.mNewKeys, result.mNewKeys);
|
||||
break;
|
||||
|
||||
case ImportResult.RESULT_OK_BOTHKEYS:
|
||||
color = Style.GREEN;
|
||||
duration = SuperToast.Duration.LONG;
|
||||
str = getResources().getQuantityString(
|
||||
R.plurals.keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
|
||||
str += getResources().getQuantityString(
|
||||
R.plurals.keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys);
|
||||
break;
|
||||
|
||||
case ImportResult.RESULT_OK_WITH_WARNINGS:
|
||||
str = "ok with warnings";
|
||||
color = Style.ORANGE;
|
||||
break;
|
||||
|
||||
case ImportResult.RESULT_PARTIAL_WITH_ERRORS:
|
||||
str = "partial with errors";
|
||||
color = Style.ORANGE;
|
||||
break;
|
||||
|
||||
case ImportResult.RESULT_FAIL_ERROR:
|
||||
str = "fail error";
|
||||
color = Style.RED;
|
||||
break;
|
||||
|
||||
case ImportResult.RESULT_FAIL_NOTHING:
|
||||
str = getString(R.string.no_keys_added_or_updated);
|
||||
color = Style.RED;
|
||||
break;
|
||||
|
||||
int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED);
|
||||
int updated = returnData
|
||||
.getInt(KeychainIntentService.RESULT_IMPORT_UPDATED);
|
||||
int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD);
|
||||
String toastMessage;
|
||||
if (added > 0 && updated > 0) {
|
||||
String addedStr = getResources().getQuantityString(
|
||||
R.plurals.keys_added_and_updated_1, added, added);
|
||||
String updatedStr = getResources().getQuantityString(
|
||||
R.plurals.keys_added_and_updated_2, updated, updated);
|
||||
toastMessage = addedStr + updatedStr;
|
||||
} else if (added > 0) {
|
||||
toastMessage = getResources().getQuantityString(R.plurals.keys_added,
|
||||
added, added);
|
||||
} else if (updated > 0) {
|
||||
toastMessage = getResources().getQuantityString(R.plurals.keys_updated,
|
||||
updated, updated);
|
||||
} else {
|
||||
toastMessage = getString(R.string.no_keys_added_or_updated);
|
||||
}
|
||||
AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO)
|
||||
.show();
|
||||
SuperCardToast toast = new SuperCardToast(ImportKeysActivity.this,
|
||||
SuperToast.Type.BUTTON, Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(duration);
|
||||
toast.setIndeterminate(duration == 0);
|
||||
toast.setButtonText("View log");
|
||||
toast.setSwipeToDismiss(true);
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
new SuperToast.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, Parcelable token) {
|
||||
// Intent intent = new Intent(
|
||||
// ImportKeysActivity.this, LogDisplayActivity.class);
|
||||
// intent.putExtra(LogDisplayFragment.EXTRA_RESULT, result);
|
||||
// startActivity(intent);
|
||||
}
|
||||
}));
|
||||
toast.show();
|
||||
|
||||
/*
|
||||
if (bad > 0) {
|
||||
BadImportKeyDialogFragment badImportKeyDialogFragment =
|
||||
BadImportKeyDialogFragment.newInstance(bad);
|
||||
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
|
||||
}
|
||||
*/
|
||||
|
||||
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
|
||||
ImportKeysActivity.this.setResult(Activity.RESULT_OK, mPendingIntentData);
|
||||
@ -483,7 +540,11 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
startService(intent);
|
||||
|
||||
} else {
|
||||
AppMsg.makeText(this, R.string.error_nothing_import, AppMsg.STYLE_ALERT).show();
|
||||
SuperCardToast toast = SuperCardToast.create(this,
|
||||
getString(R.string.error_nothing_import),
|
||||
SuperToast.Duration.LONG);
|
||||
toast.setBackground(SuperToast.Background.RED);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user