Skip to content

Commit

Permalink
Show all entity properties consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Oct 13, 2022
1 parent 0e719fd commit 7324e7f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions .circleci/test_modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ permissions:testDebug
settings:testDebug
maps:testDebug
errors:testDebug
entities:testDebug
2 changes: 2 additions & 0 deletions entities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ dependencies {
implementation Dependencies.dagger
kapt Dependencies.dagger_compiler

testImplementation Dependencies.junit
testImplementation Dependencies.robolectric
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EntitiesFragment : Fragment() {
entitiesRepository.getEntities(dataset).forEach { entity ->
val item = ListItemLayoutBinding.inflate(layoutInflater)

val firstField = entity.fields[0]
val firstField = entity.properties[0]
item.content.text =
getString(R.string.entity_summary, firstField.first, firstField.second)

Expand Down
2 changes: 1 addition & 1 deletion entities/src/main/java/org/odk/collect/entities/Entity.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package org.odk.collect.entities

data class Entity(val dataset: String, val fields: List<Pair<String, String>>)
data class Entity(val dataset: String, val properties: List<Pair<String, String>>)
17 changes: 17 additions & 0 deletions entities/src/main/java/org/odk/collect/entities/EntityItemView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.odk.collect.entities

import android.content.Context
import android.view.LayoutInflater
import android.widget.FrameLayout
import org.odk.collect.entities.databinding.EntityItemLayoutBinding

class EntityItemView(context: Context) : FrameLayout(context) {

private val binding = EntityItemLayoutBinding.inflate(LayoutInflater.from(context), this, true)

fun setEntity(entity: Entity) {
binding.properties.text = entity.properties
.sortedBy { it.first }
.joinToString(separator = ", ") { "${it.first}: ${it.second}" }
}
}
13 changes: 13 additions & 0 deletions entities/src/main/res/layout/entity_item_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/properties"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.odk.collect.entities

import android.widget.TextView
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsEqual.equalTo
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

@RunWith(RobolectricTestRunner::class)
class EntityItemViewTest {

private val context = RuntimeEnvironment.getApplication()

@Test
fun sortsOrderOfProperties() {
val view = EntityItemView(context)
view.setEntity(Entity("songs", listOf(Pair("name", "S.D.O.S"), Pair("length", "2:50"))))

val propertiesView = view.findViewById<TextView>(R.id.properties)
assertThat(propertiesView.text, equalTo("length: 2:50, name: S.D.O.S"))
}
}

0 comments on commit 7324e7f

Please sign in to comment.