From f5ae9c07631e90f40b370096298594d1576bae7b Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Sat, 16 Mar 2024 21:39:31 +0100 Subject: [PATCH] feat: (OONI Run v2) fix Run button is hard to see --- .../customwebsites/CustomWebsiteActivity.kt | 44 ++++------ .../activity/runtests/RunTestsActivity.kt | 82 +++++++------------ .../res/layout/activity_customwebsite.xml | 41 ++++++---- .../main/res/layout/activity_run_tests.xml | 43 +++++----- app/src/main/res/menu/run.xml | 8 -- 5 files changed, 95 insertions(+), 123 deletions(-) delete mode 100644 app/src/main/res/menu/run.xml 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/runtests/RunTestsActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsActivity.kt index 219b01e0f..a3d459e7b 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,8 @@ 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 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 +53,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 +84,27 @@ 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 + ) + } + } /** * Update the preferences based on the selected tests. @@ -189,10 +167,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/res/layout/activity_customwebsite.xml b/app/src/main/res/layout/activity_customwebsite.xml index e140b50e3..70f10515b 100644 --- a/app/src/main/res/layout/activity_customwebsite.xml +++ b/app/src/main/res/layout/activity_customwebsite.xml @@ -1,14 +1,19 @@ - + + app:layout_constraintTop_toBottomOf="@id/appbar_layout" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"> + app:iconTint="@color/color_black" + android:layout_marginBottom="150dp"/> - + android:text="Test Urls" + android:layout_marginBottom="@dimen/item_padding_large" + android:backgroundTint="@color/color_base" + android:textColor="@android:color/white" + android:textAllCaps="false" + app:icon="@drawable/outline_timer" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:iconTint="@android:color/white"/> - - - + diff --git a/app/src/main/res/layout/activity_run_tests.xml b/app/src/main/res/layout/activity_run_tests.xml index 10dcc4d38..dd3f26875 100644 --- a/app/src/main/res/layout/activity_run_tests.xml +++ b/app/src/main/res/layout/activity_run_tests.xml @@ -11,7 +11,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/color_white" - app:menu="@menu/close" app:layout_constraintTop_toTopOf="parent" app:contentInsetEnd="0dp" app:contentInsetStart="0dp" /> @@ -21,17 +20,26 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:layout_marginStart="16dp" + android:layout_marginStart="@dimen/item_padding_large" + android:paddingTop="@dimen/item_padding_small" + android:paddingBottom="@dimen/item_padding_large" app:layout_constraintTop_toBottomOf="@id/toolbar" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"> + +