Add compose theme adapter

pull/1412/head
Alex Baker 5 years ago
parent aa4f648505
commit 874069354d

@ -233,6 +233,7 @@ dependencies {
implementation("androidx.compose.foundation:foundation:${Versions.compose}") implementation("androidx.compose.foundation:foundation:${Versions.compose}")
implementation("androidx.compose.material:material:${Versions.compose}") implementation("androidx.compose.material:material:${Versions.compose}")
implementation("androidx.compose.runtime:runtime-livedata:${Versions.compose}") implementation("androidx.compose.runtime:runtime-livedata:${Versions.compose}")
implementation("com.google.android.material:compose-theme-adapter:${Versions.compose}")
releaseCompileOnly("androidx.compose.ui:ui-tooling:${Versions.compose}") releaseCompileOnly("androidx.compose.ui:ui-tooling:${Versions.compose}")
googleplayImplementation("com.google.firebase:firebase-crashlytics:${Versions.crashlytics}") googleplayImplementation("com.google.firebase:firebase-crashlytics:${Versions.crashlytics}")

@ -938,3 +938,9 @@
license: The Apache Software License, Version 2.0 license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0-beta01 url: https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0-beta01
- artifact: com.google.android.material:compose-theme-adapter:+
name: compose-theme-adapter
copyrightHolder: Android Open Source Project
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/material-components/material-components-android-compose-theme-adapter/

@ -2229,6 +2229,20 @@
"normalizedLicense": "apache2", "normalizedLicense": "apache2",
"url": "https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0-beta01", "url": "https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0-beta01",
"libraryName": "runtime-livedata" "libraryName": "runtime-livedata"
},
{
"artifactId": {
"name": "compose-theme-adapter",
"group": "com.google.android.material",
"version": "+"
},
"copyrightHolder": "Android Open Source Project",
"copyrightStatement": "Copyright © Android Open Source Project. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"url": "https://github.com/material-components/material-components-android-compose-theme-adapter/",
"libraryName": "compose-theme-adapter"
} }
] ]
} }

