Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a7fed56 authored by George Lin's avatar George Lin Committed by Android (Google) Code Review
Browse files

Merge "Throw exception when options have multiple isCurrent" into main

parents 6ad9d987 8d7a5036
Loading
Loading
Loading
Loading
+67 −37
Original line number Diff line number Diff line
@@ -58,11 +58,16 @@ constructor(
                                            )
                                    add(
                                        GridOptionModel(
                                        key = cursor.getString(cursor.getColumnIndex(COL_GRID_KEY)),
                                            key =
                                                cursor.getString(
                                                    cursor.getColumnIndex(COL_GRID_KEY)
                                                ),
                                            title = title,
                                            isCurrent =
                                                cursor
                                                .getString(cursor.getColumnIndex(COL_IS_DEFAULT))
                                                    .getString(
                                                        cursor.getColumnIndex(COL_IS_DEFAULT)
                                                    )
                                                    .toBoolean(),
                                            rows = rows,
                                            cols = cols,
@@ -70,6 +75,16 @@ constructor(
                                    )
                                }
                            }
                            .let { list ->
                                // In this list, exactly one item should have isCurrent true.
                                val isCurrentCount = list.count { it.isCurrent }
                                if (isCurrentCount != 1) {
                                    throw IllegalStateException(
                                        "Exactly one grid option should have isCurrent = true. Found $isCurrentCount."
                                    )
                                }
                                list
                            }
                    }
            } else {
                null
@@ -87,20 +102,35 @@ constructor(
                                    add(
                                        ShapeOptionModel(
                                            key =
                                            cursor.getString(cursor.getColumnIndex(COL_SHAPE_KEY)),
                                                cursor.getString(
                                                    cursor.getColumnIndex(COL_SHAPE_KEY)
                                                ),
                                            title =
                                                cursor.getString(
                                                    cursor.getColumnIndex(COL_SHAPE_TITLE)
                                                ),
                                        path = cursor.getString(cursor.getColumnIndex(COL_PATH)),
                                            path =
                                                cursor.getString(cursor.getColumnIndex(COL_PATH)),
                                            isCurrent =
                                                cursor
                                                .getString(cursor.getColumnIndex(COL_IS_DEFAULT))
                                                    .getString(
                                                        cursor.getColumnIndex(COL_IS_DEFAULT)
                                                    )
                                                    .toBoolean(),
                                        )
                                    )
                                }
                            }
                            .let { list ->
                                // In this list, exactly one item should have isCurrent true.
                                val isCurrentCount = list.count { it.isCurrent }
                                if (isCurrentCount != 1) {
                                    throw IllegalStateException(
                                        "Exactly one shape option should have isCurrent = true. Found $isCurrentCount."
                                    )
                                }
                                list
                            }
                    }
            } else {
                null