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/customwebsites/CustomWebsiteActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/customwebsites/CustomWebsiteActivity.kt index 7342ef29b..e00db42ae 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/customwebsites/CustomWebsiteActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/customwebsites/CustomWebsiteActivity.kt @@ -4,10 +4,9 @@ import android.content.DialogInterface import android.os.Bundle import android.os.Parcelable import android.util.Patterns -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import androidx.activity.viewModels +import androidx.core.content.ContextCompat +import androidx.core.graphics.drawable.DrawableCompat import androidx.recyclerview.widget.LinearLayoutManager import org.openobservatory.ooniprobe.R import org.openobservatory.ooniprobe.activity.AbstractActivity @@ -50,15 +49,23 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL ) setContentView(binding.root) setSupportActionBar(binding.toolbar) - supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.apply { + setDisplayHomeAsUpEnabled(true) + setHomeAsUpIndicator( + ContextCompat.getDrawable(this@CustomWebsiteActivity, R.drawable.close) + ?.apply { DrawableCompat.setTint(this, ContextCompat.getColor(this@CustomWebsiteActivity, R.color.color_black)) } + ) + title = getString(R.string.Settings_Websites_CustomURL_Title).uppercase() + } + val layoutManager = LinearLayoutManager(this) + binding.urlContainer.isNestedScrollingEnabled = false binding.urlContainer.layoutManager = layoutManager + val fatTextTemplate = "Test %s URLs" adapter = CustomWebsiteRecyclerViewAdapter( onItemChangedListener = object : ItemChangedListener { override fun onItemRemoved(position: Int) { - binding.bottomBar.title = getString( - R.string.OONIRun_URLs, adapter.itemCount.toString() - ) + binding.fabTestUrls.text = fatTextTemplate.format(adapter.itemCount) viewModel.onItemRemoved(position) } @@ -68,12 +75,10 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL }, ) viewModel.urls.observe(this) { urls -> - binding.bottomBar.title = getString( - R.string.OONIRun_URLs, urls.size.toString() - ) + binding.fabTestUrls.text = fatTextTemplate.format(urls.size) } - binding.bottomBar.setOnMenuItemClickListener { item: MenuItem? -> runTests() } + binding.fabTestUrls.setOnClickListener { runTests() } binding.add.setOnClickListener { add() } binding.urlContainer.adapter = adapter @@ -147,23 +152,6 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL return true } - override fun onCreateOptionsMenu(menu: Menu): Boolean { - val inflater: MenuInflater = menuInflater - inflater.inflate(R.menu.close, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - R.id.close_button -> { - onSupportNavigateUp() - true - } - - else -> super.onOptionsItemSelected(item) - } - } - /** * This function will add a new url to the list of urls. * It will also scroll to the bottom of the list. 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/activity/runtests/RunTestsActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsActivity.kt index 219b01e0f..adf66a69e 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsActivity.kt @@ -4,9 +4,9 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.text.TextUtils -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem +import android.widget.Toast +import androidx.core.content.ContextCompat +import androidx.core.graphics.drawable.DrawableCompat import org.openobservatory.engine.BaseNettest import org.openobservatory.ooniprobe.R import org.openobservatory.ooniprobe.activity.AbstractActivity @@ -54,7 +54,14 @@ class RunTestsActivity : AbstractActivity() { setContentView(binding.getRoot()) setSupportActionBar(binding.toolbar) - supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.apply { + setDisplayHomeAsUpEnabled(true) + setHomeAsUpIndicator( + ContextCompat.getDrawable(this@RunTestsActivity, R.drawable.close) + ?.apply { DrawableCompat.setTint(this, ContextCompat.getColor(this@RunTestsActivity, R.color.color_black)) } + ) + title = "Run tests".uppercase() + } activityComponent?.inject(this) @@ -78,55 +85,29 @@ class RunTestsActivity : AbstractActivity() { viewModel.selectedAllBtnStatus.observe(this, this::selectAllBtnStatusObserver) - binding.bottomBar.setOnMenuItemClickListener { menuItem -> - onMenuItemClickListener(menuItem) - } + binding.fabRunTests.setOnClickListener { onRunTestsClickListener() } } ?: run { finish() } } - - override fun onCreateOptionsMenu(menu: Menu): Boolean { - val inflater: MenuInflater = menuInflater - inflater.inflate(R.menu.close, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - R.id.close_button -> { - finish() - true - } - - else -> super.onOptionsItemSelected(item) - } - } - - private fun onMenuItemClickListener(menuItem: MenuItem): Boolean { - return when (menuItem.itemId) { - R.id.runButton -> { - updatePreferences() - val selectedChildItems: List = getChildItemsSelectedIdList() - if (selectedChildItems.isNotEmpty()) { - val testSuitesToRun = getGroupItemsAtLeastOneChildEnabled().map { groupItem -> - return@map groupItem.getTest(this) - } - RunningActivity.runAsForegroundService( - this@RunTestsActivity, - java.util.ArrayList(testSuitesToRun), - { finish() }, - preferenceManager - ) - - } - true - } - - else -> false - } - } + private fun onRunTestsClickListener() { + updatePreferences() + val selectedChildItems: List = getChildItemsSelectedIdList() + if (selectedChildItems.isNotEmpty()) { + val testSuitesToRun = getGroupItemsAtLeastOneChildEnabled().map { groupItem -> + return@map groupItem.getTest(this) + } + RunningActivity.runAsForegroundService( + this@RunTestsActivity, + java.util.ArrayList(testSuitesToRun), + { finish() }, + preferenceManager + ) + } else { + Toast.makeText(this@RunTestsActivity, "Please select test to run", Toast.LENGTH_LONG).show() + } + } /** * Update the preferences based on the selected tests. @@ -189,10 +170,10 @@ class RunTestsActivity : AbstractActivity() { } - private fun updateStatusIndicator() { - //TODO(aanorbel): translate status indicator - binding.bottomBar.setTitle("${getChildItemsSelectedIdList().size} Tests") - } + private fun updateStatusIndicator() { + //TODO(aanorbel): translate status indicator + binding.fabRunTests.text = "Run ${getChildItemsSelectedIdList().size} test" + } private fun getChildItemsSelectedIdList(): List { val childItemSelectedIdList: MutableList = ArrayList() 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"> + +