mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
pass import results through to viewkeyactivity on update
This commit is contained in:
parent
3acb7fb087
commit
6d7a9ec48a
@ -686,7 +686,7 @@ public class ProviderHelper {
|
|||||||
if (Arrays.hashCode(publicRing.getEncoded())
|
if (Arrays.hashCode(publicRing.getEncoded())
|
||||||
== Arrays.hashCode(oldPublicRing.getEncoded())) {
|
== Arrays.hashCode(oldPublicRing.getEncoded())) {
|
||||||
log(LogLevel.OK, LogType.MSG_IP_SUCCESS_IDENTICAL);
|
log(LogLevel.OK, LogType.MSG_IP_SUCCESS_IDENTICAL);
|
||||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_OK, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.UPDATED, mLog);
|
||||||
}
|
}
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
// Not an issue, just means we are dealing with a new keyring.
|
// Not an issue, just means we are dealing with a new keyring.
|
||||||
@ -771,7 +771,7 @@ public class ProviderHelper {
|
|||||||
== Arrays.hashCode(oldSecretRing.getEncoded())) {
|
== Arrays.hashCode(oldSecretRing.getEncoded())) {
|
||||||
log(LogLevel.OK, LogType.MSG_IS_SUCCESS_IDENTICAL,
|
log(LogLevel.OK, LogType.MSG_IS_SUCCESS_IDENTICAL,
|
||||||
PgpKeyHelper.convertKeyIdToHex(masterKeyId) );
|
PgpKeyHelper.convertKeyIdToHex(masterKeyId) );
|
||||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_OK, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.UPDATED, mLog);
|
||||||
}
|
}
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
// Not an issue, just means we are dealing with a new keyring
|
// Not an issue, just means we are dealing with a new keyring
|
||||||
|
@ -1,6 +1,19 @@
|
|||||||
package org.sufficientlysecure.keychain.service;
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Parcel;
|
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.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 abstract class OperationResults {
|
public abstract class OperationResults {
|
||||||
|
|
||||||
@ -67,6 +80,86 @@ public abstract class OperationResults {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void displayToast(final Activity activity) {
|
||||||
|
|
||||||
|
int resultType = getResult();
|
||||||
|
|
||||||
|
String str;
|
||||||
|
int duration, color;
|
||||||
|
|
||||||
|
// Not an overall failure
|
||||||
|
if ((resultType & ImportResult.RESULT_ERROR) == 0) {
|
||||||
|
String withWarnings;
|
||||||
|
|
||||||
|
// Any warnings?
|
||||||
|
if ((resultType & ImportResult.RESULT_WITH_WARNINGS) > 0) {
|
||||||
|
duration = 0;
|
||||||
|
color = Style.ORANGE;
|
||||||
|
withWarnings = activity.getResources().getString(R.string.import_with_warnings);
|
||||||
|
} else {
|
||||||
|
duration = SuperToast.Duration.LONG;
|
||||||
|
color = Style.GREEN;
|
||||||
|
withWarnings = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// New and updated keys
|
||||||
|
if (this.isOkBoth()) {
|
||||||
|
str = activity.getResources().getQuantityString(
|
||||||
|
R.plurals.import_keys_added_and_updated_1, mNewKeys, mNewKeys);
|
||||||
|
str += activity.getResources().getQuantityString(
|
||||||
|
R.plurals.import_keys_added_and_updated_2, mUpdatedKeys, mUpdatedKeys, withWarnings);
|
||||||
|
} else if (isOkUpdated()) {
|
||||||
|
str = activity.getResources().getQuantityString(
|
||||||
|
R.plurals.import_keys_updated, mUpdatedKeys, mUpdatedKeys, withWarnings);
|
||||||
|
} else if (isOkNew()) {
|
||||||
|
str = activity.getResources().getQuantityString(
|
||||||
|
R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings);
|
||||||
|
} else {
|
||||||
|
duration = 0;
|
||||||
|
color = Style.RED;
|
||||||
|
str = "internal error";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
duration = 0;
|
||||||
|
color = Style.RED;
|
||||||
|
if (isFailNothing()) {
|
||||||
|
str = activity.getString(R.string.import_error_nothing);
|
||||||
|
} else {
|
||||||
|
str = activity.getString(R.string.import_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.import_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, ImportResult.this);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
toast.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SaveKeyringResult extends OperationResultParcel {
|
public static class SaveKeyringResult extends OperationResultParcel {
|
||||||
|
@ -65,6 +65,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
+ "IMPORT_KEY_FROM_QR_CODE";
|
+ "IMPORT_KEY_FROM_QR_CODE";
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = Constants.INTENT_PREFIX
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = Constants.INTENT_PREFIX
|
||||||
+ "IMPORT_KEY_FROM_KEYSERVER";
|
+ "IMPORT_KEY_FROM_KEYSERVER";
|
||||||
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT =
|
||||||
|
Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN_RESULT";
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN = Constants.INTENT_PREFIX
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN = Constants.INTENT_PREFIX
|
||||||
+ "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN";
|
+ "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN";
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX
|
public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX
|
||||||
@ -78,6 +80,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
public static final String ACTION_IMPORT_KEY_FROM_NFC = Constants.INTENT_PREFIX
|
public static final String ACTION_IMPORT_KEY_FROM_NFC = Constants.INTENT_PREFIX
|
||||||
+ "IMPORT_KEY_FROM_NFC";
|
+ "IMPORT_KEY_FROM_NFC";
|
||||||
|
|
||||||
|
public static final String EXTRA_RESULT = "result";
|
||||||
|
|
||||||
// only used by ACTION_IMPORT_KEY
|
// only used by ACTION_IMPORT_KEY
|
||||||
public static final String EXTRA_KEY_BYTES = "key_bytes";
|
public static final String EXTRA_KEY_BYTES = "key_bytes";
|
||||||
|
|
||||||
@ -168,7 +172,8 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
startListFragment(savedInstanceState, importData, null, null);
|
startListFragment(savedInstanceState, importData, null, null);
|
||||||
}
|
}
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)
|
} else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)
|
||||||
|| ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(action)) {
|
|| ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(action)
|
||||||
|
|| ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(action)) {
|
||||||
|
|
||||||
// only used for OpenPgpService
|
// only used for OpenPgpService
|
||||||
if (extras.containsKey(EXTRA_PENDING_INTENT_DATA)) {
|
if (extras.containsKey(EXTRA_PENDING_INTENT_DATA)) {
|
||||||
@ -436,92 +441,26 @@ public class ImportKeysActivity extends ActionBarActivity {
|
|||||||
if (result == null) {
|
if (result == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int resultType = result.getResult();
|
|
||||||
|
|
||||||
String str;
|
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())) {
|
||||||
int duration, color;
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra(EXTRA_RESULT, result);
|
||||||
// Not an overall failure
|
ImportKeysActivity.this.setResult(RESULT_OK, intent);
|
||||||
if ((resultType & ImportResult.RESULT_ERROR) == 0) {
|
ImportKeysActivity.this.finish();
|
||||||
String withWarnings;
|
return;
|
||||||
|
|
||||||
// Any warnings?
|
|
||||||
if ((resultType & ImportResult.RESULT_WITH_WARNINGS) > 0) {
|
|
||||||
duration = 0;
|
|
||||||
color = Style.ORANGE;
|
|
||||||
withWarnings = getResources().getString(R.string.import_with_warnings);
|
|
||||||
} else {
|
|
||||||
duration = SuperToast.Duration.LONG;
|
|
||||||
color = Style.GREEN;
|
|
||||||
withWarnings = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// New and updated keys
|
|
||||||
if (result.isOkBoth()) {
|
|
||||||
str = getResources().getQuantityString(
|
|
||||||
R.plurals.import_keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
|
|
||||||
str += getResources().getQuantityString(
|
|
||||||
R.plurals.import_keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
|
|
||||||
} else if (result.isOkUpdated()) {
|
|
||||||
str = getResources().getQuantityString(
|
|
||||||
R.plurals.import_keys_updated, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
|
|
||||||
} else if (result.isOkNew()) {
|
|
||||||
str = getResources().getQuantityString(
|
|
||||||
R.plurals.import_keys_added, result.mNewKeys, result.mNewKeys, withWarnings);
|
|
||||||
} else {
|
|
||||||
duration = 0;
|
|
||||||
color = Style.RED;
|
|
||||||
str = "internal error";
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
duration = 0;
|
|
||||||
color = Style.RED;
|
|
||||||
if (result.isFailNothing()) {
|
|
||||||
str = getString(R.string.import_error_nothing);
|
|
||||||
} else {
|
|
||||||
str = getString(R.string.import_error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.setSwipeToDismiss(true);
|
|
||||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
|
||||||
getResources().getString(R.string.import_view_log));
|
|
||||||
toast.setButtonTextColor(getResources().getColor(R.color.black));
|
|
||||||
toast.setTextColor(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(
|
|
||||||
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())) {
|
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
|
||||||
ImportKeysActivity.this.setResult(RESULT_OK, mPendingIntentData);
|
ImportKeysActivity.this.setResult(RESULT_OK, mPendingIntentData);
|
||||||
ImportKeysActivity.this.finish();
|
ImportKeysActivity.this.finish();
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(getIntent().getAction())) {
|
return;
|
||||||
|
}
|
||||||
|
if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(getIntent().getAction())) {
|
||||||
ImportKeysActivity.this.setResult(RESULT_OK);
|
ImportKeysActivity.this.setResult(RESULT_OK);
|
||||||
ImportKeysActivity.this.finish();
|
ImportKeysActivity.this.finish();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.displayToast(ImportKeysActivity.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,6 +55,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
|
|||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer;
|
import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -331,7 +332,7 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
String fingerprint = PgpKeyHelper.convertFingerprintToHex(blob);
|
String fingerprint = PgpKeyHelper.convertFingerprintToHex(blob);
|
||||||
|
|
||||||
Intent queryIntent = new Intent(this, ImportKeysActivity.class);
|
Intent queryIntent = new Intent(this, ImportKeysActivity.class);
|
||||||
queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN);
|
queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT);
|
||||||
queryIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint);
|
queryIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint);
|
||||||
|
|
||||||
startActivityForResult(queryIntent, REQUEST_CODE_LOOKUP_KEY);
|
startActivityForResult(queryIntent, REQUEST_CODE_LOOKUP_KEY);
|
||||||
@ -355,7 +356,10 @@ public class ViewKeyActivity extends ActionBarActivity implements
|
|||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_CODE_LOOKUP_KEY: {
|
case REQUEST_CODE_LOOKUP_KEY: {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
// TODO: reload key??? move this into fragment?
|
ImportResult result = data.getParcelableExtra(ImportKeysActivity.EXTRA_RESULT);
|
||||||
|
if (result != null) {
|
||||||
|
result.displayToast(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/card_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user