/* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.cbnu.cats.ui.utils import android.graphics.Rect import androidx.window.layout.FoldingFeature import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract /** * Information about the posture of the device */ sealed interface DevicePosture { object NormalPosture : DevicePosture data class BookPosture( val hingePosition: Rect ) : DevicePosture data class Separating( val hingePosition: Rect, var orientation: FoldingFeature.Orientation ) : DevicePosture } @OptIn(ExperimentalContracts::class) fun isBookPosture(foldFeature: FoldingFeature?): Boolean { contract { returns(true) implies (foldFeature != null) } return foldFeature?.state == FoldingFeature.State.HALF_OPENED && foldFeature.orientation == FoldingFeature.Orientation.VERTICAL } @OptIn(ExperimentalContracts::class) fun isSeparating(foldFeature: FoldingFeature?): Boolean { contract { returns(true) implies (foldFeature != null) } return foldFeature?.state == FoldingFeature.State.FLAT && foldFeature.isSeparating } /** * Different type of navigation supported by app depending on device size and state. */ enum class ReplyNavigationType { BOTTOM_NAVIGATION, NAVIGATION_RAIL, PERMANENT_NAVIGATION_DRAWER } /** * Different position of navigation content inside Navigation Rail, Navigation Drawer depending on device size and state. */ enum class ReplyNavigationContentPosition { TOP, CENTER } /** * App Content shown depending on device size and state. */ enum class ReplyContentType { SINGLE_PANE, DUAL_PANE }