Skip to content

Commit

Permalink
fix: make InstallOptions serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 16, 2024
1 parent 932c583 commit e2c9472
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Color, ColorParceler>
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 {
/**
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/aliucord/manager/util/ColorParceler.kt
Original file line number Diff line number Diff line change
@@ -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<Color> {
override fun create(parcel: Parcel): Color =
Color(parcel.readInt())

override fun Color.write(parcel: Parcel, flags: Int) =
parcel.writeInt(toArgb())
}

0 comments on commit e2c9472

Please sign in to comment.