Skip to content

Commit e065104

Browse files
authored
Update MainActivity.kt
1 parent 6b78e28 commit e065104

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

app/src/main/kotlin/com/dev/debloater/MainActivity.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
4040
import androidx.compose.ui.Alignment
4141
import androidx.compose.ui.Modifier
4242
import androidx.compose.ui.draw.clip
43-
import androidx.compose.ui.graphics.ImageBitmap
4443
import androidx.compose.ui.layout.ContentScale
4544
import androidx.compose.ui.platform.LocalContext
4645
import androidx.compose.ui.res.stringResource
@@ -49,6 +48,7 @@ import androidx.compose.ui.text.style.TextOverflow
4948
import androidx.compose.ui.unit.dp
5049
import androidx.compose.material.icons.Icons
5150
import androidx.compose.material.icons.filled.*
51+
import coil.compose.rememberAsyncImagePainter
5252
import kotlinx.coroutines.Dispatchers
5353
import kotlinx.coroutines.launch
5454
import kotlinx.coroutines.withContext
@@ -101,8 +101,7 @@ data class AppData(
101101
val isSystem: Boolean,
102102
val isInstalled: Boolean,
103103
val isDisabled: Boolean,
104-
val safetyLevel: SafetyLevel,
105-
val icon: ImageBitmap? = null
104+
val safetyLevel: SafetyLevel
106105
)
107106

108107
data class ConfirmAction(
@@ -779,6 +778,17 @@ fun AppListItem(
779778
onUninstall: (AppData) -> Unit,
780779
onRestore: (AppData) -> Unit
781780
) {
781+
val context = LocalContext.current
782+
val appIcon by produceState<android.graphics.drawable.Drawable?>(
783+
initialValue = null,
784+
key1 = appData.packageName
785+
) {
786+
value = withContext(Dispatchers.IO) {
787+
runCatching { context.packageManager.getApplicationIcon(appData.packageName) }
788+
.getOrNull()
789+
}
790+
}
791+
782792
Surface(
783793
modifier = Modifier
784794
.fillMaxWidth()
@@ -797,9 +807,9 @@ fun AppListItem(
797807
modifier = Modifier.size(40.dp),
798808
contentAlignment = Alignment.Center
799809
) {
800-
if (appData.icon != null) {
810+
if (appIcon != null) {
801811
Image(
802-
bitmap = appData.icon,
812+
painter = rememberAsyncImagePainter(appIcon),
803813
contentDescription = null,
804814
modifier = Modifier.size(40.dp),
805815
contentScale = ContentScale.Fit
@@ -998,9 +1008,7 @@ private suspend fun loadAllAppDataWithIcons(
9981008
} ?: false,
9991009
isDisabled = appInfo?.enabled == false,
10001010
isInstalled = isInstalled,
1001-
safetyLevel = SafetyClassifier.classify(pkg.packageName),
1002-
// Avoid eagerly decoding every app icon into memory to prevent startup OOM crashes.
1003-
icon = null
1011+
safetyLevel = SafetyClassifier.classify(pkg.packageName)
10041012
)
10051013
}
10061014
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.appName })

0 commit comments

Comments
 (0)