Merge branch 'v/eventbus' into v/multi-decrypt

Conflicts:
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/CryptoOperationFragment.java
This commit is contained in:
Vincent Breitmoser
2015-06-10 17:12:22 +02:00
23 changed files with 274 additions and 259 deletions

View File

@@ -49,11 +49,7 @@ public class ConsolidateDialogActivity extends FragmentActivity {
private void consolidateRecovery(boolean recovery) {
// Message is received after importing is done in KeychainService
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
this,
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -94,7 +90,10 @@ public class ConsolidateDialogActivity extends FragmentActivity {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
saveHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL, false
);
// start service with intent
startService(intent);

View File

@@ -197,11 +197,7 @@ public class CreateKeyFinalFragment extends Fragment {
Intent intent = new Intent(getActivity(), KeychainService.class);
intent.setAction(KeychainService.ACTION_EDIT_KEYRING);
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_building_key),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -245,7 +241,8 @@ public class CreateKeyFinalFragment extends Fragment {
Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(getActivity());
saveHandler.showProgressDialog(getString(R.string.progress_building_key),
ProgressDialog.STYLE_HORIZONTAL, false);
getActivity().startService(intent);
}
@@ -271,11 +268,7 @@ public class CreateKeyFinalFragment extends Fragment {
intent.putExtra(KeychainService.EXTRA_DATA, data);
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_uploading),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -301,10 +294,13 @@ public class CreateKeyFinalFragment extends Fragment {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(getActivity());
saveHandler.showProgressDialog(
getString(R.string.progress_uploading),
ProgressDialog.STYLE_HORIZONTAL, false);
// start service with intent
getActivity().startService(intent);
}
}

View File

@@ -176,11 +176,7 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
public void importKey() {
// Message is received after decrypting is done in KeychainService
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -243,7 +239,10 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(getActivity());
saveHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL, false
);
// start service with intent
getActivity().startService(intent);

View File

@@ -30,7 +30,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import de.greenrobot.event.EventBus;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;

View File

@@ -263,7 +263,7 @@ public class ImportKeysActivity extends BaseNfcActivity {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
if (mListFragment != null) {
return;
}
@@ -283,7 +283,7 @@ public class ImportKeysActivity extends BaseNfcActivity {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
if (mTopFragment != null) {
return;
}
@@ -314,7 +314,7 @@ public class ImportKeysActivity extends BaseNfcActivity {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
if (mTopFragment != null) {
return;
}
@@ -388,12 +388,7 @@ public class ImportKeysActivity extends BaseNfcActivity {
return;
}
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
this,
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL,
true
) {
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -435,7 +430,11 @@ public class ImportKeysActivity extends BaseNfcActivity {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
serviceHandler.showProgressDialog(this);
serviceHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL,
true
);
// start service with intent
startService(intent);
@@ -469,7 +468,10 @@ public class ImportKeysActivity extends BaseNfcActivity {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
serviceHandler.showProgressDialog(this);
serviceHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL, true
);
// start service with intent
startService(intent);

View File

@@ -206,12 +206,7 @@ public class ImportKeysProxyActivity extends FragmentActivity {
private void startImportService(ArrayList<ParcelableKeyRing> keyRings) {
// Message is received after importing is done in KeychainService
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
this,
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL,
true
) {
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -273,7 +268,9 @@ public class ImportKeysProxyActivity extends FragmentActivity {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
serviceHandler.showProgressDialog(this);
serviceHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL, true);
// start service with intent
startService(intent);

View File

@@ -572,12 +572,7 @@ public class KeyListFragment extends LoaderFragment
keyList.add(keyEntry);
}
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_updating),
ProgressDialog.STYLE_HORIZONTAL,
true
) {
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -625,7 +620,9 @@ public class KeyListFragment extends LoaderFragment
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
serviceHandler.showProgressDialog(getActivity());
serviceHandler.showProgressDialog(
getString(R.string.progress_updating),
ProgressDialog.STYLE_HORIZONTAL, true);
// start service with intent
getActivity().startService(intent);
@@ -633,11 +630,7 @@ public class KeyListFragment extends LoaderFragment
private void consolidate() {
// Message is received after importing is done in KeychainService
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -675,7 +668,9 @@ public class KeyListFragment extends LoaderFragment
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(getActivity());
saveHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL, false);
// start service with intent
getActivity().startService(intent);

View File

@@ -23,6 +23,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;
@@ -42,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity;
import org.sufficientlysecure.keychain.util.FabContainer;
import org.sufficientlysecure.keychain.util.Preferences;
public class MainActivity extends BaseNfcActivity implements FabContainer {
public class MainActivity extends BaseNfcActivity implements FabContainer, OnBackStackChangedListener {
private static final int ID_KEYS = 1;
private static final int ID_ENCRYPT_DECRYPT = 2;
@@ -121,6 +122,8 @@ public class MainActivity extends BaseNfcActivity implements FabContainer {
return;
}
getSupportFragmentManager().addOnBackStackChangedListener(this);
Intent data = getIntent();
// If we got an EXTRA_RESULT in the intent, show the notification
if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) {
@@ -206,4 +209,25 @@ public class MainActivity extends BaseNfcActivity implements FabContainer {
}
@Override
public void onBackStackChanged() {
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager == null) {
return;
}
Fragment frag = fragmentManager.findFragmentById(R.id.main_fragment_container);
if (frag == null) {
return;
}
// make sure the selected icon is the one shown at this point
if (frag instanceof KeyListFragment) {
mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_KEYS), false);
} else if (frag instanceof EncryptDecryptOverviewFragment) {
mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_ENCRYPT_DECRYPT), false);
} else if (frag instanceof AppsListFragment) {
mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_APPS), false);
}
}
}

