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"> + +