Skip to content

Commit

Permalink
feat: (OONI Run v2) fix Run button is hard to see
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Mar 16, 2024
1 parent 73e8ea0 commit f5ae9c0
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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<String> = 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<String> = 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.
Expand Down Expand Up @@ -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<String> {
val childItemSelectedIdList: MutableList<String> = ArrayList()
Expand Down
41 changes: 25 additions & 16 deletions app/src/main/res/layout/activity_customwebsite.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.customwebsites.CustomWebsiteActivity">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:elevation="0dp">

<androidx.appcompat.widget.Toolbar
Expand All @@ -23,7 +28,9 @@
android:id="@+id/urlsList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
app:layout_constraintTop_toBottomOf="@id/appbar_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -46,22 +53,24 @@
android:textAllCaps="false"
android:textColor="@color/color_black"
app:icon="@drawable/ic_baseline_add_36"
app:iconTint="@color/color_black" />
app:iconTint="@color/color_black"
android:layout_marginBottom="150dp"/>
</LinearLayout>
</ScrollView>

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab_test_urls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">
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"/>

<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_gray0"
app:menu="@menu/run"
app:title="@string/OONIRun_URLs"
app:titleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title.App" />
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
43 changes: 24 additions & 19 deletions app/src/main/res/layout/activity_run_tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select the tests to run"
android:paddingBottom="@dimen/item_padding_small"
style="?attr/textAppearanceHeadline6"/>

<Button
android:id="@+id/select_all"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Settings_Websites_Categories_Selection_All"
android:text="Select all tests"
android:textAllCaps="false"
app:cornerRadius="24dp"
app:rippleColor="@color/ripple_material_dark"
Expand All @@ -42,7 +50,7 @@
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Settings_Websites_Categories_Selection_None"
android:text="Deselect all tests"
android:textAllCaps="false"
app:cornerRadius="24dp"
app:rippleColor="@color/ripple_material_dark"
Expand All @@ -61,25 +69,22 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/control_layout"
app:layout_constraintBottom_toTopOf="@+id/bottom_appbar_layout"
app:layout_constraintBottom_toBottomOf="parent"
tools:listitem="@layout/run_tests_group_list_item" />

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/bottom_appbar_layout"
android:layout_width="match_parent"
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab_run_tests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Run Tests"
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_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">
app:layout_constraintStart_toStartOf="parent"
app:iconTint="@android:color/white"/>

<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_white"
app:menu="@menu/run"
app:title="@string/OONIRun_URLs"
app:titleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title.App" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 0 additions & 8 deletions app/src/main/res/menu/run.xml

This file was deleted.

0 comments on commit f5ae9c0

Please sign in to comment.