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