-
Notifications
You must be signed in to change notification settings - Fork 8
/
KeyValueList.kt
46 lines (40 loc) 路 1.55 KB
/
KeyValueList.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.kernel.finch.components
import androidx.annotation.StringRes
import com.kernel.finch.common.contracts.Finch
import com.kernel.finch.common.contracts.component.Component
import com.kernel.finch.common.contracts.component.ExpandableComponent
import com.kernel.finch.common.models.Text
@Suppress("Unused")
data class KeyValueList(
val title: Text,
val pairs: List<Pair<Text, Text>>,
override val isExpandedInitially: Boolean = DEFAULT_IS_EXPANDED_INITIALLY,
override val id: String = Component.randomId
) : ExpandableComponent<KeyValueList> {
constructor(
title: CharSequence,
pairs: List<Pair<CharSequence, CharSequence>>,
isExpandedInitially: Boolean = DEFAULT_IS_EXPANDED_INITIALLY,
id: String = Component.randomId
) : this(
title = Text.CharSequence(title),
pairs = pairs.map { Text.CharSequence(it.first) to Text.CharSequence(it.second) },
isExpandedInitially = isExpandedInitially,
id = id
)
constructor(
@StringRes title: Int,
pairs: List<Pair<CharSequence, CharSequence>>,
isExpandedInitially: Boolean = DEFAULT_IS_EXPANDED_INITIALLY,
id: String = Component.randomId
) : this(
title = Text.ResourceId(title),
pairs = pairs.map { Text.CharSequence(it.first) to Text.CharSequence(it.second) },
isExpandedInitially = isExpandedInitially,
id = id
)
override fun getHeaderTitle(finch: Finch) = title
companion object {
private const val DEFAULT_IS_EXPANDED_INITIALLY = false
}
}