Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from matsumo0922/tablet
Browse files Browse the repository at this point in the history
Introduce adaptive layout
  • Loading branch information
matsumo0922 authored Dec 12, 2023
2 parents 8c5ec80 + 95eb88e commit f8ee41e
Show file tree
Hide file tree
Showing 23 changed files with 1,174 additions and 594 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/caios/android/fanbox/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -67,6 +69,7 @@ class MainActivity : FragmentActivity(), PostDownloader {
}
}

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
Expand All @@ -80,6 +83,7 @@ class MainActivity : FragmentActivity(), PostDownloader {

setContent {
val screenState by viewModel.screenState.collectAsStateWithLifecycle()
val windowSize = calculateWindowSizeClass(this)
val systemUiController = rememberSystemUiController()
val shouldUseDarkTheme = shouldUseDarkTheme(screenState)

Expand Down Expand Up @@ -115,6 +119,7 @@ class MainActivity : FragmentActivity(), PostDownloader {
PixiViewApp(
modifier = Modifier.fillMaxSize(),
viewModel = viewModel,
windowSize = windowSize.widthSizeClass,
userData = it.userData,
isAgreedTeams = isAgreedTeams,
isAllowedPermission = isAllowedPermission,
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/caios/android/fanbox/ui/EmptyDetailScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package caios.android.fanbox.ui

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import caios.android.fanbox.R
import caios.android.fanbox.core.ui.view.EmptyView

const val EmptyDetailRoute = "Empty"

fun NavGraphBuilder.emptyDetailScreen() {
composable(EmptyDetailRoute) {
EmptyView(
modifier = Modifier.fillMaxSize(),
titleRes = R.string.empty_detail_title,
messageRes = R.string.empty_detail_description,
)
}
}
56 changes: 35 additions & 21 deletions app/src/main/java/caios/android/fanbox/ui/PixiViewApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import caios.android.fanbox.MainViewModel
import caios.android.fanbox.core.model.UserData
import caios.android.fanbox.core.ui.component.PixiViewBackground
import caios.android.fanbox.core.ui.extensition.LocalNavigationType
import caios.android.fanbox.core.ui.extensition.NavigationType
import caios.android.fanbox.core.ui.extensition.PixiViewNavigationType
import caios.android.fanbox.feature.welcome.WelcomeNavHost
import com.google.accompanist.navigation.material.BottomSheetNavigator
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
Expand All @@ -24,12 +28,19 @@ import timber.log.Timber
@Composable
internal fun PixiViewApp(
userData: UserData,
windowSize: WindowWidthSizeClass,
isAgreedTeams: Boolean,
isAllowedPermission: Boolean,
isLoggedIn: Boolean,
viewModel: MainViewModel,
modifier: Modifier = Modifier,
) {
val navigationType = when (windowSize) {
WindowWidthSizeClass.Medium -> PixiViewNavigationType.NavigationRail
WindowWidthSizeClass.Expanded -> PixiViewNavigationType.PermanentNavigationDrawer
else -> PixiViewNavigationType.BottomNavigation
}

LaunchedEffect(true) {
if (userData.pixiViewId.isBlank()) {
viewModel.initPixiViewId()
Expand All @@ -40,24 +51,27 @@ internal fun PixiViewApp(
Timber.d("isShowWelcomeScreen:, $isLoggedIn")
}

PixiViewBackground(modifier) {
AnimatedContent(
targetState = !isAgreedTeams || !isLoggedIn || !isAllowedPermission,
transitionSpec = { fadeIn().togetherWith(fadeOut()) },
label = "isShowWelcomeScreen",
) {
if (it) {
WelcomeNavHost(
modifier = Modifier.fillMaxSize(),
isAgreedTeams = isAgreedTeams,
isAllowedPermission = isAllowedPermission,
isLoggedIn = isLoggedIn,
onComplete = viewModel::updateState,
)
} else {
IdleScreen(
modifier = Modifier.fillMaxSize(),
)
CompositionLocalProvider(LocalNavigationType provides NavigationType(navigationType)) {
PixiViewBackground(modifier) {
AnimatedContent(
targetState = !isAgreedTeams || !isLoggedIn || !isAllowedPermission,
transitionSpec = { fadeIn().togetherWith(fadeOut()) },
label = "isShowWelcomeScreen",
) {
if (it) {
WelcomeNavHost(
modifier = Modifier.fillMaxSize(),
isAgreedTeams = isAgreedTeams,
isAllowedPermission = isAllowedPermission,
isLoggedIn = isLoggedIn,
onComplete = viewModel::updateState,
)
} else {
IdleScreen(
modifier = Modifier.fillMaxSize(),
navigationType = navigationType,
)
}
}
}
}
Expand All @@ -66,16 +80,16 @@ internal fun PixiViewApp(
@OptIn(ExperimentalMaterialNavigationApi::class, ExperimentalMaterialApi::class)
@Composable
private fun IdleScreen(
navigationType: PixiViewNavigationType,
modifier: Modifier = Modifier,
) {
val bottomSheetState =
rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true)
val bottomSheetNavigator = remember { BottomSheetNavigator(bottomSheetState) }
val navController = rememberNavController(bottomSheetNavigator)

PixiViewNavHost(
modifier = modifier,
bottomSheetNavigator = bottomSheetNavigator,
navController = navController,
navigationType = navigationType,
)
}
Loading

0 comments on commit f8ee41e

Please sign in to comment.