Skip to content

Commit

Permalink
Merge pull request #6313 from seadowg/view-entity-id
Browse files Browse the repository at this point in the history
Show entity id and version on list
  • Loading branch information
grzesiek2010 authored Aug 13, 2024
2 parents 740f1a6 + 3a86332 commit 8f3ffc1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.odk.collect.entities.browser

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.widget.FrameLayout
Expand All @@ -11,8 +12,10 @@ class EntityItemView(context: Context) : FrameLayout(context) {

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

@SuppressLint("SetTextI18n")
fun setEntity(entity: Entity.Saved) {
binding.label.text = entity.label
binding.id.text = "${entity.id} (${entity.version})"
binding.properties.text = entity.properties
.sortedBy { it.first }
.joinToString(separator = "\n") { "${it.first}: ${it.second}" }
Expand Down
13 changes: 12 additions & 1 deletion entities/src/main/res/layout/entity_item_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
app:layout_constraintTop_toBottomOf="@id/offline_pill"
tools:text="Label" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_small"
android:layout_marginBottom="@dimen/margin_standard"
android:textAppearance="?textAppearanceLabelMedium"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toBottomOf="@id/label"
tools:text="e636bbe8-7707-4c6b-bee1-41698005ac23 (12)" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/properties"
android:layout_width="wrap_content"
Expand All @@ -43,7 +54,7 @@
android:textAppearance="?textAppearanceBodyMedium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toBottomOf="@id/label"
app:layout_constraintTop_toBottomOf="@id/id"
tools:text="property1: value1" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ class EntityItemViewTest {
view.setEntity(entity.copy(state = Entity.State.ONLINE))
assertThat(view.binding.offlinePill.isVisible, equalTo(false))
}

@Test
fun `shows id and version`() {
val view = EntityItemView(context)
val entity = Entity.Saved("songs", "1", "S.D.O.S", version = 11, index = 0)

view.setEntity(entity.copy(state = Entity.State.OFFLINE))
assertThat(view.binding.id.text, equalTo("${entity.id} (${entity.version})"))
}
}

0 comments on commit 8f3ffc1

Please sign in to comment.