Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit 23a59b4

Browse files
author
Nick Rout
committed
Refactor common theme adapter logic into :core module
1 parent b56f30b commit 23a59b4

File tree

17 files changed

+276
-598
lines changed

17 files changed

+276
-598
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/src/main/java/com/google/android/material/composethemeadapter/dependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ object Libs {
8484
}
8585
}
8686

87+
const val mdc = "com.google.android.material:material:1.7.0"
88+
8789
const val junit = "junit:junit:4.13"
8890

8991
const val truth = "com.google.truth:truth:1.0.1"

core/api/core.api

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
public final class com/google/android/material/composethemeadapter/core/FontFamilyWithWeight {
2+
public static final field $stable I
3+
public fun <init> (Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;)V
4+
public synthetic fun <init> (Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
5+
public final fun component1 ()Landroidx/compose/ui/text/font/FontFamily;
6+
public final fun component2 ()Landroidx/compose/ui/text/font/FontWeight;
7+
public final fun copy (Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;)Lcom/google/android/material/composethemeadapter/core/FontFamilyWithWeight;
8+
public static synthetic fun copy$default (Lcom/google/android/material/composethemeadapter/core/FontFamilyWithWeight;Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;ILjava/lang/Object;)Lcom/google/android/material/composethemeadapter/core/FontFamilyWithWeight;
9+
public fun equals (Ljava/lang/Object;)Z
10+
public final fun getFontFamily ()Landroidx/compose/ui/text/font/FontFamily;
11+
public final fun getWeight ()Landroidx/compose/ui/text/font/FontWeight;
12+
public fun hashCode ()I
13+
public fun toString ()Ljava/lang/String;
14+
}
15+
16+
public final class com/google/android/material/composethemeadapter/core/ResourceUtilsKt {
17+
public static final fun getComposeColor-mxwnekA (Landroid/content/res/TypedArray;IJ)J
18+
public static synthetic fun getComposeColor-mxwnekA$default (Landroid/content/res/TypedArray;IJILjava/lang/Object;)J
19+
public static final fun getCornerSizeOrNull (Landroid/content/res/TypedArray;I)Landroidx/compose/foundation/shape/CornerSize;
20+
public static final fun getFontFamilyOrNull (Landroid/content/res/TypedArray;I)Lcom/google/android/material/composethemeadapter/core/FontFamilyWithWeight;
21+
public static final fun getTextUnit-lGoEivg (Landroid/content/res/TypedArray;ILandroidx/compose/ui/unit/Density;J)J
22+
public static synthetic fun getTextUnit-lGoEivg$default (Landroid/content/res/TypedArray;ILandroidx/compose/ui/unit/Density;JILjava/lang/Object;)J
23+
public static final fun getTextUnitOrNull (Landroid/content/res/TypedArray;ILandroidx/compose/ui/unit/Density;)Landroidx/compose/ui/unit/TextUnit;
24+
public static final fun parseShapeAppearance (Landroid/content/Context;ILandroidx/compose/foundation/shape/CornerBasedShape;Landroidx/compose/ui/unit/LayoutDirection;)Landroidx/compose/foundation/shape/CornerBasedShape;
25+
public static final fun textStyleFromTextAppearance (Landroid/content/Context;Landroidx/compose/ui/unit/Density;IZLandroidx/compose/ui/text/font/FontFamily;)Landroidx/compose/ui/text/TextStyle;
26+
}
27+

core/build.gradle

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.google.android.material.composethemeadapter.Libs
18+
19+
plugins {
20+
id 'com.android.library'
21+
id 'kotlin-android'
22+
id 'org.jetbrains.dokka'
23+
}
24+
25+
android {
26+
compileSdkVersion 33
27+
28+
defaultConfig {
29+
minSdkVersion 21
30+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31+
}
32+
33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
38+
buildFeatures {
39+
compose true
40+
buildConfig false
41+
}
42+
43+
composeOptions {
44+
kotlinCompilerExtensionVersion Libs.AndroidX.Compose.compilerVersion
45+
}
46+
}
47+
48+
dependencies {
49+
api Libs.Kotlin.stdlib
50+
api Libs.AndroidX.coreKtx
51+
api Libs.AndroidX.appcompat
52+
api Libs.mdc
53+
api Libs.AndroidX.Compose.runtime
54+
api Libs.AndroidX.Compose.foundation
55+
56+
androidTestImplementation Libs.junit
57+
androidTestImplementation Libs.AndroidX.Compose.test
58+
androidTestImplementation Libs.AndroidX.Test.rules
59+
androidTestImplementation Libs.AndroidX.Test.runner
60+
}

core/src/main/AndroidManifest.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--
2+
~ Copyright 2020 The Android Open Source Project
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ https://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<manifest package="com.google.android.material.composethemeadapter.core">
18+
</manifest>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.android.material.composethemeadapter
17+
package com.google.android.material.composethemeadapter.core
1818

1919
import android.annotation.SuppressLint
2020
import android.content.Context
@@ -49,7 +49,7 @@ import androidx.core.content.res.getColorOrThrow
4949
import androidx.core.content.res.use
5050
import kotlin.concurrent.getOrSet
5151

52-
internal fun textStyleFromTextAppearance(
52+
fun textStyleFromTextAppearance(
5353
context: Context,
5454
density: Density,
5555
@StyleRes id: Int,
@@ -134,7 +134,7 @@ internal fun textStyleFromTextAppearance(
134134
}
135135
}
136136

137-
internal fun parseShapeAppearance(
137+
fun parseShapeAppearance(
138138
context: Context,
139139
@StyleRes id: Int,
140140
fallbackShape: CornerBasedShape,
@@ -190,7 +190,7 @@ internal fun parseShapeAppearance(
190190

191191
private val tempTypedValue = ThreadLocal<TypedValue>()
192192

193-
internal fun TypedArray.getComposeColor(
193+
fun TypedArray.getComposeColor(
194194
index: Int,
195195
fallbackColor: Color = Color.Unspecified
196196
): Color = if (hasValue(index)) Color(getColorOrThrow(index)) else fallbackColor
@@ -201,7 +201,7 @@ internal fun TypedArray.getComposeColor(
201201
*
202202
* @param index index of attribute to retrieve.
203203
*/
204-
internal fun TypedArray.getFontFamilyOrNull(index: Int): FontFamilyWithWeight? {
204+
fun TypedArray.getFontFamilyOrNull(index: Int): FontFamilyWithWeight? {
205205
val tv = tempTypedValue.getOrSet(::TypedValue)
206206
if (getValue(index, tv) && tv.type == TypedValue.TYPE_STRING) {
207207
return when (tv.string) {
@@ -272,7 +272,7 @@ private fun fontWeightOf(weight: Int): FontWeight = when (weight) {
272272
else -> FontWeight.W400
273273
}
274274

275-
internal data class FontFamilyWithWeight(
275+
data class FontFamilyWithWeight(
276276
val fontFamily: FontFamily,
277277
val weight: FontWeight = FontWeight.Normal
278278
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2020 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<resources>
19+
20+
<declare-styleable name="ComposeThemeAdapterTextAppearance">
21+
<attr name="android:textColor" />
22+
<attr name="android:textSize" />
23+
<attr name="android:textStyle" />
24+
<attr name="android:textFontWeight" />
25+
<attr name="android:typeface" />
26+
<attr name="android:shadowColor" />
27+
<attr name="android:shadowDx" />
28+
<attr name="android:shadowDy" />
29+
<attr name="android:shadowRadius" />
30+
<attr name="lineHeight" />
31+
<attr name="android:lineHeight" />
32+
<attr name="android:letterSpacing" />
33+
<attr name="android:fontFeatureSettings" />
34+
<attr name="android:fontFamily" />
35+
<attr name="fontFamily" />
36+
<!-- TODOs below -->
37+
<attr name="android:fontVariationSettings" />
38+
</declare-styleable>
39+
40+
<declare-styleable name="ComposeThemeAdapterShapeAppearance">
41+
<attr name="cornerSize" />
42+
<attr name="cornerSizeTopLeft" />
43+
<attr name="cornerSizeTopRight" />
44+
<attr name="cornerSizeBottomRight" />
45+
<attr name="cornerSizeBottomLeft" />
46+
<attr name="cornerFamily" />
47+
</declare-styleable>
48+
49+
</resources>

material3Lib/api/material3Lib.api

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
public final class com/google/android/material/composethemeadapter3/FontFamilyWithWeight {
2-
public fun <init> (Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;)V
3-
public synthetic fun <init> (Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
4-
public final fun component1 ()Landroidx/compose/ui/text/font/FontFamily;
5-
public final fun component2 ()Landroidx/compose/ui/text/font/FontWeight;
6-
public final fun copy (Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;)Lcom/google/android/material/composethemeadapter3/FontFamilyWithWeight;
7-
public static synthetic fun copy$default (Lcom/google/android/material/composethemeadapter3/FontFamilyWithWeight;Landroidx/compose/ui/text/font/FontFamily;Landroidx/compose/ui/text/font/FontWeight;ILjava/lang/Object;)Lcom/google/android/material/composethemeadapter3/FontFamilyWithWeight;
8-
public fun equals (Ljava/lang/Object;)Z
9-
public final fun getFontFamily ()Landroidx/compose/ui/text/font/FontFamily;
10-
public final fun getWeight ()Landroidx/compose/ui/text/font/FontWeight;
11-
public fun hashCode ()I
12-
public fun toString ()Ljava/lang/String;
13-
}
14-
151
public final class com/google/android/material/composethemeadapter3/Mdc3Theme {
162
public static final fun Mdc3Theme (Landroid/content/Context;ZZZZZLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
173
public static final fun createMdc3Theme (Landroid/content/Context;Landroidx/compose/ui/unit/LayoutDirection;Landroidx/compose/ui/unit/Density;ZZZZZ)Lcom/google/android/material/composethemeadapter3/Theme3Parameters;
@@ -34,15 +20,3 @@ public final class com/google/android/material/composethemeadapter3/Theme3Parame
3420
public fun toString ()Ljava/lang/String;
3521
}
3622

37-
public final class com/google/android/material/composethemeadapter3/TypedArrayUtilsKt {
38-
public static final fun getComposeColor-mxwnekA (Landroid/content/res/TypedArray;IJ)J
39-
public static synthetic fun getComposeColor-mxwnekA$default (Landroid/content/res/TypedArray;IJILjava/lang/Object;)J
40-
public static final fun getCornerSizeOrNull (Landroid/content/res/TypedArray;I)Landroidx/compose/foundation/shape/CornerSize;
41-
public static final fun getFontFamilyOrNull (Landroid/content/res/TypedArray;I)Lcom/google/android/material/composethemeadapter3/FontFamilyWithWeight;
42-
public static final fun getTextUnit-lGoEivg (Landroid/content/res/TypedArray;ILandroidx/compose/ui/unit/Density;J)J
43-
public static synthetic fun getTextUnit-lGoEivg$default (Landroid/content/res/TypedArray;ILandroidx/compose/ui/unit/Density;JILjava/lang/Object;)J
44-
public static final fun getTextUnitOrNull (Landroid/content/res/TypedArray;ILandroidx/compose/ui/unit/Density;)Landroidx/compose/ui/unit/TextUnit;
45-
public static final fun parseShapeAppearance (Landroid/content/Context;ILandroidx/compose/foundation/shape/CornerBasedShape;Landroidx/compose/ui/unit/LayoutDirection;)Landroidx/compose/foundation/shape/CornerBasedShape;
46-
public static final fun textStyleFromTextAppearance (Landroid/content/Context;Landroidx/compose/ui/unit/Density;IZLandroidx/compose/ui/text/font/FontFamily;)Landroidx/compose/ui/text/TextStyle;
47-
}
48-

material3Lib/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,9 @@ android {
6060
}
6161

6262
dependencies {
63-
api Libs.AndroidX.appcompat
64-
implementation Libs.AndroidX.coreKtx
65-
implementation Libs.AndroidX.Compose.runtime
66-
implementation Libs.AndroidX.Compose.ui
67-
implementation Libs.AndroidX.Compose.material3
68-
69-
implementation 'com.google.android.material:material:1.7.0-rc01'
63+
implementation(project(':core'))
7064

71-
implementation Libs.Kotlin.stdlib
65+
implementation Libs.AndroidX.Compose.material3
7266

7367
androidTestImplementation Libs.junit
7468
androidTestImplementation Libs.AndroidX.Compose.test

0 commit comments

Comments
 (0)