From 874069354d723099641b70b05aa8ed7b53b246ac Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Fri, 12 Mar 2021 16:26:43 -0600 Subject: [PATCH] Add compose theme adapter --- app/build.gradle.kts | 1 + app/licenses.yml | 6 +++ app/src/main/assets/licenses.json | 14 +++++++ .../caldav/CaldavCalendarSettingsActivity.kt | 5 ++- app/src/main/java/org/tasks/themes/Theme.kt | 39 +------------------ deps_fdroid.txt | 15 +++++-- deps_googleplay.txt | 15 +++++-- 7 files changed, 47 insertions(+), 48 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 87595a837..addc78fdf 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -233,6 +233,7 @@ dependencies { implementation("androidx.compose.foundation:foundation:${Versions.compose}") implementation("androidx.compose.material:material:${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}") googleplayImplementation("com.google.firebase:firebase-crashlytics:${Versions.crashlytics}") diff --git a/app/licenses.yml b/app/licenses.yml index 1934be04a..612b3b1e6 100644 --- a/app/licenses.yml +++ b/app/licenses.yml @@ -938,3 +938,9 @@ license: The Apache Software License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt 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/ diff --git a/app/src/main/assets/licenses.json b/app/src/main/assets/licenses.json index 9422619f0..e1001f857 100644 --- a/app/src/main/assets/licenses.json +++ b/app/src/main/assets/licenses.json @@ -2229,6 +2229,20 @@ "normalizedLicense": "apache2", "url": "https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0-beta01", "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" } ] } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.kt b/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.kt index 212061b53..3d8d3ecc7 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.kt +++ b/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.kt @@ -11,6 +11,7 @@ import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.res.painterResource import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope +import com.google.android.material.composethemeadapter.MdcTheme import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch import org.tasks.R @@ -55,7 +56,7 @@ class CaldavCalendarSettingsActivity : BaseCaldavCalendarSettingsActivity() { findViewById(R.id.people) .apply { isVisible = it.isNotEmpty() } .setContent { - tasksTheme.TasksTheme { + MdcTheme { PrincipalList(it, if (canRemovePrincipals) this::onRemove else null) } } @@ -65,7 +66,7 @@ class CaldavCalendarSettingsActivity : BaseCaldavCalendarSettingsActivity() { findViewById(R.id.fab) .apply { isVisible = true } .setContent { - tasksTheme.TasksTheme { + MdcTheme { val openDialog = rememberSaveable { mutableStateOf(false) } ShareInviteDialog( openDialog, diff --git a/app/src/main/java/org/tasks/themes/Theme.kt b/app/src/main/java/org/tasks/themes/Theme.kt index 636a8bc89..4caf46c59 100644 --- a/app/src/main/java/org/tasks/themes/Theme.kt +++ b/app/src/main/java/org/tasks/themes/Theme.kt @@ -4,52 +4,15 @@ import android.app.Activity import android.content.Context import android.graphics.PixelFormat 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 javax.inject.Inject class Theme @Inject constructor( - @ActivityContext val context: Context, val themeBase: ThemeBase, val themeColor: ThemeColor, private val themeAccent: ThemeAccent ) { - private val darkTheme = themeBase.isDarkTheme(context as Activity) - - @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 withThemeColor(themeColor: ThemeColor) = Theme(themeBase, themeColor, themeAccent) fun getLayoutInflater(context: Context) = wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater diff --git a/deps_fdroid.txt b/deps_fdroid.txt index f2a751f5d..4cc7d5db8 100644 --- a/deps_fdroid.txt +++ b/deps_fdroid.txt @@ -491,8 +491,15 @@ +| +--- androidx.compose.animation:animation:1.0.0-beta02 (*) +| +--- androidx.compose.foundation:foundation-layout: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.lifecycle:lifecycle-livedata:2.2.0 (*) -+ +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*) -+ \--- androidx.compose.ui:ui:1.0.0-beta02 (*) ++ +--- androidx.compose.material:material:1.0.0-beta02 (*) ++ +--- com.google.android.material:material:1.1.0 -> 1.3.0 (*) ++ \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*) diff --git a/deps_googleplay.txt b/deps_googleplay.txt index 3067e26ac..54c7298c5 100644 --- a/deps_googleplay.txt +++ b/deps_googleplay.txt @@ -605,8 +605,15 @@ +| +--- androidx.compose.animation:animation:1.0.0-beta02 (*) +| +--- androidx.compose.foundation:foundation-layout: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.lifecycle:lifecycle-livedata:2.2.0 (*) -+ +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*) -+ \--- androidx.compose.ui:ui:1.0.0-beta02 (*) ++ +--- androidx.compose.material:material:1.0.0-beta02 (*) ++ +--- com.google.android.material:material:1.1.0 -> 1.3.0 (*) ++ \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.31 (*)