Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: (OONI Run V2) Add descriptor flow update #695

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading