From 82879a129e12509223a05230ebeb884f103d0745 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sun, 19 Jun 2022 20:16:55 +0600 Subject: [PATCH] Make stub source icon part of `SourceIcon` (#7337) * Make stub source icon part of `SourceIcon` * Review Changes --- .../browse/MigrateSourceScreen.kt | 15 +------ .../browse/components/BrowseIcons.kt | 39 +++++++++++++------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt index 3f8dabda6..c81f1965f 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt @@ -1,6 +1,5 @@ package eu.kanade.presentation.browse -import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -16,10 +15,8 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -117,17 +114,7 @@ fun MigrateSourceItem( showLanguageInContent = source.lang != "", onClickItem = onClickItem, onLongClickItem = onLongClickItem, - icon = { - if (source.isStub) { - Image( - painter = painterResource(R.drawable.ic_warning_white_24dp), - contentDescription = "", - colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.error), - ) - } else { - SourceIcon(source = source) - } - }, + icon = { SourceIcon(source = source) }, action = { ItemBadges(primaryText = "$count") }, content = { source, showLanguageInContent -> Column( diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt index 59457aadd..8eda1586c 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt @@ -7,6 +7,9 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.height import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Warning +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.getValue @@ -14,6 +17,7 @@ import androidx.compose.runtime.produceState import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.ColorPainter @@ -40,18 +44,29 @@ fun SourceIcon( ) { val icon = source.icon - if (icon != null) { - Image( - bitmap = icon, - contentDescription = "", - modifier = modifier.then(defaultModifier), - ) - } else { - Image( - painter = painterResource(id = R.mipmap.ic_local_source), - contentDescription = "", - modifier = modifier.then(defaultModifier), - ) + when { + source.isStub && icon == null -> { + Image( + imageVector = Icons.Default.Warning, + contentDescription = "", + colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.error), + modifier = modifier.then(defaultModifier), + ) + } + icon != null -> { + Image( + bitmap = icon, + contentDescription = "", + modifier = modifier.then(defaultModifier), + ) + } + else -> { + Image( + painter = painterResource(id = R.mipmap.ic_local_source), + contentDescription = "", + modifier = modifier.then(defaultModifier), + ) + } } }