Skip to content

Commit

Permalink
[#651] Rename some files and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea committed Oct 17, 2023
1 parent 6bc6061 commit e579cab
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 38 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/com/orange/ods/app/ui/AppBarState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ val LocalAppBarManager = staticCompositionLocalOf<AppBarManager> { error("Compos
interface AppBarManager {
fun setCustomAppBar(appBarConfiguration: AppBarConfiguration)

fun updateTopAppBarTabs(tabsConfiguration: TabsConfiguration)
fun clearTopAppBarTabs()
fun updateAppBarTabs(tabsConfiguration: TabsConfiguration)
fun clearAppBarTabs()
}

class AppBarState(
private val navController: NavController,
val searchedText: MutableState<TextFieldValue>,
private val customAppBarConfiguration: MutableState<AppBarConfiguration>,
val tabsState: MainTabsState
val tabsState: AppBarTabsState
) : AppBarManager {

companion object {
Expand Down Expand Up @@ -134,12 +134,12 @@ class AppBarState(
customAppBarConfiguration.value = appBarConfiguration
}

override fun updateTopAppBarTabs(tabsConfiguration: TabsConfiguration) {
tabsState.updateTopAppBarTabs(tabsConfiguration)
override fun updateAppBarTabs(tabsConfiguration: TabsConfiguration) {
tabsState.updateAppBarTabs(tabsConfiguration)
}

override fun clearTopAppBarTabs() {
tabsState.clearTopAppBarTabs()
override fun clearAppBarTabs() {
tabsState.clearAppBarTabs()
}
}

Expand All @@ -148,7 +148,7 @@ fun rememberAppBarState(
navController: NavController,
searchedText: MutableState<TextFieldValue> = remember { mutableStateOf(TextFieldValue("")) },
customAppBarConfiguration: MutableState<AppBarConfiguration> = remember { mutableStateOf(CustomDefaultConfiguration) },
tabsState: MainTabsState = rememberMainTabsState()
tabsState: AppBarTabsState = rememberAppBarTabsState()
) = remember { AppBarState(navController, searchedText, customAppBarConfiguration, tabsState) }

data class AppBarConfiguration constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import com.orange.ods.app.ui.utilities.NavigationItem
import com.orange.ods.app.ui.utilities.rememberSaveableMutableStateListOf

@Composable
fun rememberMainTabsState(
fun rememberAppBarTabsState(
tabs: SnapshotStateList<NavigationItem> = rememberSaveableMutableStateListOf(),
tabIconType: MutableState<MainTabsCustomizationState.TabIconType> = rememberSaveable { mutableStateOf(MainTabsState.DefaultConfiguration.tabIconType) },
tabTextEnabled: MutableState<Boolean> = rememberSaveable { mutableStateOf(MainTabsState.DefaultConfiguration.tabTextEnabled) },
scrollableTabs: MutableState<Boolean> = rememberSaveable { mutableStateOf(MainTabsState.DefaultConfiguration.scrollableTabs) }
tabIconType: MutableState<MainTabsCustomizationState.TabIconType> = rememberSaveable { mutableStateOf(AppBarTabsState.DefaultConfiguration.tabIconType) },
tabTextEnabled: MutableState<Boolean> = rememberSaveable { mutableStateOf(AppBarTabsState.DefaultConfiguration.tabTextEnabled) },
scrollableTabs: MutableState<Boolean> = rememberSaveable { mutableStateOf(AppBarTabsState.DefaultConfiguration.scrollableTabs) }
) =
remember(tabs, tabIconType, tabTextEnabled, scrollableTabs) {
MainTabsState(tabs, tabIconType, tabTextEnabled, scrollableTabs)
AppBarTabsState(tabs, tabIconType, tabTextEnabled, scrollableTabs)
}

@OptIn(ExperimentalFoundationApi::class)
class MainTabsState(
class AppBarTabsState(
val tabs: SnapshotStateList<NavigationItem>,
val tabIconType: MutableState<MainTabsCustomizationState.TabIconType>,
val tabTextEnabled: MutableState<Boolean>,
Expand All @@ -61,7 +61,7 @@ class MainTabsState(
// Tabs state source of truth
// ----------------------------------------------------------

fun updateTopAppBarTabs(tabsConfiguration: TabsConfiguration) {
fun updateAppBarTabs(tabsConfiguration: TabsConfiguration) {
with(tabs) {
clear()
addAll(tabsConfiguration.tabs)
Expand All @@ -72,7 +72,7 @@ class MainTabsState(
scrollableTabs.value = tabsConfiguration.scrollableTabs
}

fun clearTopAppBarTabs() {
fun clearAppBarTabs() {
tabs.clear()
pagerState = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun NavGraphBuilder.appNavGraph(
) {
navigation(
route = MainDestinations.HomeRoute,
startDestination = BottomNavigationSection.Guidelines.route
startDestination = BottomNavigationBarItem.Guidelines.route
) {
addBottomNavigationGraph(navigateToElement)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import com.orange.ods.compose.component.bottomnavigation.OdsBottomNavigationItem
import com.orange.ods.compose.component.bottomnavigation.OdsBottomNavigationItemIcon

@Composable
fun MainBottomNavigation(items: Array<BottomNavigationSection>, currentRoute: String, navigateToRoute: (String) -> Unit) {
fun BottomNavigationBar(items: Array<BottomNavigationBarItem>, currentRoute: String, navigateToRoute: (String) -> Unit) {
OdsBottomNavigation(
items = items.map { item ->
OdsBottomNavigationItem(
Expand All @@ -49,16 +49,16 @@ fun MainBottomNavigation(items: Array<BottomNavigationSection>, currentRoute: St
}

fun NavGraphBuilder.addBottomNavigationGraph(navigateToElement: (String, Long?, NavBackStackEntry) -> Unit) {
composable(BottomNavigationSection.Guidelines.route) { from ->
composable(BottomNavigationBarItem.Guidelines.route) { from ->
GuidelinesScreen(onGuidelineClick = { route -> navigateToElement(route, null, from) })
}
composable(BottomNavigationSection.Components.route) { from ->
composable(BottomNavigationBarItem.Components.route) { from ->
ComponentsScreen(onComponentClick = { id -> navigateToElement(ComponentsNavigation.ComponentDetailRoute, id, from) })
}
composable(BottomNavigationSection.Modules.route) {
composable(BottomNavigationBarItem.Modules.route) {
ModulesScreen()
}
composable(BottomNavigationSection.About.route) { from ->
composable(BottomNavigationBarItem.About.route) { from ->
val context = LocalContext.current
AboutScreen(onAboutItemClick = { id ->
val aboutItem = aboutItems.firstOrNull { it.id == id }
Expand All @@ -71,7 +71,7 @@ fun NavGraphBuilder.addBottomNavigationGraph(navigateToElement: (String, Long?,
}
}

enum class BottomNavigationSection(
enum class BottomNavigationBarItem(
@StringRes val titleRes: Int,
@DrawableRes val iconRes: Int,
val route: String
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/orange/ods/app/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
scrollBehavior = topBarScrollBehavior
)
if (showTabs) {
MainTabs(mainTabsState = mainState.appBarState.tabsState)
MainTabs(appBarTabsState = mainState.appBarState.tabsState)
}
}
}
Expand All @@ -139,7 +139,7 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
enter = fadeIn(),
exit = fadeOut()
) {
MainBottomNavigation(
BottomNavigationBar(
items = mainState.bottomBarItems,
currentRoute = mainState.currentRoute!!,
navigateToRoute = mainState::navigateToBottomBarRoute
Expand Down Expand Up @@ -193,8 +193,8 @@ private fun SystemBarsColorSideEffect() {

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun MainTabs(mainTabsState: MainTabsState) {
with(mainTabsState) {
private fun MainTabs(appBarTabsState: AppBarTabsState) {
with(appBarTabsState) {
pagerState?.let { pagerState ->
// Do not use tabs directly because this is a SnapshotStateList
// Thus its value can be modified and can lead to crashes if it becomes empty
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/orange/ods/app/ui/MainState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainState(
// BottomBar state source of truth
// ----------------------------------------------------------

val bottomBarItems = BottomNavigationSection.values()
val bottomBarItems = BottomNavigationBarItem.values()
private val bottomBarRoutes = bottomBarItems.map { it.route }

// Reading this attribute will cause recompositions when the bottom bar needs shown, or not.
Expand All @@ -62,7 +62,7 @@ class MainState(
get() = navController.currentDestination?.route

fun upPress() {
appBarState.clearTopAppBarTabs()
appBarState.clearAppBarTabs()
navController.navigateUp()
}

Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/orange/ods/app/ui/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fun getScreen(route: String?, args: Bundle?): Screen? = route?.let {

sealed class Screen(
val route: String,
val isAppBarVisible: Boolean = true,
val isLargeAppBar: Boolean = false,
val title: UiString? = null,
val type: ScreenType = ScreenType.Default,
Expand All @@ -71,25 +70,25 @@ sealed class Screen(
// Bottom navigation screens

data object Guidelines : Screen(
route = BottomNavigationSection.Guidelines.route,
route = BottomNavigationBarItem.Guidelines.route,
title = UiString.StringResource(R.string.navigation_item_guidelines),
type = ScreenType.Home
)

data object Components : Screen(
route = BottomNavigationSection.Components.route,
route = BottomNavigationBarItem.Components.route,
title = UiString.StringResource(R.string.navigation_item_components),
type = ScreenType.Home
)

data object Modules : Screen(
route = BottomNavigationSection.Modules.route,
route = BottomNavigationBarItem.Modules.route,
title = UiString.StringResource(R.string.navigation_item_modules),
type = ScreenType.Home
)

data object About : Screen(
route = BottomNavigationSection.About.route,
route = BottomNavigationBarItem.About.route,
title = UiString.StringResource(R.string.navigation_item_about),
type = ScreenType.Home
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun ComponentTopAppBar(variant: Variant) {
val customizationState = rememberTopAppBarCustomizationState(large = remember { mutableStateOf(variant == Variant.AppBarsTopLarge) })

with(customizationState) {
val topAppBarConfiguration = AppBarConfiguration(
val appBarConfiguration = AppBarConfiguration(
isLarge = isLarge,
titleRes = if (isLarge) title.value.titleResId else R.string.component_app_bars_top_regular,
scrollBehavior = scrollBehavior.value,
Expand All @@ -64,7 +64,7 @@ fun ComponentTopAppBar(variant: Variant) {
isOverflowMenuEnabled = isOverflowMenuEnabled
)

LocalAppBarManager.current.setCustomAppBar(topAppBarConfiguration)
LocalAppBarManager.current.setCustomAppBar(appBarConfiguration)

ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
Expand Down Expand Up @@ -239,7 +239,7 @@ private fun CustomizationBottomSheetContent(customizationState: TopAppBarCustomi

@Composable
private fun BlinkingChevronDown(modifier: Modifier = Modifier) {
val infiniteTransition = rememberInfiniteTransition()
val infiniteTransition = rememberInfiniteTransition(label = "")
val animationSpec = infiniteRepeatable<Float>(
animation = tween(1000),
repeatMode = RepeatMode.Reverse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun ComponentTabs(variant: Variant, upPress: () -> Unit) {
}

val tabsCustomizationState = rememberMainTabsCustomizationState(tabsCount = rememberSaveable { mutableStateOf(tabCountMin) })
LocalAppBarManager.current.updateTopAppBarTabs(
LocalAppBarManager.current.updateAppBarTabs(
TabsConfiguration(
scrollableTabs = scrollableTabs,
tabs = tabsCustomizationState.tabs,
Expand Down

0 comments on commit e579cab

Please sign in to comment.