diff --git a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java index 8b881c25e..018740cc7 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java @@ -32,6 +32,7 @@ import org.openobservatory.ooniprobe.item.*; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; +import org.openobservatory.ooniprobe.model.database.ResultExtensions; import org.openobservatory.ooniprobe.model.database.Result_Table; import org.openobservatory.ooniprobe.test.suite.*; @@ -162,9 +163,11 @@ void queryList() { for (DatedResults group : list) { items.add(new DateItem(group.getGroupedDate())); for (Result result : group.getResultsList()) { - if (result.countTotalMeasurements() == 0) + if (ResultExtensions.getStatus(result) == -1){ + items.add(new ProgressItem(result, this, this)); + } else if (result.countTotalMeasurements() == 0) { items.add(new FailedItem(result, this, this)); - else { + } else { switch (result.test_group_name) { case WebsitesSuite.NAME: items.add(new WebsiteItem(result, this, this)); diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java index 4566b4341..5741d7f61 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java @@ -12,9 +12,7 @@ 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; @@ -41,24 +39,13 @@ 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)); } - class ViewHolder extends RecyclerView.ViewHolder { + public class ViewHolder extends RecyclerView.ViewHolder { ItemFailedBinding binding; ViewHolder(ItemFailedBinding binding) { diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/ProgressItem.kt b/app/src/main/java/org/openobservatory/ooniprobe/item/ProgressItem.kt new file mode 100644 index 000000000..822269dd4 --- /dev/null +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/ProgressItem.kt @@ -0,0 +1,18 @@ +package org.openobservatory.ooniprobe.item + +import android.view.View +import org.openobservatory.ooniprobe.R +import org.openobservatory.ooniprobe.model.database.Result + +class ProgressItem( + result: Result, + onClickListener: View.OnClickListener, + onLongClickListener: View.OnLongClickListener +) : FailedItem(result, onClickListener, onLongClickListener) { + override fun onBindViewHolder(viewHolder: ViewHolder) { + super.onBindViewHolder(viewHolder) + viewHolder.binding.subtitle.text = viewHolder.itemView.context + .getString(R.string.Dashboard_Running_Running) + .replace(":", ""); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openobservatory/ooniprobe/model/database/ResultExtensions.kt b/app/src/main/java/org/openobservatory/ooniprobe/model/database/ResultExtensions.kt new file mode 100644 index 000000000..044d0aa0c --- /dev/null +++ b/app/src/main/java/org/openobservatory/ooniprobe/model/database/ResultExtensions.kt @@ -0,0 +1,44 @@ +package org.openobservatory.ooniprobe.model.database + +import com.raizlabs.android.dbflow.config.FlowManager +import com.raizlabs.android.dbflow.structure.database.FlowCursor +import org.openobservatory.ooniprobe.common.AppDatabase + + +class ResultExtensions { + + companion object { + + @JvmStatic + fun Result.getStatus(): Int { + val queryById = """ + SELECT + CASE + WHEN COUNT(m.result_id) = 0 THEN -1 + ELSE SUM(CASE WHEN m.is_done = 0 THEN 1 ELSE 0 END) + END AS in_progress_count + FROM + Result r + LEFT JOIN + Measurement m ON r.id = m.result_id + WHERE + r.id = ? + """.trimIndent() + val cursor: FlowCursor = FlowManager.getDatabase(AppDatabase::class.java) + .writableDatabase + .rawQuery(queryById, arrayOf(id.toString())) + + var inProgressCount = 0 + if (cursor.moveToFirst()) { + cursor.getColumnIndex("in_progress_count").let { + if (it == -1) { + return@let + } + inProgressCount = cursor.getInt(it) + } + } + cursor.close() + return inProgressCount + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openobservatory/ooniprobe/test/TestAsyncTask.java b/app/src/main/java/org/openobservatory/ooniprobe/test/TestAsyncTask.java index 826f41a77..f46934283 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/test/TestAsyncTask.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/test/TestAsyncTask.java @@ -151,6 +151,10 @@ private void runTest(AbstractTest... tests) { currentTest.run(app, app.getPreferenceManager(),app.getLogger(), app.getGson(), result, i, this); } } + if (result.countTotalMeasurements() == tests.length) { + result.is_done = true; + result.save(); + } } catch (Exception e) { publishProgress(ERR, app.getString(R.string.Modal_Error_CantDownloadURLs)); e.printStackTrace();