From 0c883ddfd66914e5ba8c28f207089bca862ee066 Mon Sep 17 00:00:00 2001 From: rifsxd Date: Fri, 6 Jun 2025 04:09:16 +0600 Subject: [PATCH] manager: let module banner be set locally from module dir ex: banner=banner.png , banner=example.webp banner=temp/hello.jpg if banner string value starts with http, https then it will try to fetch from online. Co-authored-by: fatalcoder524 <11532648+fatalcoder524@users.noreply.github.com> --- .../com/rifsxd/ksunext/ui/screen/Module.kt | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt index 01422143..6b922e05 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt @@ -102,6 +102,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import coil.compose.AsyncImage +import coil.request.ImageRequest import com.rifsxd.ksunext.Natives import com.rifsxd.ksunext.R import com.rifsxd.ksunext.ksuApp @@ -122,6 +123,7 @@ import com.rifsxd.ksunext.ui.viewmodel.ModuleViewModel import com.rifsxd.ksunext.ui.webui.WebUIActivity import com.rifsxd.ksunext.ui.webui.WebUIXActivity import com.dergoogler.mmrl.ui.component.LabelItem +import com.topjohnwu.superuser.io.SuFile @OptIn(ExperimentalMaterial3Api::class) @Destination @@ -716,15 +718,39 @@ fun ModuleItem( .matchParentSize(), contentAlignment = Alignment.Center ) { - AsyncImage( - model = module.banner, - contentDescription = null, - modifier = Modifier - .fillMaxWidth() - .fillMaxHeight(), - contentScale = ContentScale.Crop, - alpha = 0.18f - ) + if (module.banner.startsWith("https", true) || module.banner.startsWith("http", true)) { + AsyncImage( + model = module.banner, + contentDescription = null, + modifier = Modifier + .fillMaxWidth() + .fillMaxHeight(), + contentScale = ContentScale.Crop, + alpha = 0.18f + ) + } else { + val bannerData = remember(module.banner) { + try { + val file = SuFile("/data/adb/modules/${module.id}/${module.banner}") + file.newInputStream().use { it.readBytes() } + } catch (e: Exception) { + null + } + } + if (bannerData != null) { + AsyncImage( + model = ImageRequest.Builder(context) + .data(bannerData) + .build(), + contentDescription = null, + modifier = Modifier + .fillMaxWidth() + .fillMaxHeight(), + contentScale = ContentScale.Crop, + alpha = 0.18f + ) + } + } Box( modifier = Modifier .fillMaxWidth() @@ -742,7 +768,6 @@ fun ModuleItem( ) } } - Column { val textDecoration = if (!module.remove) null else TextDecoration.LineThrough val interactionSource = remember { MutableInteractionSource() }