View File

@@ -124,12 +124,7 @@ public class SafeSlingerActivity extends BaseActivity {
final FragmentActivity activity = SafeSlingerActivity.this;
// Message is received after importing is done in KeychainService
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
activity,
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL,
true
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(activity) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -202,7 +197,10 @@ public class SafeSlingerActivity extends BaseActivity {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(activity);
saveHandler.showProgressDialog(
getString(R.string.progress_importing),
ProgressDialog.STYLE_HORIZONTAL, true
);
// start service with intent
activity.startService(intent);

View File

@@ -108,11 +108,7 @@ public class UploadKeyActivity extends BaseActivity {
intent.putExtra(KeychainService.EXTRA_DATA, data);
// Message is received after uploading is done in KeychainService
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
this,
getString(R.string.progress_uploading),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -132,7 +128,9 @@ public class UploadKeyActivity extends BaseActivity {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
saveHandler.showProgressDialog(
getString(R.string.progress_uploading),
ProgressDialog.STYLE_HORIZONTAL, false);
// start service with intent
startService(intent);

View File

@@ -698,9 +698,6 @@ public class ViewKeyActivity extends BaseNfcActivity implements
Messenger messenger = new Messenger(serviceHandler);
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
serviceHandler.showProgressDialog(this);
// start service with intent
startService(intent);

View File

@@ -360,12 +360,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
mProofVerifyDetail.setVisibility(View.GONE);
// Create a new Messenger for the communication back after proof work is done
//
ServiceProgressHandler handler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_verifying_signature),
ProgressDialog.STYLE_HORIZONTAL
) {
ServiceProgressHandler handler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
@@ -454,7 +449,10 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
handler.showProgressDialog(getActivity());
handler.showProgressDialog(
getString(R.string.progress_verifying_signature),
ProgressDialog.STYLE_HORIZONTAL, false
);
// start service with intent
getActivity().startService(intent);

View File

@@ -5,11 +5,13 @@ import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcelable;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.service.KeychainNewService;
import org.sufficientlysecure.keychain.service.KeychainService;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -55,6 +57,7 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
// Notify was created by createCryptoInput.
return;
}
}
// Send all information needed to service to edit key in other thread
@@ -63,12 +66,36 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
intent.putExtra(KeychainNewService.EXTRA_OPERATION_INPUT, mCachedActionsParcel);
intent.putExtra(KeychainNewService.EXTRA_CRYPTO_INPUT, cryptoInput);
showProgressFragment(
getString(R.string.progress_start),
ProgressDialog.STYLE_HORIZONTAL,
false);
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
// get returned data bundle
Bundle returnData = message.getData();
if (returnData == null) {
return;
}
final OperationResult result =
returnData.getParcelable(OperationResult.EXTRA_RESULT);
onHandleResult(result);
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(
getString(R.string.progress_building_key),
ProgressDialog.STYLE_HORIZONTAL, false);
// start service with intent
getActivity().startService(intent);
}