@ -11,6 +11,7 @@ import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.android.material.composethemeadapter.MdcTheme
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.tasks.R import org.tasks.R
@ -55,7 +56,7 @@ class CaldavCalendarSettingsActivity : BaseCaldavCalendarSettingsActivity() {
findViewById<ComposeView>(R.id.people) findViewById<ComposeView>(R.id.people)
.apply { isVisible = it.isNotEmpty() } .apply { isVisible = it.isNotEmpty() }
.setContent { .setContent {
tasksTheme.TasksTheme { MdcTheme {
PrincipalList(it, if (canRemovePrincipals) this::onRemove else null) PrincipalList(it, if (canRemovePrincipals) this::onRemove else null)
} }
} }
@ -65,7 +66,7 @@ class CaldavCalendarSettingsActivity : BaseCaldavCalendarSettingsActivity() {
findViewById<ComposeView>(R.id.fab) findViewById<ComposeView>(R.id.fab)
.apply { isVisible = true } .apply { isVisible = true }
.setContent { .setContent {
tasksTheme.TasksTheme { MdcTheme {
val openDialog = rememberSaveable { mutableStateOf(false) } val openDialog = rememberSaveable { mutableStateOf(false) }
ShareInviteDialog( ShareInviteDialog(
openDialog, openDialog,

@ -4,52 +4,15 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.graphics.PixelFormat import android.graphics.PixelFormat
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.core.content.ContextCompat
import dagger.hilt.android.qualifiers.ActivityContext
import org.tasks.R import org.tasks.R
import javax.inject.Inject import javax.inject.Inject
class Theme @Inject constructor( class Theme @Inject constructor(
@ActivityContext val context: Context,
val themeBase: ThemeBase, val themeBase: ThemeBase,
val themeColor: ThemeColor, val themeColor: ThemeColor,
private val themeAccent: ThemeAccent private val themeAccent: ThemeAccent
) { ) {
private val darkTheme = themeBase.isDarkTheme(context as Activity) fun withThemeColor(themeColor: ThemeColor) = Theme(themeBase, themeColor, themeAccent)
@Composable
fun TasksTheme(
content: @Composable () -> Unit,
) {
val primary = Color(themeColor.primaryColor)
val onPrimary = Color(themeColor.colorOnPrimary)
val secondary = Color(themeAccent.accentColor)
MaterialTheme(
colors = if (darkTheme) {
darkColors(
primary = primary,
onPrimary = onPrimary,
secondary = secondary,
background = Color(ContextCompat.getColor(context, R.color.window_background)),
surface = Color(ContextCompat.getColor(context, R.color.content_background)),
)
} else {
lightColors(
primary = primary,
onPrimary = onPrimary,
secondary = secondary,
)
},
content = content
)
}
fun withThemeColor(themeColor: ThemeColor) = Theme(context, themeBase, themeColor, themeAccent)
fun getLayoutInflater(context: Context) = fun getLayoutInflater(context: Context) =
wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

@ -491,8 +491,15 @@
+| +--- androidx.compose.animation:animation:1.0.0-beta02 (*) +| +--- androidx.compose.animation:animation:1.0.0-beta02 (*)
+| +--- androidx.compose.foundation:foundation-layout:1.0.0-beta02 (*) +| +--- androidx.compose.foundation:foundation-layout:1.0.0-beta02 (*)
+| \--- androidx.compose.ui:ui-util:1.0.0-beta02 (*) +| \--- androidx.compose.ui:ui-util:1.0.0-beta02 (*)
+\--- androidx.compose.runtime:runtime-livedata:1.0.0-beta02 ++--- androidx.compose.runtime:runtime-livedata:1.0.0-beta02
+| +--- androidx.compose.runtime:runtime:1.0.0-beta02 (*)
+| +--- androidx.lifecycle:lifecycle-livedata:2.2.0 (*)
+| +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*)
+| \--- androidx.compose.ui:ui:1.0.0-beta02 (*)
+\--- com.google.android.material:compose-theme-adapter:1.0.0-beta02
+ +--- androidx.appcompat:appcompat:1.3.0-beta01 (*)
+ +--- androidx.core:core-ktx:1.3.1 -> 1.3.2 (*)
+ +--- androidx.compose.runtime:runtime:1.0.0-beta02 (*) + +--- androidx.compose.runtime:runtime:1.0.0-beta02 (*)
+ +--- androidx.lifecycle:lifecycle-livedata:2.2.0 (*) + +--- androidx.compose.material:material:1.0.0-beta02 (*)
+ +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*) + +--- com.google.android.material:material:1.1.0 -> 1.3.0 (*)
+ \--- androidx.compose.ui:ui:1.0.0-beta02 (*) + \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*)

@ -605,8 +605,15 @@
+| +--- androidx.compose.animation:animation:1.0.0-beta02 (*) +| +--- androidx.compose.animation:animation:1.0.0-beta02 (*)
+| +--- androidx.compose.foundation:foundation-layout:1.0.0-beta02 (*) +| +--- androidx.compose.foundation:foundation-layout:1.0.0-beta02 (*)
+| \--- androidx.compose.ui:ui-util:1.0.0-beta02 (*) +| \--- androidx.compose.ui:ui-util:1.0.0-beta02 (*)
+\--- androidx.compose.runtime:runtime-livedata:1.0.0-beta02 ++--- androidx.compose.runtime:runtime-livedata:1.0.0-beta02
+| +--- androidx.compose.runtime:runtime:1.0.0-beta02 (*)
+| +--- androidx.lifecycle:lifecycle-livedata:2.2.0 (*)
+| +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*)
+| \--- androidx.compose.ui:ui:1.0.0-beta02 (*)
+\--- com.google.android.material:compose-theme-adapter:1.0.0-beta02
+ +--- androidx.appcompat:appcompat:1.3.0-beta01 (*)
+ +--- androidx.core:core-ktx:1.3.1 -> 1.3.2 (*)
+ +--- androidx.compose.runtime:runtime:1.0.0-beta02 (*) + +--- androidx.compose.runtime:runtime:1.0.0-beta02 (*)
+ +--- androidx.lifecycle:lifecycle-livedata:2.2.0 (*) + +--- androidx.compose.material:material:1.0.0-beta02 (*)
+ +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*) + +--- com.google.android.material:material:1.1.0 -> 1.3.0 (*)
+ \--- androidx.compose.ui:ui:1.0.0-beta02 (*) + \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*)

Loading…
Cancel
Save