|
1 | 1 | package org.openobservatory.ooniprobe.activity;
|
2 | 2 |
|
| 3 | +import static java.util.Locale.ENGLISH; |
| 4 | + |
3 | 5 | import android.app.AlertDialog;
|
4 | 6 | import android.app.NotificationManager;
|
5 | 7 | import android.content.Context;
|
|
17 | 19 | import android.widget.TextView;
|
18 | 20 | import android.widget.Toast;
|
19 | 21 |
|
| 22 | +import androidx.annotation.NonNull; |
20 | 23 | import androidx.annotation.Nullable;
|
21 | 24 | import androidx.core.content.ContextCompat;
|
22 | 25 | import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
@@ -143,8 +146,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
143 | 146 | });
|
144 | 147 | testProgressRepository.getEta().observe(this,etaValue -> {
|
145 | 148 | if (etaValue!=null) {
|
146 |
| - eta.setText(getString(R.string.Dashboard_Running_Seconds, |
147 |
| - String.valueOf(Math.round(etaValue)))); |
| 149 | + eta.setText(readableTimeRemaining(etaValue)); |
148 | 150 | }
|
149 | 151 | });
|
150 | 152 |
|
@@ -186,8 +188,7 @@ private void applyUIChanges(RunTestService service) {
|
186 | 188 |
|
187 | 189 | Double etaValue = testProgressRepository.getEta().getValue();
|
188 | 190 | if (etaValue!=null){
|
189 |
| - eta.setText(getString(R.string.Dashboard_Running_Seconds, |
190 |
| - String.valueOf(Math.round(etaValue)))); |
| 191 | + eta.setText(readableTimeRemaining(etaValue)); |
191 | 192 | }else {
|
192 | 193 | eta.setText(R.string.Dashboard_Running_CalculatingETA);
|
193 | 194 | }
|
@@ -270,8 +271,8 @@ public void onRun(String value) {
|
270 | 271 | public void onProgress(int state, double timeLeft) {
|
271 | 272 | progress.setIndeterminate(false);
|
272 | 273 | progress.setProgress(state);
|
273 |
| - eta.setText(getString(R.string.Dashboard_Running_Seconds, |
274 |
| - String.valueOf(Math.round(timeLeft)))); |
| 274 | + |
| 275 | + eta.setText(readableTimeRemaining(timeLeft)); |
275 | 276 | }
|
276 | 277 |
|
277 | 278 | @Override
|
@@ -300,4 +301,10 @@ public void onEnd(Context context) {
|
300 | 301 | testEnded(context);
|
301 | 302 | }
|
302 | 303 | }
|
| 304 | + |
| 305 | + @NonNull |
| 306 | + private static String readableTimeRemaining(double timeLeft) { |
| 307 | + long letaValue = Math.round(timeLeft); |
| 308 | + return String.format(ENGLISH,"%dm %02ds", letaValue/60, letaValue%60); |
| 309 | + } |
303 | 310 | }
|
0 commit comments