Merge "Fix crash when restoring data from phone to tablet with responsive grid" into main
This commit is contained in:
commit
7808efbba1
2 files changed
+38
-3
No files matched your search
@@ -40,13 +40,28 @@ class HotseatSpecsProvider(groupOfSpecs: List<ResponsiveSpecGroup<HotseatSpec>>)
|
||||
return specsGroup
|
||||
}
|
||||
|
||||
private fun getSpecIgnoringDimensionType(
|
||||
availableSize: Int,
|
||||
specsGroup: ResponsiveSpecGroup<HotseatSpec>
|
||||
): HotseatSpec? {
|
||||
val specWidth = specsGroup.widthSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
|
||||
val specHeight = specsGroup.heightSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
|
||||
return specWidth ?: specHeight
|
||||
}
|
||||
|
||||
fun getCalculatedSpec(
|
||||
aspectRatio: Float,
|
||||
dimensionType: DimensionType,
|
||||
availableSpace: Int
|
||||
availableSpace: Int,
|
||||
): CalculatedHotseatSpec {
|
||||
val specsGroup = getSpecsByAspectRatio(aspectRatio)
|
||||
val spec = specsGroup.getSpec(dimensionType, availableSpace)
|
||||
|
||||
// TODO(b/315548992): Ignore the dimension type to prevent crash before launcher
|
||||
// data migration is finished. The restore process allows the initialization of
|
||||
// an invalid or disabled grid until the data is restored and migrated.
|
||||
val spec = getSpecIgnoringDimensionType(availableSpace, specsGroup)
|
||||
check(spec != null) { "No available spec found within $availableSpace. $specsGroup" }
|
||||
// val spec = specsGroup.getSpec(dimensionType, availableSpace)
|
||||
return CalculatedHotseatSpec(availableSpace, spec)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.launcher3.responsive
|
||||
|
||||
import android.content.res.TypedArray
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
|
||||
import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
|
||||
|
||||
/**
|
||||
@@ -54,10 +55,29 @@ class ResponsiveSpecGroup<T : IResponsiveSpec>(
|
||||
} else {
|
||||
heightSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
|
||||
}
|
||||
check(spec != null) { "No available $type spec found within $availableSize." }
|
||||
check(spec != null) { "No available $type spec found within $availableSize. $this" }
|
||||
return spec
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
fun printSpec(spec: IResponsiveSpec) =
|
||||
when (spec.specType) {
|
||||
ResponsiveSpecType.AllApps,
|
||||
ResponsiveSpecType.Folder,
|
||||
ResponsiveSpecType.Workspace -> (spec as ResponsiveSpec).toString()
|
||||
ResponsiveSpecType.Hotseat -> (spec as HotseatSpec).toString()
|
||||
ResponsiveSpecType.Cell -> (spec as CellSpec).toString()
|
||||
}
|
||||
|
||||
val widthSpecsString = widthSpecs.joinToString(", ") { printSpec(it) }
|
||||
val heightSpecsString = heightSpecs.joinToString(", ") { printSpec(it) }
|
||||
return "ResponsiveSpecGroup(" +
|
||||
"aspectRatio=${aspectRatio}, " +
|
||||
"widthSpecs=[${widthSpecsString}], " +
|
||||
"heightSpecs=[${heightSpecsString}]" +
|
||||
")"
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val XML_GROUP_NAME = "specs"
|
||||
|
||||
|
||||
Reference in new issue
Block a user