mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 04:22:18 -05:00
Merge branch 'development' of github.com:open-keychain/open-keychain into development
This commit is contained in:
commit
7e5cc9ee70
@ -74,6 +74,8 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
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.service.KeychainIntentServiceHandler.MessageStatus;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler.MessageStatus;
|
||||||
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||||
@ -310,31 +312,31 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.menu_key_view_export_file: {
|
case R.id.menu_key_view_export_file: {
|
||||||
Intent mIntent = new Intent(this,PassphraseDialogActivity.class);
|
|
||||||
long keyId=0;
|
|
||||||
try {
|
try {
|
||||||
keyId = new ProviderHelper(this)
|
if (PassphraseCacheService.getCachedPassphrase(this, mMasterKeyId, mMasterKeyId) != null) {
|
||||||
.getCachedPublicKeyRing(mDataUri)
|
exportToFile(mDataUri, mExportHelper, mProviderHelper);
|
||||||
.extractOrGetMasterKeyId();
|
return true;
|
||||||
} catch (PgpKeyNotFoundException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
|
startPassphraseActivity(REQUEST_EXPORT);
|
||||||
|
} catch (PassphraseCacheService.KeyNotFoundException e) {
|
||||||
|
// This happens when the master key is stripped
|
||||||
|
exportToFile(mDataUri, mExportHelper, mProviderHelper);
|
||||||
}
|
}
|
||||||
mIntent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID,keyId);
|
|
||||||
startActivityForResult(mIntent,REQUEST_EXPORT);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.menu_key_view_delete: {
|
case R.id.menu_key_view_delete: {
|
||||||
Intent mIntent = new Intent(this,PassphraseDialogActivity.class);
|
|
||||||
long keyId=0;
|
|
||||||
try {
|
try {
|
||||||
keyId = new ProviderHelper(this)
|
if (PassphraseCacheService.getCachedPassphrase(this, mMasterKeyId, mMasterKeyId) != null) {
|
||||||
.getCachedPublicKeyRing(mDataUri)
|
deleteKey();
|
||||||
.extractOrGetMasterKeyId();
|
return true;
|
||||||
} catch (PgpKeyNotFoundException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
|
startPassphraseActivity(REQUEST_DELETE);
|
||||||
|
} catch (PassphraseCacheService.KeyNotFoundException e) {
|
||||||
|
// This happens when the master key is stripped
|
||||||
|
deleteKey();
|
||||||
}
|
}
|
||||||
mIntent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID,keyId);
|
|
||||||
startActivityForResult(mIntent,REQUEST_DELETE);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.menu_key_view_advanced: {
|
case R.id.menu_key_view_advanced: {
|
||||||
@ -473,8 +475,14 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
ActivityCompat.startActivity(this, qrCodeIntent, opts);
|
ActivityCompat.startActivity(this, qrCodeIntent, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportToFile(Uri dataUri, ExportHelper exportHelper, ProviderHelper providerHelper)
|
private void startPassphraseActivity(int requestCode) {
|
||||||
throws ProviderHelper.NotFoundException {
|
Intent intent = new Intent(this, PassphraseDialogActivity.class);
|
||||||
|
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mMasterKeyId);
|
||||||
|
startActivityForResult(intent, requestCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exportToFile(Uri dataUri, ExportHelper exportHelper, ProviderHelper providerHelper) {
|
||||||
|
try {
|
||||||
Uri baseUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri);
|
Uri baseUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri);
|
||||||
|
|
||||||
HashMap<String, Object> data = providerHelper.getGenericData(
|
HashMap<String, Object> data = providerHelper.getGenericData(
|
||||||
@ -486,9 +494,13 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
new long[]{(Long) data.get(KeychainContract.KeyRings.MASTER_KEY_ID)},
|
new long[]{(Long) data.get(KeychainContract.KeyRings.MASTER_KEY_ID)},
|
||||||
Constants.Path.APP_DIR_FILE, ((Long) data.get(KeychainContract.KeyRings.HAS_SECRET) != 0)
|
Constants.Path.APP_DIR_FILE, ((Long) data.get(KeychainContract.KeyRings.HAS_SECRET) != 0)
|
||||||
);
|
);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Notify.showNotify(this, R.string.error_key_not_found, Notify.Style.ERROR);
|
||||||
|
Log.e(Constants.TAG, "Key not found", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteKey(Uri dataUri, ExportHelper exportHelper) {
|
private void deleteKey() {
|
||||||
// Message is received after key is deleted
|
// Message is received after key is deleted
|
||||||
Handler returnHandler = new Handler() {
|
Handler returnHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
@ -500,7 +512,11 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exportHelper.deleteKey(dataUri, returnHandler);
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(returnHandler);
|
||||||
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
||||||
|
new long[]{ mMasterKeyId });
|
||||||
|
deleteKeyDialog.show(getSupportFragmentManager(), "deleteKeyDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -531,17 +547,12 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requestCode == REQUEST_DELETE && resultCode == Activity.RESULT_OK){
|
if (requestCode == REQUEST_DELETE && resultCode == Activity.RESULT_OK){
|
||||||
deleteKey(mDataUri, mExportHelper);
|
deleteKey();
|
||||||
}
|
|
||||||
if (requestCode == REQUEST_EXPORT && resultCode == Activity.RESULT_OK){
|
|
||||||
try {
|
|
||||||
exportToFile(mDataUri, mExportHelper, mProviderHelper);
|
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
|
||||||
Notify.showNotify(this, R.string.error_key_not_found, Notify.Style.ERROR);
|
|
||||||
Log.e(Constants.TAG, "Key not found", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (requestCode == REQUEST_EXPORT && resultCode == Activity.RESULT_OK){
|
||||||
|
exportToFile(mDataUri, mExportHelper, mProviderHelper);
|
||||||
|
}
|
||||||
|
|
||||||
if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) {
|
if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) {
|
||||||
OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
|
OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
|
||||||
|
@ -19,6 +19,11 @@ package org.sufficientlysecure.keychain.ui.util;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.nispok.snackbar.Snackbar;
|
import com.nispok.snackbar.Snackbar;
|
||||||
import com.nispok.snackbar.Snackbar.SnackbarDuration;
|
import com.nispok.snackbar.Snackbar.SnackbarDuration;
|
||||||
@ -61,11 +66,11 @@ public class Notify {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SnackbarManager.show(bar);
|
showSnackbar(activity, bar);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Showable createNotify (Activity activity, int resId, int duration, Style style) {
|
public static Showable createNotify (final Activity activity, int resId, int duration, Style style) {
|
||||||
final Snackbar bar = getSnackbar(activity)
|
final Snackbar bar = getSnackbar(activity)
|
||||||
.text(resId);
|
.text(resId);
|
||||||
|
|
||||||
@ -90,7 +95,7 @@ public class Notify {
|
|||||||
return new Showable () {
|
return new Showable () {
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
SnackbarManager.show(bar);
|
showSnackbar(activity, bar);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -104,7 +109,7 @@ public class Notify {
|
|||||||
return createNotify(activity, msg, duration, style, null, 0);
|
return createNotify(activity, msg, duration, style, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Showable createNotify(Activity activity, String msg, int duration, Style style,
|
public static Showable createNotify(final Activity activity, String msg, int duration, Style style,
|
||||||
final ActionListener listener, int resIdAction) {
|
final ActionListener listener, int resIdAction) {
|
||||||
|
|
||||||
final Snackbar bar = getSnackbar(activity)
|
final Snackbar bar = getSnackbar(activity)
|
||||||
@ -141,7 +146,7 @@ public class Notify {
|
|||||||
return new Showable () {
|
return new Showable () {
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
SnackbarManager.show(bar);
|
showSnackbar(activity, bar);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -178,6 +183,26 @@ public class Notify {
|
|||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void showSnackbar(Activity activity, Snackbar snackbar) {
|
||||||
|
if (activity instanceof FragmentActivity) {
|
||||||
|
FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager();
|
||||||
|
|
||||||
|
int count = fragmentManager.getBackStackEntryCount();
|
||||||
|
Fragment fragment = fragmentManager.getFragments().get(count > 0 ? count - 1 : 0);
|
||||||
|
|
||||||
|
if (fragment != null) {
|
||||||
|
View view = fragment.getView();
|
||||||
|
|
||||||
|
if (view != null) {
|
||||||
|
SnackbarManager.show(snackbar, (ViewGroup) view);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SnackbarManager.show(snackbar);
|
||||||
|
}
|
||||||
|
|
||||||
public interface Showable {
|
public interface Showable {
|
||||||
public void show();
|
public void show();
|
||||||
|
|
||||||
|
@ -47,21 +47,6 @@ public class ExportHelper {
|
|||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteKey(Uri dataUri, Handler deleteHandler) {
|
|
||||||
try {
|
|
||||||
long masterKeyId = new ProviderHelper(mActivity).getCachedPublicKeyRing(dataUri)
|
|
||||||
.extractOrGetMasterKeyId();
|
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
|
||||||
Messenger messenger = new Messenger(deleteHandler);
|
|
||||||
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
|
||||||
new long[]{ masterKeyId });
|
|
||||||
deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
|
|
||||||
} catch (PgpKeyNotFoundException e) {
|
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show dialog where to export keys
|
* Show dialog where to export keys
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user