Fix transformations for dynamic launcher icons
This commit is contained in:
parent
6152c566f0
commit
050e8284e7
@ -3,6 +3,7 @@ package de.mm20.launcher2.icons
|
|||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.graphics.drawable.AdaptiveIconDrawable
|
import android.graphics.drawable.AdaptiveIconDrawable
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import androidx.lifecycle.Transformations
|
||||||
import de.mm20.launcher2.icons.transformations.LauncherIconTransformation
|
import de.mm20.launcher2.icons.transformations.LauncherIconTransformation
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
@ -11,8 +12,8 @@ internal class DynamicCalendarIcon(
|
|||||||
val resources: Resources,
|
val resources: Resources,
|
||||||
val resourceIds: IntArray,
|
val resourceIds: IntArray,
|
||||||
val isThemed: Boolean = false,
|
val isThemed: Boolean = false,
|
||||||
private val transformations: List<LauncherIconTransformation> = emptyList(),
|
private var transformations: List<LauncherIconTransformation> = emptyList(),
|
||||||
) : DynamicLauncherIcon {
|
) : DynamicLauncherIcon, TransformableDynamicLauncherIcon {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (resourceIds.size < 31) throw IllegalArgumentException("DynamicCalendarIcon resourceIds must at least have 31 items")
|
if (resourceIds.size < 31) throw IllegalArgumentException("DynamicCalendarIcon resourceIds must at least have 31 items")
|
||||||
@ -67,4 +68,8 @@ internal class DynamicCalendarIcon(
|
|||||||
}
|
}
|
||||||
return icon
|
return icon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setTransformations(transformations: List<LauncherIconTransformation>) {
|
||||||
|
this.transformations = transformations
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package de.mm20.launcher2.icons
|
||||||
|
|
||||||
|
import de.mm20.launcher2.icons.transformations.LauncherIconTransformation
|
||||||
|
|
||||||
|
internal interface TransformableDynamicLauncherIcon {
|
||||||
|
fun setTransformations(transformations: List<LauncherIconTransformation>)
|
||||||
|
}
|
||||||
@ -2,17 +2,23 @@ package de.mm20.launcher2.icons.transformations
|
|||||||
|
|
||||||
import de.mm20.launcher2.icons.LauncherIcon
|
import de.mm20.launcher2.icons.LauncherIcon
|
||||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||||
|
import de.mm20.launcher2.icons.TransformableDynamicLauncherIcon
|
||||||
|
|
||||||
internal interface LauncherIconTransformation {
|
internal interface LauncherIconTransformation {
|
||||||
suspend fun transform(icon: StaticLauncherIcon): StaticLauncherIcon
|
suspend fun transform(icon: StaticLauncherIcon): StaticLauncherIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
internal suspend fun Iterable<LauncherIconTransformation>.apply(icon: LauncherIcon): LauncherIcon {
|
internal suspend fun Iterable<LauncherIconTransformation>.apply(icon: LauncherIcon): LauncherIcon {
|
||||||
var transformedIcon = icon
|
if (icon is StaticLauncherIcon) {
|
||||||
if (transformedIcon is StaticLauncherIcon) {
|
var transformedIcon = icon
|
||||||
for (transformation in this) {
|
for (transformation in this) {
|
||||||
transformedIcon = transformation.transform(transformedIcon as StaticLauncherIcon)
|
transformedIcon = transformation.transform(transformedIcon as StaticLauncherIcon)
|
||||||
}
|
}
|
||||||
|
return transformedIcon
|
||||||
}
|
}
|
||||||
return transformedIcon
|
if (icon is TransformableDynamicLauncherIcon) {
|
||||||
|
icon.setTransformations(this.toList())
|
||||||
|
return icon
|
||||||
|
}
|
||||||
|
return icon
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user