Skip to content

Commit

Permalink
feat: (OONI Run V2) Add descriptor flow update (#695)
Browse files Browse the repository at this point in the history
- Fixes : ooni/run#148 ,
ooni/run#152 ,
ooni/run#149 ,
ooni/run#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)
|
  • Loading branch information
aanorbel authored Mar 21, 2024
1 parent 6a00d6a commit 8e23e83
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ typealias OnTaskComplete<R> = (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.
Expand All @@ -54,8 +53,10 @@ class TaskExecutor {
fun <R> executeTask(task: Task<R>, onComplete: OnTaskComplete<R>) {
future = executor.submit {
val result = task.call()
handler.post {
onComplete(result)
if (!future.isCancelled) {
handler.post {
onComplete(result)
}
}
}
}
Expand Down Expand Up @@ -90,6 +91,6 @@ class TaskExecutor {
* Cancels the currently running task.
*/
fun cancelTask() {
future?.cancel(true)
this.future.cancel(true)
}
}
34 changes: 29 additions & 5 deletions app/src/main/res/layout/activity_add_descriptor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,37 @@
android:layout_gravity="bottom"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">

<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomBar"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_gray0"
app:menu="@menu/add_descriptor"
app:titleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title.App" />
android:gravity="center">

<Button
android:id="@+id/btn_cancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Modal_Cancel"
android:textColor="@color/color_base" />

<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />

<Button
android:id="@+id/btn_install_link"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:elevation="0dp"
android:text="Install Link"
android:textColor="@color/color_base" />

</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
10 changes: 0 additions & 10 deletions app/src/main/res/menu/add_descriptor.xml

This file was deleted.

0 comments on commit 8e23e83

Please sign in to comment.