From 3907b068f1e3ae58532c546f26c65855d80d327e Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Wed, 22 May 2024 17:59:44 +0100 Subject: [PATCH 1/3] Restyle entities browser --- .../odk/collect/entities/EntitiesFragment.kt | 2 + .../odk/collect/entities/EntityItemView.kt | 2 +- .../collect/entities/EntityListsFragment.kt | 4 ++ .../main/res/layout/entity_item_layout.xml | 43 +++++++++++-------- .../collect/entities/EntityItemViewTest.kt | 2 +- .../res/drawable/ic_baseline_wifi_off_24.xml | 5 +++ 6 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 icons/src/main/res/drawable/ic_baseline_wifi_off_24.xml diff --git a/entities/src/main/java/org/odk/collect/entities/EntitiesFragment.kt b/entities/src/main/java/org/odk/collect/entities/EntitiesFragment.kt index 700005730d3..f0daa09f365 100644 --- a/entities/src/main/java/org/odk/collect/entities/EntitiesFragment.kt +++ b/entities/src/main/java/org/odk/collect/entities/EntitiesFragment.kt @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.ViewHolder import org.odk.collect.entities.databinding.ListLayoutBinding +import org.odk.collect.lists.RecyclerViewUtils import org.odk.collect.lists.RecyclerViewUtils.matchParentWidth class EntitiesFragment(private val viewModelFactory: ViewModelProvider.Factory) : Fragment() { @@ -29,6 +30,7 @@ class EntitiesFragment(private val viewModelFactory: ViewModelProvider.Factory) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { val binding = ListLayoutBinding.bind(view) binding.list.layoutManager = LinearLayoutManager(requireContext()) + binding.list.addItemDecoration(RecyclerViewUtils.verticalLineDivider(requireContext())) val list = EntitiesFragmentArgs.fromBundle(requireArguments()).list entitiesViewModel.getEntities(list).observe(viewLifecycleOwner) { diff --git a/entities/src/main/java/org/odk/collect/entities/EntityItemView.kt b/entities/src/main/java/org/odk/collect/entities/EntityItemView.kt index 81eb6be2965..3c349347fac 100644 --- a/entities/src/main/java/org/odk/collect/entities/EntityItemView.kt +++ b/entities/src/main/java/org/odk/collect/entities/EntityItemView.kt @@ -14,7 +14,7 @@ class EntityItemView(context: Context) : FrameLayout(context) { binding.label.text = entity.label binding.properties.text = entity.properties .sortedBy { it.first } - .joinToString(separator = ", ") { "${it.first}: ${it.second}" } + .joinToString(separator = "\n") { "${it.first}: ${it.second}" } binding.offlinePill.isVisible = entity.state == Entity.State.OFFLINE } } diff --git a/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt b/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt index 0b7e88330b6..728395d7cd0 100644 --- a/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt +++ b/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt @@ -19,9 +19,11 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.ViewHolder import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.odk.collect.androidshared.ui.enableIconsVisibility import org.odk.collect.entities.databinding.AddEntitiesDialogLayoutBinding import org.odk.collect.entities.databinding.EntityListItemLayoutBinding import org.odk.collect.entities.databinding.ListLayoutBinding +import org.odk.collect.lists.RecyclerViewUtils class EntityListsFragment( private val viewModelFactory: ViewModelProvider.Factory, @@ -41,6 +43,7 @@ class EntityListsFragment( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { val binding = ListLayoutBinding.bind(view) binding.list.layoutManager = LinearLayoutManager(requireContext()) + binding.list.addItemDecoration(RecyclerViewUtils.verticalLineDivider(requireContext())) entitiesViewModel.lists.observe(viewLifecycleOwner) { binding.list.adapter = ListsAdapter(it, findNavController()) @@ -72,6 +75,7 @@ private class ListsMenuProvider( val binding = AddEntitiesDialogLayoutBinding.inflate(LayoutInflater.from(context)) MaterialAlertDialogBuilder(context) .setView(binding.root) + .setTitle("Add entity list") .setPositiveButton(org.odk.collect.strings.R.string.add) { _, _ -> entitiesViewModel.addEntityList(binding.entityListName.text.toString()) } diff --git a/entities/src/main/res/layout/entity_item_layout.xml b/entities/src/main/res/layout/entity_item_layout.xml index b7a9b680a0e..507fdc070f1 100644 --- a/entities/src/main/res/layout/entity_item_layout.xml +++ b/entities/src/main/res/layout/entity_item_layout.xml @@ -4,36 +4,45 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?android:attr/selectableItemBackground" - android:paddingHorizontal="@dimen/margin_standard" - android:paddingTop="@dimen/margin_standard"> + android:background="?android:attr/selectableItemBackground"> + + + + - - + tools:text="property1: value1" /> diff --git a/entities/src/test/java/org/odk/collect/entities/EntityItemViewTest.kt b/entities/src/test/java/org/odk/collect/entities/EntityItemViewTest.kt index 799c9f87786..9199c8b7828 100644 --- a/entities/src/test/java/org/odk/collect/entities/EntityItemViewTest.kt +++ b/entities/src/test/java/org/odk/collect/entities/EntityItemViewTest.kt @@ -28,7 +28,7 @@ class EntityItemViewTest { ) val propertiesView = view.binding.properties - assertThat(propertiesView.text, equalTo("length: 2:50, name: S.D.O.S")) + assertThat(propertiesView.text, equalTo("length: 2:50\nname: S.D.O.S")) } @Test diff --git a/icons/src/main/res/drawable/ic_baseline_wifi_off_24.xml b/icons/src/main/res/drawable/ic_baseline_wifi_off_24.xml new file mode 100644 index 00000000000..cbcdfdb6f26 --- /dev/null +++ b/icons/src/main/res/drawable/ic_baseline_wifi_off_24.xml @@ -0,0 +1,5 @@ + + + + + From 38960bbfbcc1056170793f19135613809bd8b47a Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Thu, 23 May 2024 11:11:12 +0100 Subject: [PATCH 2/3] Use highest surface container for offline pill --- .../main/res/layout/entity_item_layout.xml | 1 + .../org/odk/collect/material/MaterialPill.kt | 47 ++++++++++++------- material/src/main/res/values/attrs.xml | 1 + 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/entities/src/main/res/layout/entity_item_layout.xml b/entities/src/main/res/layout/entity_item_layout.xml index 507fdc070f1..c862bb186b7 100644 --- a/entities/src/main/res/layout/entity_item_layout.xml +++ b/entities/src/main/res/layout/entity_item_layout.xml @@ -21,6 +21,7 @@ app:icon="@drawable/ic_baseline_wifi_off_24" app:layout_constraintStart_toStartOf="@id/guideline_start" app:layout_constraintTop_toTopOf="parent" + app:pillBackgroundColor="?colorSurfaceContainerHighest" app:text="@string/offline" /> + From 023639c2484dbe51168b5edfcec8896f004e2185 Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Thu, 23 May 2024 11:45:05 +0100 Subject: [PATCH 3/3] Use translatable string --- .../main/java/org/odk/collect/entities/EntityListsFragment.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt b/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt index 728395d7cd0..6e1470fe508 100644 --- a/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt +++ b/entities/src/main/java/org/odk/collect/entities/EntityListsFragment.kt @@ -19,7 +19,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.ViewHolder import com.google.android.material.dialog.MaterialAlertDialogBuilder -import org.odk.collect.androidshared.ui.enableIconsVisibility import org.odk.collect.entities.databinding.AddEntitiesDialogLayoutBinding import org.odk.collect.entities.databinding.EntityListItemLayoutBinding import org.odk.collect.entities.databinding.ListLayoutBinding @@ -75,7 +74,7 @@ private class ListsMenuProvider( val binding = AddEntitiesDialogLayoutBinding.inflate(LayoutInflater.from(context)) MaterialAlertDialogBuilder(context) .setView(binding.root) - .setTitle("Add entity list") + .setTitle(org.odk.collect.strings.R.string.add_entity_list) .setPositiveButton(org.odk.collect.strings.R.string.add) { _, _ -> entitiesViewModel.addEntityList(binding.entityListName.text.toString()) }