mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 18:40: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.view.View.OnClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
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.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
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.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
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 org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -135,6 +138,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleActions(savedInstanceState, getIntent());
|
handleActions(savedInstanceState, getIntent());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleActions(Bundle savedInstanceState, Intent intent) {
|
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) {
|
public void loadFromFingerprint(Bundle savedInstanceState, String fingerprint) {
|
||||||
if (fingerprint == null || fingerprint.length() < 40) {
|
if (fingerprint == null || fingerprint.length() < 40) {
|
||||||
AppMsg.makeText(this, R.string.import_qr_code_too_short_fingerprint,
|
SuperCardToast toast = SuperCardToast.create(this,
|
||||||
AppMsg.STYLE_ALERT).show();
|
getString(R.string.import_qr_code_too_short_fingerprint),
|
||||||
|
SuperToast.Duration.LONG);
|
||||||
|
toast.setBackground(SuperToast.Background.RED);
|
||||||
|
toast.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,34 +375,84 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
// get returned data bundle
|
// get returned data bundle
|
||||||
Bundle returnData = message.getData();
|
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)
|
SuperCardToast toast = new SuperCardToast(ImportKeysActivity.this,
|
||||||
.show();
|
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) {
|
if (bad > 0) {
|
||||||
BadImportKeyDialogFragment badImportKeyDialogFragment =
|
BadImportKeyDialogFragment badImportKeyDialogFragment =
|
||||||
BadImportKeyDialogFragment.newInstance(bad);
|
BadImportKeyDialogFragment.newInstance(bad);
|
||||||
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
|
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
|
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
|
||||||
ImportKeysActivity.this.setResult(Activity.RESULT_OK, mPendingIntentData);
|
ImportKeysActivity.this.setResult(Activity.RESULT_OK, mPendingIntentData);
|
||||||
@ -483,7 +540,11 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
startService(intent);
|
startService(intent);
|
||||||
|
|
||||||
} else {
|
} 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