mirror of
https://github.com/revanced/revanced-manager-compose-old.git
synced 2025-04-29 22:14:28 +02:00
fix: crash caused by missing packages
This commit is contained in:
parent
0a5dfa906f
commit
e240c6b77c
@ -3,8 +3,14 @@ package app.revanced.manager.ui.component
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Android
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||
|
||||
@ -14,9 +20,18 @@ fun AppIcon(
|
||||
contentDescription: String?,
|
||||
size: Int = 48
|
||||
) {
|
||||
var image: Painter = rememberVectorPainter(Icons.Outlined.Android)
|
||||
var colorFilter: ColorFilter? = ColorFilter.tint(LocalContentColor.current)
|
||||
|
||||
if (drawable != null) {
|
||||
image = rememberDrawablePainter(drawable)
|
||||
colorFilter = null
|
||||
}
|
||||
|
||||
Image(
|
||||
rememberDrawablePainter(drawable),
|
||||
image,
|
||||
contentDescription,
|
||||
Modifier.size(size.dp)
|
||||
Modifier.size(size.dp),
|
||||
colorFilter = colorFilter
|
||||
)
|
||||
}
|
@ -19,6 +19,7 @@ import app.revanced.manager.ui.component.ApplicationItem
|
||||
import app.revanced.manager.ui.component.ApplicationItemDualTint
|
||||
import app.revanced.manager.ui.component.HeadlineWithCard
|
||||
import app.revanced.manager.ui.viewmodel.DashboardViewModel
|
||||
import app.revanced.manager.util.loadIcon
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -89,7 +90,11 @@ fun DashboardScreen(viewModel: DashboardViewModel = getViewModel()) {
|
||||
ApplicationItem(
|
||||
appName = "Compose Manager",
|
||||
appIcon = {
|
||||
AppIcon(drawable = LocalContext.current.packageManager.getApplicationIcon("app.revanced.manager.compose"), contentDescription = null, size = 38)
|
||||
AppIcon(
|
||||
drawable = context.loadIcon("app.revanced.manager.compose"),
|
||||
contentDescription = null,
|
||||
size = 38
|
||||
)
|
||||
},
|
||||
releaseAgo = "9d ago"
|
||||
) {
|
||||
@ -102,7 +107,13 @@ fun DashboardScreen(viewModel: DashboardViewModel = getViewModel()) {
|
||||
ApplicationItemDualTint(
|
||||
appName = "Flutter Manager",
|
||||
releaseAgo = "9d ago",
|
||||
appIcon = { AppIcon(drawable = LocalContext.current.packageManager.getApplicationIcon("app.revanced.manager.flutter"), contentDescription = null, size = 38) }
|
||||
appIcon = {
|
||||
AppIcon(
|
||||
drawable = context.loadIcon("app.revanced.manager.flutter"),
|
||||
contentDescription = null,
|
||||
size = 38
|
||||
)
|
||||
}
|
||||
) {
|
||||
ChangelogText(
|
||||
"""
|
||||
|
@ -1,12 +1,6 @@
|
||||
package app.revanced.manager.ui.screen
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Build
|
||||
import androidx.compose.material3.*
|
||||
@ -22,6 +16,7 @@ import app.revanced.manager.ui.component.AppIcon
|
||||
import app.revanced.manager.ui.component.FloatingActionButton
|
||||
import app.revanced.manager.ui.component.SplitAPKDialog
|
||||
import app.revanced.manager.ui.viewmodel.PatcherScreenViewModel
|
||||
import app.revanced.manager.util.loadIcon
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -36,6 +31,8 @@ fun PatcherScreen(
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
val hasAppSelected by mutableStateOf(vm.selectedAppPackage.isPresent)
|
||||
val patchesLoaded by mutableStateOf(vm.patchesLoaded is Resource.Success)
|
||||
val context = LocalContext.current
|
||||
|
||||
Scaffold(
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(
|
||||
@ -84,9 +81,8 @@ fun PatcherScreen(
|
||||
) {
|
||||
if (vm.selectedAppPackage.isPresent) {
|
||||
AppIcon(
|
||||
LocalContext.current.packageManager.getApplicationIcon(
|
||||
vm.selectedAppPackage.get().packageName
|
||||
), contentDescription = null, size = 18
|
||||
context.loadIcon(vm.selectedAppPackage.get().packageName),
|
||||
contentDescription = null, size = 18
|
||||
)
|
||||
Spacer(Modifier.width(5.dp))
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package app.revanced.manager.util
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
@ -17,6 +19,14 @@ fun Context.openUrl(url: String) {
|
||||
})
|
||||
}
|
||||
|
||||
fun Context.loadIcon(string: String): Drawable? {
|
||||
return try {
|
||||
packageManager.getApplicationIcon(string)
|
||||
} catch (e: NameNotFoundException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.requestAllFilesAccess() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
startActivity(Intent(
|
||||
|
Loading…
x
Reference in New Issue
Block a user