/
KeyValueListModule.kt
56 lines (50 loc) · 2.11 KB
/
KeyValueListModule.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
47
48
49
50
51
52
53
54
55
56
package com.pandulapeter.beagle.modules
import androidx.annotation.StringRes
import com.pandulapeter.beagle.common.configuration.Text
import com.pandulapeter.beagle.common.configuration.toText
import com.pandulapeter.beagle.common.contracts.BeagleContract
import com.pandulapeter.beagle.common.contracts.module.ExpandableModule
import com.pandulapeter.beagle.commonBase.randomId
import com.pandulapeter.beagle.modules.KeyValueListModule.Companion.DEFAULT_IS_EXPANDED_INITIALLY
/**
* Displays a list of key-value pairs that can be collapsed into a header.
*
* @param title - The title of the module that will be displayed in the header of the list.
* @param pairs - The list of key-value pairs to display.
* @param isExpandedInitially - Whether or not the list is expanded the first time the module becomes visible. [DEFAULT_IS_EXPANDED_INITIALLY] by default.
* @param id - A unique identifier for the module. [randomId] by default.
*/
@Suppress("unused")
data class KeyValueListModule(
val title: Text,
val pairs: List<Pair<Text, Text>>,
override val isExpandedInitially: Boolean = DEFAULT_IS_EXPANDED_INITIALLY,
override val id: String = randomId
) : ExpandableModule<KeyValueListModule> {
constructor(
title: CharSequence,
pairs: List<Pair<CharSequence, CharSequence>>,
isExpandedInitially: Boolean = DEFAULT_IS_EXPANDED_INITIALLY,
id: String = randomId
) : this(
title = title.toText(),
pairs = pairs.map { it.first.toText() to it.second.toText() },
isExpandedInitially = isExpandedInitially,
id = id
)
constructor(
@StringRes title: Int,
pairs: List<Pair<CharSequence, CharSequence>>,
isExpandedInitially: Boolean = DEFAULT_IS_EXPANDED_INITIALLY,
id: String = randomId
) : this(
title = title.toText(),
pairs = pairs.map { it.first.toText() to it.second.toText() },
isExpandedInitially = isExpandedInitially,
id = id
)
override fun getHeaderTitle(beagle: BeagleContract) = title
companion object {
private const val DEFAULT_IS_EXPANDED_INITIALLY = false
}
}