Skip to content

Commit

Permalink
Fix: Update rules for displaying an error message when test starts (#614
Browse files Browse the repository at this point in the history
)

Fixes ooni/probe#2468

## Proposed Changes

- Only display an error message if the `start_time` of the test is more
than 5 minutes ago.


![Screenshot_20230904_090258](https://github.com/ooni/probe-android/assets/17911892/57af92a1-464c-4a89-8fc4-c899ee11a62c)
  • Loading branch information
aanorbel authored Oct 18, 2023
1 parent bccb236 commit 1457054
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.openobservatory.ooniprobe.databinding.ItemFailedBinding;
import org.openobservatory.ooniprobe.model.database.Result;

import java.util.Date;
import java.util.Locale;
import static java.util.concurrent.TimeUnit.*;

import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;

Expand All @@ -39,8 +41,19 @@ public FailedItem(Result extra, View.OnClickListener onClickListener, View.OnLon
viewHolder.binding.icon.setImageResource(extra.getTestSuite().getIcon());
viewHolder.binding.testName.setText(extra.getTestSuite().getTitle());
String failure_msg = viewHolder.itemView.getContext().getString(R.string.TestResults_Overview_Error);
if (extra.failure_msg != null)
if (extra.failure_msg != null) {
failure_msg += " - " + extra.failure_msg;
} else {
// NOTE: If the test is running for more than 5 minutes, we assume it's stuck or failed,
// and we show the default error message.
long MAX_DURATION = MILLISECONDS.convert(5, MINUTES);
long duration = new Date().getTime() - extra.start_time.getTime();
if (duration < MAX_DURATION) {
failure_msg = viewHolder.itemView.getContext()
.getString(R.string.Dashboard_Running_Running)
.replace(":","");
}
}
viewHolder.binding.subtitle.setText(failure_msg);
viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time));
}
Expand Down

0 comments on commit 1457054

Please sign in to comment.