Format file (no other change)

This commit is contained in:
Benoit Marty 2022-03-22 14:42:05 +01:00 committed by Benoit Marty
parent f07c9bf105
commit ed62a2f1c9

View file

@ -25,7 +25,7 @@ import me.gujun.android.span.Span
import me.gujun.android.span.span
internal class JSonViewerEpoxyController(private val context: Context) :
TypedEpoxyController<JSonViewerState>() {
TypedEpoxyController<JSonViewerState>() {
private var styleProvider: JSonViewerStyleProvider = JSonViewerStyleProvider.default(context)
@ -52,9 +52,9 @@ internal class JSonViewerEpoxyController(private val context: Context) :
}
private fun buildRec(
model: JSonViewerModel,
depth: Int,
idBase: String
model: JSonViewerModel,
depth: Int,
idBase: String
) {
val host = this
val id = "$idBase/${model.key ?: model.index}_${model.isExpanded}}"
@ -71,34 +71,34 @@ internal class JSonViewerEpoxyController(private val context: Context) :
id(id + "_sum")
depth(depth)
text(
span {
if (model.key != null) {
span("\"${model.key}\"") {
textColor = host.styleProvider.keyColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
if (model.index != null) {
span("${model.index}") {
textColor = host.styleProvider.secondaryColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
span {
+"{+${model.keys.size}}"
textColor = host.styleProvider.baseColor
}
}.toEpoxyCharSequence()
if (model.key != null) {
span("\"${model.key}\"") {
textColor = host.styleProvider.keyColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
if (model.index != null) {
span("${model.index}") {
textColor = host.styleProvider.secondaryColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
span {
+"{+${model.keys.size}}"
textColor = host.styleProvider.baseColor
}
}.toEpoxyCharSequence()
)
itemClickListener(View.OnClickListener { host.itemClicked(model) })
}
}
}
is JSonViewerArray -> {
is JSonViewerArray -> {
if (model.isExpanded) {
open(id, model.key, model.index, depth, false, model)
model.items.forEach {
@ -110,6 +110,38 @@ internal class JSonViewerEpoxyController(private val context: Context) :
id(id + "_sum")
depth(depth)
text(
span {
if (model.key != null) {
span("\"${model.key}\"") {
textColor = host.styleProvider.keyColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
if (model.index != null) {
span("${model.index}") {
textColor = host.styleProvider.secondaryColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
span {
+"[+${model.items.size}]"
textColor = host.styleProvider.baseColor
}
}.toEpoxyCharSequence()
)
itemClickListener(View.OnClickListener { host.itemClicked(model) })
}
}
}
is JSonViewerLeaf -> {
valueItem {
id(id)
depth(depth)
text(
span {
if (model.key != null) {
span("\"${model.key}\"") {
@ -119,6 +151,7 @@ internal class JSonViewerEpoxyController(private val context: Context) :
textColor = host.styleProvider.baseColor
}
}
if (model.index != null) {
span("${model.index}") {
textColor = host.styleProvider.secondaryColor
@ -127,41 +160,8 @@ internal class JSonViewerEpoxyController(private val context: Context) :
textColor = host.styleProvider.baseColor
}
}
span {
+"[+${model.items.size}]"
textColor = host.styleProvider.baseColor
}
append(host.valueToSpan(model))
}.toEpoxyCharSequence()
)
itemClickListener(View.OnClickListener { host.itemClicked(model) })
}
}
}
is JSonViewerLeaf -> {
valueItem {
id(id)
depth(depth)
text(
span {
if (model.key != null) {
span("\"${model.key}\"") {
textColor = host.styleProvider.keyColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
if (model.index != null) {
span("${model.index}") {
textColor = host.styleProvider.secondaryColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
append(host.valueToSpan(model))
}.toEpoxyCharSequence()
)
copyValue(model.stringRes)
}
@ -172,12 +172,12 @@ internal class JSonViewerEpoxyController(private val context: Context) :
private fun valueToSpan(leaf: JSonViewerLeaf): Span {
val host = this
return when (leaf.type) {
JSONType.STRING -> {
JSONType.STRING -> {
span("\"${leaf.stringRes}\"") {
textColor = host.styleProvider.stringColor
}
}
JSONType.NUMBER -> {
JSONType.NUMBER -> {
span(leaf.stringRes) {
textColor = host.styleProvider.numberColor
}
@ -187,7 +187,7 @@ internal class JSonViewerEpoxyController(private val context: Context) :
textColor = host.styleProvider.booleanColor
}
}
JSONType.NULL -> {
JSONType.NULL -> {
span("null") {
textColor = host.styleProvider.booleanColor
}
@ -196,42 +196,42 @@ internal class JSonViewerEpoxyController(private val context: Context) :
}
private fun open(
id: String,
key: String?,
index: Int?,
depth: Int,
isObject: Boolean = true,
composed: JSonViewerModel
id: String,
key: String?,
index: Int?,
depth: Int,
isObject: Boolean = true,
composed: JSonViewerModel
) {
val host = this
valueItem {
id("${id}_Open")
depth(depth)
text(
span {
if (key != null) {
span("\"$key\"") {
textColor = host.styleProvider.keyColor
span {
if (key != null) {
span("\"$key\"") {
textColor = host.styleProvider.keyColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
span(" : ") {
textColor = host.styleProvider.baseColor
if (index != null) {
span("$index") {
textColor = host.styleProvider.secondaryColor
}
span(" : ") {
textColor = host.styleProvider.baseColor
}
}
}
if (index != null) {
span("$index") {
span("- ") {
textColor = host.styleProvider.secondaryColor
}
span(" : ") {
span("{".takeIf { isObject } ?: "[") {
textColor = host.styleProvider.baseColor
}
}
span("- ") {
textColor = host.styleProvider.secondaryColor
}
span("{".takeIf { isObject } ?: "[") {
textColor = host.styleProvider.baseColor
}
}.toEpoxyCharSequence()
}.toEpoxyCharSequence()
)
itemClickListener(View.OnClickListener { host.itemClicked(composed) })
}
@ -248,10 +248,10 @@ internal class JSonViewerEpoxyController(private val context: Context) :
id("${id}_Close")
depth(depth)
text(
span {
text = "}".takeIf { isObject } ?: "]"
textColor = host.styleProvider.baseColor
}.toEpoxyCharSequence()
span {
text = "}".takeIf { isObject } ?: "]"
textColor = host.styleProvider.baseColor
}.toEpoxyCharSequence()
)
}
}