From b3112b10508dbd7fe759512f1899f8b71b55e2b8 Mon Sep 17 00:00:00 2001 From: johnsonlee Date: Sun, 7 Jan 2024 01:26:26 +0900 Subject: [PATCH] Fix theme issue --- .../playground/sandbox/LayoutlibCallbackImpl.kt | 2 ++ .../playground/sandbox/SessionParamsBuilder.kt | 13 ++++++------- .../playground/sandbox/parsers/AttributeSnapshot.kt | 2 +- .../playground/sandbox/parsers/ResourceParser.kt | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/io/johnsonlee/playground/sandbox/LayoutlibCallbackImpl.kt b/src/main/kotlin/io/johnsonlee/playground/sandbox/LayoutlibCallbackImpl.kt index 5818294..5a1976c 100644 --- a/src/main/kotlin/io/johnsonlee/playground/sandbox/LayoutlibCallbackImpl.kt +++ b/src/main/kotlin/io/johnsonlee/playground/sandbox/LayoutlibCallbackImpl.kt @@ -66,6 +66,8 @@ internal class LayoutlibCallbackImpl( override fun getApplicationId(): String = appId + override fun getResourcePackage(): String = appId + override fun loadView( name: String, constructorSignature: Array>, diff --git a/src/main/kotlin/io/johnsonlee/playground/sandbox/SessionParamsBuilder.kt b/src/main/kotlin/io/johnsonlee/playground/sandbox/SessionParamsBuilder.kt index bdb9862..32263dd 100644 --- a/src/main/kotlin/io/johnsonlee/playground/sandbox/SessionParamsBuilder.kt +++ b/src/main/kotlin/io/johnsonlee/playground/sandbox/SessionParamsBuilder.kt @@ -52,14 +52,13 @@ data class SessionParamsBuilder( require(themeName != null) val folderConfiguration = deviceModel.resourceConfiguration + val platformResources = listOf(ResourceNamespace.ANDROID).associateWith { + frameworkResources.getConfiguredResources(folderConfiguration).row(it) + } + val applicationResources = projectResources.getConfiguredResources(folderConfiguration).rowMap() val resourceResolver = ResourceResolver.create( - mapOf( - ResourceNamespace.ANDROID to frameworkResources.getConfiguredResources(folderConfiguration) - .row(ResourceNamespace.ANDROID), - *projectResources.getConfiguredResources(folderConfiguration).rowMap() - .map { (key, value) -> key to value }.toTypedArray() - ), - ResourceReference(ResourceNamespace.ANDROID, ResourceType.STYLE, themeName), + platformResources + applicationResources, + ResourceReference(ResourceNamespace.RES_AUTO, ResourceType.STYLE, themeName), ) val sessionParams = SessionParams( layoutPullParser, diff --git a/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/AttributeSnapshot.kt b/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/AttributeSnapshot.kt index 1defeec..b19916e 100644 --- a/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/AttributeSnapshot.kt +++ b/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/AttributeSnapshot.kt @@ -2,7 +2,7 @@ package io.johnsonlee.playground.sandbox.parsers open class AttributeSnapshot( open val namespace: String, - open val prefix: String, + open val prefix: String?, open val name: String, open val value: String ) { diff --git a/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/ResourceParser.kt b/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/ResourceParser.kt index b77fbb6..aa5f37c 100644 --- a/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/ResourceParser.kt +++ b/src/main/kotlin/io/johnsonlee/playground/sandbox/parsers/ResourceParser.kt @@ -85,11 +85,11 @@ class ResourceParser(input: InputStream) : KXmlParser() { } private fun findPrefixByQualifiedName(qualifiedName: String): String { - return qualifiedName.substringBefore(':').takeIf(String::isNotEmpty) ?: "" + return qualifiedName.substringBefore(':', "") } private fun findLocalNameByQualifiedName(qualifiedName: String): String { - return qualifiedName.substringAfterLast(':') + return qualifiedName.substringAfter(':') } private fun createAttributesForTag(): MutableList {