diff --git a/app/build.gradle b/app/build.gradle index e47d19f5..5ff4a5a4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,24 +52,12 @@ dependencies { implementation "androidx.compose.foundation:foundation-layout:$compose_version" implementation "androidx.compose.foundation:foundation-text:$compose_version" implementation "androidx.compose.runtime:runtime:$compose_version" - implementation "androidx.compose.runtime:runtime-dispatch:$compose_version" - implementation "androidx.compose.runtime:runtime-livedata:$compose_version" - implementation "androidx.compose.runtime:runtime-rxjava2:$compose_version" - implementation "androidx.compose.runtime:runtime-saved-instance-state:$compose_version" implementation "androidx.compose.material:material:$compose_version" - implementation "androidx.compose.material:material-icons-core:$compose_version" - implementation "androidx.compose.material:material-icons-extended:$compose_version" implementation "androidx.compose:compose-compiler:$compose_version" implementation "androidx.compose.ui:ui:$compose_version" - implementation "androidx.compose.ui:ui-geometry:$compose_version" - implementation "androidx.compose.ui:ui-graphics:$compose_version" implementation "androidx.compose.ui:ui-text:$compose_version" implementation "androidx.compose.ui:ui-text-android:$compose_version" implementation "androidx.compose.ui:ui-unit:$compose_version" - implementation "androidx.compose.ui:ui-util:$compose_version" - implementation "androidx.compose.ui:ui-viewbinding:$compose_version" - implementation "androidx.compose.animation:animation:$compose_version" - implementation "androidx.compose.animation:animation-core:$compose_version" implementation "androidx.ui:ui-tooling:$compose_version" testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.2-alpha05' diff --git a/app/src/main/java/dev/msfjarvis/todo/MainActivity.kt b/app/src/main/java/dev/msfjarvis/todo/MainActivity.kt index a3a21b8e..79261adc 100644 --- a/app/src/main/java/dev/msfjarvis/todo/MainActivity.kt +++ b/app/src/main/java/dev/msfjarvis/todo/MainActivity.kt @@ -2,7 +2,6 @@ package dev.msfjarvis.todo import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import androidx.compose.foundation.Icon import androidx.compose.foundation.Text import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumnFor @@ -10,8 +9,6 @@ import androidx.compose.material.FloatingActionButton import androidx.compose.material.MaterialTheme import androidx.compose.material.Scaffold import androidx.compose.material.TopAppBar -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ExposurePlus1 import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateListOf import androidx.compose.ui.Modifier @@ -20,6 +17,7 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTag import androidx.compose.ui.unit.dp import androidx.ui.tooling.preview.Preview +import dev.msfjarvis.todo.compose.utils.IconResource import dev.msfjarvis.todo.data.model.TodoItem import dev.msfjarvis.todo.ui.TodoRowItem import dev.msfjarvis.todo.ui.TodoTheme @@ -49,7 +47,10 @@ fun TodoApp() { elevation = 8.dp, modifier = Modifier.semantics { testTag = "fab" } ) { - Icon(asset = Icons.Filled.ExposurePlus1, tint = MaterialTheme.colors.onSurface) + IconResource( + resourceId = R.drawable.ic_exposure_plus_1_24dp, + tint = MaterialTheme.colors.onSurface, + ) } }, bodyContent = { diff --git a/app/src/main/java/dev/msfjarvis/todo/compose/utils/DeferredIcon.kt b/app/src/main/java/dev/msfjarvis/todo/compose/utils/DeferredIcon.kt new file mode 100644 index 00000000..99b6023a --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/todo/compose/utils/DeferredIcon.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package dev.msfjarvis.todo.compose.utils + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.Icon +import androidx.compose.foundation.contentColor +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.DeferredResource +import androidx.compose.ui.res.loadVectorResource + +@Composable +fun IconResource( + @DrawableRes resourceId: Int, + modifier: Modifier = Modifier, + tint: Color = contentColor() +) { + val deferredResource = loadVectorResource(resourceId) + deferredResource.onLoadRun { asset -> + Icon(asset = asset, modifier = modifier, tint = tint) + } +} + +inline fun DeferredResource.onLoadRun(block: (T) -> Unit) { + val res = resource.resource + if (res != null) { + block(res) + } +} diff --git a/app/src/main/res/drawable/ic_exposure_plus_1_24dp.xml b/app/src/main/res/drawable/ic_exposure_plus_1_24dp.xml new file mode 100644 index 00000000..9a7d92f1 --- /dev/null +++ b/app/src/main/res/drawable/ic_exposure_plus_1_24dp.xml @@ -0,0 +1,9 @@ + + +