small fix and some cleanup in ServiceProgressFragment

This commit is contained in:
Vincent Breitmoser 2015-06-22 23:08:03 +02:00
parent 1590d8f538
commit 8d1dc940c4

View File

@ -98,24 +98,15 @@ public class ServiceProgressHandler extends Handler {
public void handleMessage(Message message) {
Bundle data = message.getData();
ProgressDialogFragment progressDialogFragment =
(ProgressDialogFragment) mActivity.getSupportFragmentManager()
.findFragmentByTag("progressDialog");
if (progressDialogFragment == null) {
Log.e(Constants.TAG, "Progress has not been updated because mProgressDialogFragment was null!");
return;
}
MessageStatus status = MessageStatus.fromInt(message.arg1);
switch (status) {
case OKAY:
progressDialogFragment.dismissAllowingStateLoss();
dismissAllowingStateLoss();
break;
case EXCEPTION:
progressDialogFragment.dismissAllowingStateLoss();
dismissAllowingStateLoss();
// show error from service
if (data.containsKey(DATA_ERROR)) {
@ -147,7 +138,7 @@ public class ServiceProgressHandler extends Handler {
break;
case PREVENT_CANCEL:
progressDialogFragment.setPreventCancel(true);
setPreventCancel(true);
break;
default:
@ -156,12 +147,41 @@ public class ServiceProgressHandler extends Handler {
}
}
private void setPreventCancel(boolean preventCancel) {
ProgressDialogFragment progressDialogFragment =
(ProgressDialogFragment) mActivity.getSupportFragmentManager()
.findFragmentByTag("progressDialog");
if (progressDialogFragment == null) {
return;
}
progressDialogFragment.setPreventCancel(preventCancel);
}
protected void dismissAllowingStateLoss() {
ProgressDialogFragment progressDialogFragment =
(ProgressDialogFragment) mActivity.getSupportFragmentManager()
.findFragmentByTag("progressDialog");
if (progressDialogFragment == null) {
return;
}
progressDialogFragment.dismissAllowingStateLoss();
}
protected void onSetProgress(String msg, int progress, int max) {
ProgressDialogFragment progressDialogFragment =
(ProgressDialogFragment) mActivity.getSupportFragmentManager()
.findFragmentByTag("progressDialog");
if (progressDialogFragment == null) {
return;
}
if (msg != null) {
progressDialogFragment.setProgress(msg, progress, max);
} else {