Skip to content

Commit

Permalink
Merge pull request #676 from ooni/fix/dashboard-progress-indicator
Browse files Browse the repository at this point in the history
fix: Updated `ProgressFragment` and its position on dashboard.
  • Loading branch information
aanorbel authored Feb 28, 2024
2 parents 0723c62 + 3e0238e commit 24f16bf
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public class Application extends android.app.Application {
ExecutorService executorService = Executors.newFixedThreadPool(4);

public AppComponent component;
@Inject AppLogger logger;
@Inject AppLogger logger;

@Inject
TestStateRepository testStateRepository;

@Override public void onCreate() {
super.onCreate();
Expand Down Expand Up @@ -116,6 +119,9 @@ public AppLogger getLogger() {
return logger;
}

public TestStateRepository getTestStateRepository() {
return testStateRepository;
}
public Gson getGson() {
return _gson;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.openobservatory.ooniprobe.common

import androidx.lifecycle.MutableLiveData
import javax.inject.Inject
import javax.inject.Singleton

/**
* This class is used to store the state of the test group.
* It is used to communicate the state of the test group between the [org.openobservatory.ooniprobe.test.TestAsyncTask] and any [androidx.lifecycle.Observer].
*
* Note: Ideally, this class should used to replace Broadcasts from [org.openobservatory.ooniprobe.test.TestAsyncTask]
* and "org.openobservatory.ooniprobe.activity.RunningActivity" broadcast events
*/
@Singleton
class TestStateRepository @Inject constructor() {
var testGroupStatus = MutableLiveData(TestGroupStatus.NOT_STARTED)
}

enum class TestGroupStatus { NOT_STARTED, RUNNING, FINISHED }
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import org.openobservatory.engine.BaseNettest
import org.openobservatory.ooniprobe.R
import org.openobservatory.ooniprobe.activity.AbstractActivity
import org.openobservatory.ooniprobe.activity.OverviewActivity
import org.openobservatory.ooniprobe.activity.RunningActivity
import org.openobservatory.ooniprobe.activity.runtests.RunTestsActivity
import org.openobservatory.ooniprobe.adapters.DashboardAdapter
import org.openobservatory.ooniprobe.common.Application
import org.openobservatory.ooniprobe.common.OONIDescriptor
import org.openobservatory.ooniprobe.common.PreferenceManager
import org.openobservatory.ooniprobe.common.ReachabilityManager
import org.openobservatory.ooniprobe.common.TestGroupStatus
import org.openobservatory.ooniprobe.common.TestStateRepository
import org.openobservatory.ooniprobe.common.ThirdPartyServices
import org.openobservatory.ooniprobe.databinding.FragmentDashboardBinding
import org.openobservatory.ooniprobe.fragment.dashboard.DashboardViewModel
import org.openobservatory.ooniprobe.model.database.Result
import org.openobservatory.ooniprobe.test.suite.AbstractSuite
import javax.inject.Inject

class DashboardFragment : Fragment(), View.OnClickListener {
Expand All @@ -34,6 +34,9 @@ class DashboardFragment : Fragment(), View.OnClickListener {
@Inject
lateinit var viewModel: DashboardViewModel

@Inject
lateinit var testStateRepository: TestStateRepository

private var descriptors: ArrayList<OONIDescriptor<BaseNettest>> = ArrayList()

private lateinit var binding: FragmentDashboardBinding
Expand Down Expand Up @@ -72,6 +75,16 @@ class DashboardFragment : Fragment(), View.OnClickListener {
addAll(items)
}
}

testStateRepository.testGroupStatus.observe(viewLifecycleOwner) { status ->
if (status == TestGroupStatus.RUNNING) {
binding.runAll.visibility = View.GONE
binding.lastTested.visibility = View.GONE
} else {
binding.runAll.visibility = View.VISIBLE
binding.lastTested.visibility = View.VISIBLE
}
}
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,20 @@ class ProgressFragment : Fragment() {

override fun onPause() {
super.onPause()
if (receiver.isBound) {
requireContext().unbindService(receiver)
receiver.isBound = false
if (::receiver.isInitialized) {
if (receiver.isBound) {
requireContext().unbindService(receiver)
receiver.isBound = false
}
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(receiver)
}
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(receiver)
}

override fun onDestroy() {
super.onDestroy()
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(receiver)
if (::receiver.isInitialized) {
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(receiver)
}
}

private inner class TestRunnerEventListener : TestRunBroadRequestReceiver.EventListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openobservatory.ooniprobe.common.ListUtility;
import org.openobservatory.ooniprobe.common.MKException;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.TestGroupStatus;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.common.service.RunTestService;
import org.openobservatory.ooniprobe.common.service.ServiceUtil;
Expand Down Expand Up @@ -107,6 +108,7 @@ private void unregisterConnChange() {

@Override
protected Void doInBackground(Void... voids) {
app.getTestStateRepository().getTestGroupStatus().postValue(TestGroupStatus.RUNNING);
if (app != null && testSuites != null) {
registerConnChange();
for (int suiteIdx = 0; suiteIdx < testSuites.size(); suiteIdx++) {
Expand All @@ -125,6 +127,7 @@ protected Void doInBackground(Void... voids) {
}
}
}
app.getTestStateRepository().getTestGroupStatus().postValue(TestGroupStatus.FINISHED);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/progress_blue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<solid android:color="#33ffffff"/>
<solid android:color="@color/color_gray9"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
android:layout_height="0dp"
android:layout_weight="1"/>

<fragment
android:name="org.openobservatory.ooniprobe.fragment.ProgressFragment"
android:id="@+id/progress_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/layout/activity_measurement_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,4 @@
android:padding="16dp" />
</LinearLayout>
</ScrollView>

<fragment
android:name="org.openobservatory.ooniprobe.fragment.ProgressFragment"
android:id="@+id/progress_fragment"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
8 changes: 0 additions & 8 deletions app/src/main/res/layout/activity_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,4 @@
app:layout_constraintTop_toBottomOf="@id/header" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/progress_fragment"
android:name="org.openobservatory.ooniprobe.fragment.ProgressFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_anchorGravity="bottom" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
7 changes: 0 additions & 7 deletions app/src/main/res/layout/activity_result_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,4 @@
android:id="@+id/snackbarAnchor"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:name="org.openobservatory.ooniprobe.fragment.ProgressFragment"
android:id="@+id/progress_fragment"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</androidx.coordinatorlayout.widget.CoordinatorLayout> <!-- app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" -->
73 changes: 44 additions & 29 deletions app/src/main/res/layout/fragment_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,53 @@

</com.github.florent37.shapeofview.shapes.ArcView>

<Button
android:id="@+id/run_all"
android:textAppearance="?attr/textAppearanceHeadline6"
android:layout_width="wrap_content"
android:layout_height="56dp"
<LinearLayout
android:id="@+id/idle_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:stateListAnimator="@null"
android:elevation="5dp"
android:translationZ="5dp"
android:text="@string/Dashboard_Card_Run"
android:textAllCaps="false"
android:transitionName="@string/transitionNameRun"
android:drawableEnd="@drawable/outline_timer"
android:drawableTint="@android:color/white"
android:paddingStart="14dp"
android:paddingEnd="14dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="@id/arc_view"
app:layout_constraintEnd_toEndOf="@id/arc_view"
app:layout_constraintStart_toStartOf="@id/arc_view"
app:layout_constraintBottom_toBottomOf="@id/arc_view"
app:cornerRadius="24dp"
app:rippleColor="@color/ripple_material_light" />
app:layout_constraintStart_toStartOf="@id/arc_view">

<TextView
android:id="@+id/last_tested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Dashboard_Overview_LatestTest"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/run_all"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="@color/color_black"/>
<Button
android:id="@+id/run_all"
android:textAppearance="?attr/textAppearanceHeadline6"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:stateListAnimator="@null"
android:elevation="5dp"
android:translationZ="5dp"
android:text="@string/Dashboard_Card_Run"
android:textAllCaps="false"
android:transitionName="@string/transitionNameRun"
android:drawableEnd="@drawable/outline_timer"
android:drawableTint="@android:color/white"
app:layout_constraintBottom_toBottomOf="@id/arc_view"
app:cornerRadius="24dp"
app:rippleColor="@color/ripple_material_light"
android:visibility="gone"/>

<TextView
android:id="@+id/last_tested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Dashboard_Overview_LatestTest"
android:textAppearance="?attr/textAppearanceCaption"
android:textColor="@color/color_black"
android:visibility="gone"/>

<fragment
android:name="org.openobservatory.ooniprobe.fragment.ProgressFragment"
android:id="@+id/progress_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"/>
</LinearLayout>

<RelativeLayout
android:id="@+id/vpnLayout"
Expand All @@ -85,8 +101,7 @@
android:layout_margin="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/last_tested">

app:layout_constraintTop_toBottomOf="@id/idle_layout">
<TextView
android:id="@+id/vpn"
app:drawableStartCompat="@android:drawable/ic_dialog_alert"
Expand Down
95 changes: 46 additions & 49 deletions app/src/main/res/layout/fragment_progress.xml
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/progress_background"
tools:context=".fragment.ProgressFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:minHeight="8dp"
android:maxHeight="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/progress_blue"
android:indeterminateTint="@color/color_base"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragment.ProgressFragment">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/test_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/OONIRun_TestName"
android:src="@null"
app:tint="@color/color_white"
android:visibility="gone"
tools:ignore="RtlSymmetry"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="8dp"
android:gravity="center_horizontal"
android:orientation="horizontal">

<TextView
android:id="@+id/name"
style="@style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/color_white"
android:text="@string/Dashboard_Running_PreparingTest"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/test_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/OONIRun_TestName"
android:src="@null"
android:visibility="gone"
app:tint="@color/color_gray9"
tools:ignore="RtlSymmetry" />

</FrameLayout>
<TextView
android:id="@+id/name"
style="@style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/Dashboard_Running_PreparingTest"
android:textColor="@color/color_gray9" />
</LinearLayout>

<ProgressBar
android:id="@+id/progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminateTint="@color/color_base"
android:maxHeight="8dp"
android:minHeight="8dp"
android:progressDrawable="@drawable/progress_blue" />

</LinearLayout>

0 comments on commit 24f16bf

Please sign in to comment.