View File

@@ -21,16 +21,18 @@ package org.sufficientlysecure.keychain.ui.base;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import de.greenrobot.event.EventBus;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.service.KeychainNewService;
import org.sufficientlysecure.keychain.service.ProgressEvent;
import org.sufficientlysecure.keychain.service.KeychainService;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
@@ -47,18 +49,6 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
public static final int REQUEST_CODE_NFC = 0x00008002;
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}
private void initiateInputActivity(RequiredInputParcel requiredInput) {
switch (requiredInput.mType) {
@@ -130,22 +120,6 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
}
public void showProgressFragment(String progressDialogMessage,
int progressDialogStyle,
boolean cancelable) {
if (getFragmentManager().findFragmentByTag("progressDialog") != null) {
return;
}
ProgressDialogFragment progressDialogFragment = ProgressDialogFragment.newInstance(
progressDialogMessage, progressDialogStyle, cancelable);
FragmentManager manager = getFragmentManager();
progressDialogFragment.show(manager, "progressDialog");
}
protected abstract T createOperationInput();
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
@@ -161,12 +135,36 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
intent.putExtra(KeychainNewService.EXTRA_OPERATION_INPUT, operationInput);
intent.putExtra(KeychainNewService.EXTRA_CRYPTO_INPUT, cryptoInput);
showProgressFragment(
getString(R.string.progress_start),
ProgressDialog.STYLE_HORIZONTAL,
false);
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
// get returned data bundle
Bundle returnData = message.getData();
if (returnData == null) {
return;
}
final OperationResult result =
returnData.getParcelable(OperationResult.EXTRA_RESULT);
onHandleResult(result);
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(
getString(R.string.progress_building_key),
ProgressDialog.STYLE_HORIZONTAL, false);
// start service with intent
getActivity().startService(intent);
}
@@ -190,23 +188,9 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
}
protected void onCryptoOperationCancelled() {
dismissProgress();
}
protected void onCryptoSetProgress(String msg, int progress, int max) {
ProgressDialogFragment progressDialogFragment =
(ProgressDialogFragment) getFragmentManager().findFragmentByTag("progressDialog");
if (progressDialogFragment == null) {
return;
}
progressDialogFragment.setProgress(msg, progress, max);
}
@SuppressWarnings("unused") // it's an EventBus method
public void onEventMainThread(OperationResult result) {
public void onHandleResult(OperationResult result) {
if (result instanceof InputPendingResult) {
InputPendingResult pendingResult = (InputPendingResult) result;
@@ -229,9 +213,4 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
}
@SuppressWarnings("unused") // it's an EventBus method
public void onEventMainThread(ProgressEvent event) {
onCryptoSetProgress(event.mMessage, event.mProgress, event.mMax);
}
}

View File

@@ -135,12 +135,7 @@ public class DeleteKeyDialogFragment extends DialogFragment {
intent.setAction(KeychainService.ACTION_DELETE);
// Message is received after importing is done in KeychainService
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(),
getString(R.string.progress_deleting),
ProgressDialog.STYLE_HORIZONTAL,
true
) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
@Override
public void handleMessage(Message message) {
super.handleMessage(message);
@@ -168,7 +163,8 @@ public class DeleteKeyDialogFragment extends DialogFragment {
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(getActivity());
saveHandler.showProgressDialog(getString(R.string.progress_deleting),
ProgressDialog.STYLE_HORIZONTAL, true);
// start service with intent
getActivity().startService(intent);