aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java
diff options
context:
space:
mode:
authorAdithya Abraham Philip <adithyaphilip@gmail.com>2015-03-22 03:31:13 +0530
committerAdithya Abraham Philip <adithyaphilip@gmail.com>2015-03-23 15:37:05 +0530
commit9f5581463f1b2d07217f59fa32346c786069dbf5 (patch)
tree3f3e8688dce87ba5253a9efe600f39456dbecc77 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java
parent19775c399b106149e8906a7482a4b5a4af2ac8fa (diff)
downloadopen-keychain-9f5581463f1b2d07217f59fa32346c786069dbf5.tar.gz
open-keychain-9f5581463f1b2d07217f59fa32346c786069dbf5.tar.bz2
open-keychain-9f5581463f1b2d07217f59fa32346c786069dbf5.zip
shifted multi-threading to own service
added multi-threaded cloud import, restored KeychainIntentService eliminated code duplication in multi-threaded import
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java44
1 files changed, 39 insertions, 5 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java
index df7943f55..b58f584c8 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java
@@ -32,23 +32,43 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
+import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.service.CloudImportService;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
+import org.sufficientlysecure.keychain.util.Log;
public class ProgressDialogFragment extends DialogFragment {
private static final String ARG_MESSAGE = "message";
private static final String ARG_STYLE = "style";
private static final String ARG_CANCELABLE = "cancelable";
+ private static final String ARG_SERVICE_TYPE = "service_class";
+
+ public static enum ServiceType {
+ KEYCHAIN_INTENT,
+ CLOUD_IMPORT
+ }
+
+ ServiceType mServiceType;
boolean mCanCancel = false, mPreventCancel = false, mIsCancelled = false;
- /** Creates new instance of this fragment */
- public static ProgressDialogFragment newInstance(String message, int style, boolean cancelable) {
+ /**
+ * creates a new instance of this fragment
+ * @param message the message to be displayed initially above the progress bar
+ * @param style the progress bar style, as defined in ProgressDialog (horizontal or spinner)
+ * @param cancelable should we let the user cancel this operation
+ * @param serviceType which Service this progress dialog is meant for
+ * @return
+ */
+ public static ProgressDialogFragment newInstance(String message, int style, boolean cancelable,
+ ServiceType serviceType) {
ProgressDialogFragment frag = new ProgressDialogFragment();
Bundle args = new Bundle();
args.putString(ARG_MESSAGE, message);
args.putInt(ARG_STYLE, style);
args.putBoolean(ARG_CANCELABLE, cancelable);
+ args.putSerializable(ARG_SERVICE_TYPE, serviceType);
frag.setArguments(args);
@@ -106,6 +126,7 @@ public class ProgressDialogFragment extends DialogFragment {
String message = getArguments().getString(ARG_MESSAGE);
int style = getArguments().getInt(ARG_STYLE);
mCanCancel = getArguments().getBoolean(ARG_CANCELABLE);
+ mServiceType = (ServiceType) getArguments().getSerializable(ARG_SERVICE_TYPE);
dialog.setMessage(message);
dialog.setProgressStyle(style);
@@ -175,9 +196,22 @@ public class ProgressDialogFragment extends DialogFragment {
// send a cancel message. note that this message will be handled by
// KeychainIntentService.onStartCommand, which runs in this thread,
// not the service one, and will not queue up a command.
- Intent intent = new Intent(getActivity(), KeychainIntentService.class);
- intent.setAction(KeychainIntentService.ACTION_CANCEL);
- getActivity().startService(intent);
+ Intent serviceIntent = null;
+
+ switch (mServiceType) {
+ case CLOUD_IMPORT:
+ serviceIntent = new Intent(getActivity(), CloudImportService.class);
+ break;
+ case KEYCHAIN_INTENT:
+ serviceIntent = new Intent(getActivity(), KeychainIntentService.class);
+ break;
+ default:
+ //should never happen, unless we forget to include a ServiceType enum case
+ Log.e(Constants.TAG, "Unrecognized ServiceType at ProgressDialogFragment");
+ }
+
+ serviceIntent.setAction(KeychainIntentService.ACTION_CANCEL);
+ getActivity().startService(serviceIntent);
}
});