Skip to content

Commit a358731

Browse files
authored
converted time remaininng to human readable format (#574)
1 parent 890e68e commit a358731

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/src/main/java/org/openobservatory/ooniprobe/activity/RunningActivity.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.openobservatory.ooniprobe.activity;
22

3+
import static java.util.Locale.ENGLISH;
4+
35
import android.app.AlertDialog;
46
import android.app.NotificationManager;
57
import android.content.Context;
@@ -17,6 +19,7 @@
1719
import android.widget.TextView;
1820
import android.widget.Toast;
1921

22+
import androidx.annotation.NonNull;
2023
import androidx.annotation.Nullable;
2124
import androidx.core.content.ContextCompat;
2225
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@@ -143,8 +146,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
143146
});
144147
testProgressRepository.getEta().observe(this,etaValue -> {
145148
if (etaValue!=null) {
146-
eta.setText(getString(R.string.Dashboard_Running_Seconds,
147-
String.valueOf(Math.round(etaValue))));
149+
eta.setText(readableTimeRemaining(etaValue));
148150
}
149151
});
150152

@@ -186,8 +188,7 @@ private void applyUIChanges(RunTestService service) {
186188

187189
Double etaValue = testProgressRepository.getEta().getValue();
188190
if (etaValue!=null){
189-
eta.setText(getString(R.string.Dashboard_Running_Seconds,
190-
String.valueOf(Math.round(etaValue))));
191+
eta.setText(readableTimeRemaining(etaValue));
191192
}else {
192193
eta.setText(R.string.Dashboard_Running_CalculatingETA);
193194
}
@@ -270,8 +271,8 @@ public void onRun(String value) {
270271
public void onProgress(int state, double timeLeft) {
271272
progress.setIndeterminate(false);
272273
progress.setProgress(state);
273-
eta.setText(getString(R.string.Dashboard_Running_Seconds,
274-
String.valueOf(Math.round(timeLeft))));
274+
275+
eta.setText(readableTimeRemaining(timeLeft));
275276
}
276277

277278
@Override
@@ -300,4 +301,10 @@ public void onEnd(Context context) {
300301
testEnded(context);
301302
}
302303
}
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+
}
303310
}

app/src/main/java/org/openobservatory/ooniprobe/receiver/TestRunBroadRequestReceiver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void onReceive(Context context, Intent intent) {
5858
break;
5959
case TestAsyncTask.PRG:
6060
try {
61-
if (service != null && service.task.testSuites.indexOf(service.task.currentSuite) > 0) {
61+
if (service != null && service.task.testSuites.contains(service.task.currentSuite)) {
6262
List<AbstractSuite> previousTestSuites =
6363
service.task.testSuites.subList(0, service.task.testSuites.indexOf(service.task.currentSuite));
6464
int previousTestProgress = ListUtility.sum(Lists.transform(

0 commit comments

Comments
 (0)