@@ -34,7 +34,8 @@ public class ProgressDialogFragment extends BaseDialogFragment implements Progre
34
34
35
35
private String repoName = null ;
36
36
private boolean taskCancelled = false ;
37
- private int totalTasks = 6 ;
37
+ @ SuppressWarnings ("FieldCanBeLocal" )
38
+ private final int totalTasks = 6 ;
38
39
private int currentTask = 0 ;
39
40
private int totalWork = 0 ;
40
41
private int currentWork = 0 ;
@@ -81,17 +82,15 @@ public void beginTask(String title, int totalWork) {
81
82
/** ProgressMonitor: Denote that some work units have been completed. */
82
83
@ Override
83
84
public void update (int completed ) {
84
- this .currentWork += completed ;
85
-
86
- String message = this .currentWork + " / " + this .totalWork ;
87
85
String percentage ;
88
- // if (mDebug) {Log.d(LOG_TAG, "items complete: " + message);}
86
+ this . currentWork += completed ;
89
87
if (this .totalWork == 0 ) {
90
88
percentage = "0.00%" ;
91
89
} else {
92
- percentage = String .format (Locale .ROOT ,"%.02f" , (float ) ( this .currentWork / this .totalWork * 100 ) ) + "%" ;
90
+ percentage = String .format (Locale .ROOT ,"%.02f" , (( float ) this .currentWork / ( float ) this .totalWork ) * 100 ) + "%" ;
93
91
}
94
92
93
+ String message = this .currentWork + " / " + this .totalWork ;
95
94
requireActivity ().runOnUiThread (() -> {
96
95
this .mDataBinding .progressIndicator .setProgress (this .currentWork );
97
96
this .mDataBinding .textTaskStatus .setText (message );
@@ -103,11 +102,14 @@ public void update(int completed) {
103
102
@ Override
104
103
public void endTask () {
105
104
if (mDebug ) {Log .d (LOG_TAG , "endTask " + this .currentTask + " / " + this .totalTasks );}
106
- // if (this.currentTask == this.totalTasks) {this.dismiss();} // TODO: comparison doesn't work.
107
-
108
- /* Reset the progress indicator */
109
- requireActivity ().runOnUiThread (() ->
110
- this .mDataBinding .progressIndicator .setProgress (0 ));
105
+ if (this .currentTask != this .totalTasks ) {
106
+ /* Reset the progress indicator. */
107
+ requireActivity ().runOnUiThread (() ->
108
+ this .mDataBinding .progressIndicator .setProgress (0 ));
109
+ } else {
110
+ /* Dismiss dialog. */
111
+ this .dismiss ();
112
+ }
111
113
}
112
114
113
115
/** Interface: ProgressMonitor. Check for user task cancellation. */
0 commit comments