From 8e23e8317e15378a356a51e83a7b3184392cfe61 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Thu, 21 Mar 2024 16:18:25 +0100 Subject: [PATCH] feat: (OONI Run V2) Add descriptor flow update (#695) - Fixes : https://github.com/ooni/run/issues/148 , https://github.com/ooni/run/issues/152 , https://github.com/ooni/run/issues/149 , https://github.com/ooni/run/issues/151 ## Proposed Changes - Add missing post-load toast from install link flow - Add 'cancel' button on link install flow. - Change 'add link' to 'install link' in new link install flow. - Add Link cancellation toast missing. |.|.|.| |-|-|-| |![Screenshot_20240316_135514](https://github.com/ooni/probe-android/assets/17911892/132d06ad-7b83-4a61-959f-32c15c5d2e17) | ![Screenshot_20240316_143418](https://github.com/ooni/probe-android/assets/17911892/091661dd-4532-420a-97fd-4fd2a9ce7631) | ![Screenshot_20240316_145934](https://github.com/ooni/probe-android/assets/17911892/7d58a7f2-911e-412b-91f9-686de2c6ccaa) | --- .../adddescriptor/AddDescriptorActivity.kt | 31 ++++++++--------- .../activity/oonirun/OoniRunV2Activity.kt | 2 +- .../ooniprobe/common/TaskExecutor.kt | 11 +++--- .../res/layout/activity_add_descriptor.xml | 34 ++++++++++++++++--- app/src/main/res/menu/add_descriptor.xml | 10 ------ 5 files changed, 50 insertions(+), 38 deletions(-) delete mode 100644 app/src/main/res/menu/add_descriptor.xml diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt index 6fedc19fd..450b3ae35 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/adddescriptor/AddDescriptorActivity.kt @@ -10,8 +10,8 @@ import android.view.MenuInflater import android.view.MenuItem import android.widget.ImageView import android.widget.TextView +import android.widget.Toast import androidx.activity.viewModels -import androidx.appcompat.widget.Toolbar import androidx.databinding.BindingAdapter import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider @@ -113,7 +113,7 @@ class AddDescriptorActivity : AbstractActivity() { setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(false) supportActionBar?.setDisplayShowHomeEnabled(false) - supportActionBar?.title = "Add New Link" + supportActionBar?.title = "Install New Link" val descriptorExtra = if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { intent.getParcelableExtra(DESCRIPTOR, TestDescriptor::class.java) } else { @@ -144,21 +144,17 @@ class AddDescriptorActivity : AbstractActivity() { for (i in 0 until adapter.groupCount) { binding.expandableListView.expandGroup(i) } - val bottomBarOnMenuItemClickListener: Toolbar.OnMenuItemClickListener = - Toolbar.OnMenuItemClickListener { item -> - when (item.itemId) { - R.id.add_descriptor -> { - viewModel.onAddButtonClicked( - disabledAutorunNettests = adapter.nettests.filter { it.selected }, - automatedUpdates = binding.automaticUpdatesSwitch.isChecked - ) - true - } - - else -> false - } - } - binding.bottomBar.setOnMenuItemClickListener(bottomBarOnMenuItemClickListener) + + binding.btnInstallLink.setOnClickListener { + viewModel.onAddButtonClicked( + disabledAutorunNettests = adapter.nettests.filter { it.selected }, + automatedUpdates = binding.automaticUpdatesSwitch.isChecked + ) + } + + binding.btnCancel.setOnClickListener { + finish() + } viewModel.selectedAllBtnStatus.observe(this) { state -> binding.testsCheckbox.checkedState = state; @@ -173,6 +169,7 @@ class AddDescriptorActivity : AbstractActivity() { // This observer is used to finish the activity when the descriptor is added. viewModel.finishActivity.observe(this) { shouldFinish -> if (shouldFinish) { + Toast.makeText(this@AddDescriptorActivity, "Link installed", Toast.LENGTH_LONG).show() finish() } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/oonirun/OoniRunV2Activity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/oonirun/OoniRunV2Activity.kt index b5a092621..e832525af 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/oonirun/OoniRunV2Activity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/oonirun/OoniRunV2Activity.kt @@ -85,7 +85,7 @@ class OoniRunV2Activity : AbstractActivity() { val executor = TaskExecutor() binding.cancelButton.setOnClickListener { executor.cancelTask() - finishWithError(message = getString(R.string.Modal_Cancel)) + finishWithError(message = "Link installation cancelled") } executor.executeTask({ try { diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/TaskExecutor.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/TaskExecutor.kt index 8b821654d..57e5afdfb 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/TaskExecutor.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/TaskExecutor.kt @@ -44,8 +44,7 @@ typealias OnTaskComplete = (R) -> Unit class TaskExecutor { private val executor = Executors.newSingleThreadExecutor() private val handler = Handler(Looper.getMainLooper()) - private var future: Future<*>? = null - + private lateinit var future: Future<*> /** * Executes a task in a separate thread and posts the result on the main thread. * @param task The task to be executed. @@ -54,8 +53,10 @@ class TaskExecutor { fun executeTask(task: Task, onComplete: OnTaskComplete) { future = executor.submit { val result = task.call() - handler.post { - onComplete(result) + if (!future.isCancelled) { + handler.post { + onComplete(result) + } } } } @@ -90,6 +91,6 @@ class TaskExecutor { * Cancels the currently running task. */ fun cancelTask() { - future?.cancel(true) + this.future.cancel(true) } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_add_descriptor.xml b/app/src/main/res/layout/activity_add_descriptor.xml index 36fbf7298..6d7aaaecf 100644 --- a/app/src/main/res/layout/activity_add_descriptor.xml +++ b/app/src/main/res/layout/activity_add_descriptor.xml @@ -162,13 +162,37 @@ android:layout_gravity="bottom" android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"> - + android:gravity="center"> + +