mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Minor cleanups
Pulling out some of the smaller changes that aren't related to the manga controller changes in #7244
This commit is contained in:
@@ -24,7 +24,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import coil.compose.AsyncImage
|
||||
import eu.kanade.domain.source.model.Source
|
||||
import eu.kanade.presentation.util.bitmapPainterResource
|
||||
import eu.kanade.presentation.util.rememberResourceBitmapPainter
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.extension.model.Extension
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
@@ -67,7 +67,7 @@ fun ExtensionIcon(
|
||||
model = extension.iconUrl,
|
||||
contentDescription = "",
|
||||
placeholder = ColorPainter(Color(0x1F888888)),
|
||||
error = bitmapPainterResource(id = R.drawable.cover_error),
|
||||
error = rememberResourceBitmapPainter(id = R.drawable.cover_error),
|
||||
modifier = modifier
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.then(defaultModifier),
|
||||
|
||||
@@ -11,7 +11,7 @@ import androidx.compose.ui.graphics.painter.ColorPainter
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
import eu.kanade.presentation.util.bitmapPainterResource
|
||||
import eu.kanade.presentation.util.rememberResourceBitmapPainter
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
enum class MangaCover(private val ratio: Float) {
|
||||
@@ -28,7 +28,7 @@ enum class MangaCover(private val ratio: Float) {
|
||||
AsyncImage(
|
||||
model = data,
|
||||
placeholder = ColorPainter(CoverPlaceholderColor),
|
||||
error = bitmapPainterResource(id = R.drawable.cover_error),
|
||||
error = rememberResourceBitmapPainter(id = R.drawable.cover_error),
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier
|
||||
.aspectRatio(ratio)
|
||||
|
||||
@@ -3,15 +3,21 @@ package eu.kanade.presentation.components
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.google.accompanist.swiperefresh.SwipeRefreshState
|
||||
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator as AccompanistSwipeRefreshIndicator
|
||||
|
||||
@Composable
|
||||
fun SwipeRefreshIndicator(state: SwipeRefreshState, refreshTrigger: Dp) {
|
||||
fun SwipeRefreshIndicator(
|
||||
state: SwipeRefreshState,
|
||||
refreshTriggerDistance: Dp,
|
||||
refreshingOffset: Dp = 16.dp,
|
||||
) {
|
||||
AccompanistSwipeRefreshIndicator(
|
||||
state = state,
|
||||
refreshTriggerDistance = refreshTrigger,
|
||||
refreshTriggerDistance = refreshTriggerDistance,
|
||||
backgroundColor = MaterialTheme.colorScheme.primary,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimary,
|
||||
refreshingOffset = refreshingOffset,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.calculateEndPadding
|
||||
import androidx.compose.foundation.layout.calculateStartPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues {
|
||||
val layoutDirection = LocalLayoutDirection.current
|
||||
return PaddingValues(
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.content.res.Resources
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.PluralsRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -18,6 +20,7 @@ import androidx.core.graphics.drawable.toBitmap
|
||||
* @return the string data associated with the resource
|
||||
*/
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String {
|
||||
val context = LocalContext.current
|
||||
return context.resources.getQuantityString(id, quantity, quantity)
|
||||
@@ -32,6 +35,7 @@ fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String {
|
||||
* @return the string data associated with the resource
|
||||
*/
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any): String {
|
||||
val context = LocalContext.current
|
||||
return context.resources.getQuantityString(id, quantity, *formatArgs)
|
||||
@@ -46,9 +50,11 @@ fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs
|
||||
* @return the bitmap associated with the resource
|
||||
*/
|
||||
@Composable
|
||||
fun bitmapPainterResource(@DrawableRes id: Int): BitmapPainter {
|
||||
fun rememberResourceBitmapPainter(@DrawableRes id: Int): BitmapPainter {
|
||||
val context = LocalContext.current
|
||||
val drawable = ContextCompat.getDrawable(context, id)
|
||||
?: throw Resources.NotFoundException()
|
||||
return BitmapPainter(drawable.toBitmap().asImageBitmap())
|
||||
return remember(id) {
|
||||
val drawable = ContextCompat.getDrawable(context, id)
|
||||
?: throw Resources.NotFoundException()
|
||||
BitmapPainter(drawable.toBitmap().asImageBitmap())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user