diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt index 4b64c951..2975e73f 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt @@ -5,6 +5,7 @@ package com.aliucord.manager.ui.screens.install +import android.os.Parcelable import androidx.activity.compose.BackHandler import androidx.compose.foundation.* import androidx.compose.foundation.interaction.MutableInteractionSource @@ -30,9 +31,13 @@ import com.aliucord.manager.ui.components.back import com.aliucord.manager.ui.components.dialogs.InstallerAbortDialog import com.aliucord.manager.ui.screens.install.components.* import com.aliucord.manager.ui.screens.installopts.InstallOptions +import kotlinx.parcelize.IgnoredOnParcel +import kotlinx.parcelize.Parcelize import org.koin.core.parameter.parametersOf -class InstallScreen(private val data: InstallOptions) : Screen { +@Parcelize +class InstallScreen(private val data: InstallOptions) : Screen, Parcelable { + @IgnoredOnParcel override val key = "Install" @Composable diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/installopts/InstallOptions.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/installopts/InstallOptions.kt index 10ea91b6..646d6b39 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/installopts/InstallOptions.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/installopts/InstallOptions.kt @@ -1,9 +1,14 @@ package com.aliucord.manager.ui.screens.installopts +import android.os.Parcelable import androidx.compose.runtime.Immutable import androidx.compose.ui.graphics.Color +import com.aliucord.manager.util.ColorParceler +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.TypeParceler @Immutable +@Parcelize data class InstallOptions( /** * The app name that's user-facing in launchers. @@ -30,25 +35,39 @@ data class InstallOptions( * This is independent of [InstallOptions.iconReplacement] */ val monochromeIcon: Boolean, -) { +) : Parcelable { @Immutable - sealed interface IconReplacement { + @Parcelize + sealed interface IconReplacement : Parcelable { /** * Keeps the original icons that are present in the APK. */ + @Immutable + @Parcelize data object Original : IconReplacement /** - * Replaces the foreground image of the icon entirely and sets the background to transparent. - * This does not affect the monochrome icon. + * Changes the background of the icon to a specific color without + * altering the foreground or monochrome variants. */ - data class CustomImage(val imageBytes: ByteArray) : IconReplacement + @Immutable + @Parcelize + data class CustomColor( + @TypeParceler + val color: Color, + ) : IconReplacement /** - * Changes the background of the icon to a specific color without - * altering the foreground or monochrome variants. + * Replaces the foreground image of the icon entirely and sets the background to transparent. + * This does not affect the monochrome icon. */ - data class CustomColor(val color: Color) : IconReplacement + @Immutable + @Parcelize + data class CustomImage(val imageBytes: ByteArray) : IconReplacement { + override fun hashCode() = imageBytes.contentHashCode() + override fun equals(other: Any?) = this === other + || (javaClass == other?.javaClass && imageBytes.contentEquals((other as CustomImage).imageBytes)) + } companion object { /** diff --git a/app/src/main/kotlin/com/aliucord/manager/util/ColorParceler.kt b/app/src/main/kotlin/com/aliucord/manager/util/ColorParceler.kt new file mode 100644 index 00000000..ce540d9e --- /dev/null +++ b/app/src/main/kotlin/com/aliucord/manager/util/ColorParceler.kt @@ -0,0 +1,17 @@ +package com.aliucord.manager.util + +import android.os.Parcel +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb +import kotlinx.parcelize.Parceler + +/** + * Parcelize Compose [Color] for reading and writing in ARGB representation for the sRGB color space. + */ +object ColorParceler : Parceler { + override fun create(parcel: Parcel): Color = + Color(parcel.readInt()) + + override fun Color.write(parcel: Parcel, flags: Int) = + parcel.writeInt(toArgb()) +}