Selaa lähdekoodia

Progress modifiers don't need to be posted to the UI thread, progress bar does that automatically. Removed thrown exception for not being on the UI thread too.

Aidan Follestad 10 vuotta sitten
vanhempi
commit
12b8f1d9ca

+ 5 - 16
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -1314,26 +1314,17 @@ public class MaterialDialog extends DialogBase implements
     }
 
     public final void incrementProgress(final int by) {
-        if (mBuilder.progress <= -2)
-            throw new IllegalStateException("Cannot use incrementProgress() on this dialog.");
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                setProgress(getCurrentProgress() + by);
-            }
-        });
+        setProgress(getCurrentProgress() + by);
     }
 
     public final void setProgress(final int progress) {
-        if (Looper.myLooper() != Looper.getMainLooper())
-            throw new IllegalStateException("You can only set the dialog's progress from the UI thread.");
-        else if (mBuilder.progress <= -2)
+        if (mBuilder.progress <= -2)
             throw new IllegalStateException("Cannot use setProgress() on this dialog.");
+        mProgress.setProgress(progress);
         mHandler.post(new Runnable() {
             @Override
             public void run() {
-                mProgress.setProgress(progress);
-                int percentage = (int) (((float) getCurrentProgress() / (float) getMaxProgress()) * 100f);
+                final int percentage = (int) (((float) getCurrentProgress() / (float) getMaxProgress()) * 100f);
                 mProgressLabel.setText(percentage + "%");
                 if (mProgressMinMax != null)
                     mProgressMinMax.setText(getCurrentProgress() + "/" + getMaxProgress());
@@ -1342,9 +1333,7 @@ public class MaterialDialog extends DialogBase implements
     }
 
     public final void setMaxProgress(final int max) {
-        if (Looper.myLooper() != Looper.getMainLooper())
-            throw new IllegalStateException("You can only set the dialog's progress from the UI thread.");
-        else if (mBuilder.progress <= -2)
+        if (mBuilder.progress <= -2)
             throw new IllegalStateException("Cannot use setMaxProgress() on this dialog.");
         mHandler.post(new Runnable() {
             @Override