Skip to content

Commit

Permalink
Merge pull request #704 from Orange-OpenSource/ods-module-about-step2…
Browse files Browse the repository at this point in the history
…-menu

OdsAboutModule - step 2 - Add menu
  • Loading branch information
florentmaitre authored Nov 23, 2023
2 parents a5301e5 + 166a1a8 commit 908c18c
Show file tree
Hide file tree
Showing 37 changed files with 1,064 additions and 360 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/orange/ods/app/ui/AppBarState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface AppBarManager {
/**
* AppBar state source of truth.
*
* The app bar is managed according to the [Screen] displayed except when its type is [ScreenType.WithCustomizableTopAppBar]. In this case, the app bar is
* The app bar is managed according to the [Screen] displayed except when the screen has a custom app bar. In this case, the app bar is
* displayed according to the provided [AppBarConfiguration].
*/
class AppBarState(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/orange/ods/app/ui/AppNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ object MainNavigation {
fun NavGraphBuilder.appNavGraph(
navController: NavController,
navigateToElement: (String, Long?, NavBackStackEntry) -> Unit,
navigateToAboutModule: () -> Unit,
upPress: () -> Unit
) {
addBottomBarGraph(navController)

addGuidelinesGraph()
addComponentsGraph(navController, upPress)
addModulesGraph(navController)
addModulesGraph(navigateToAboutModule)

composable(
route = MainNavigation.SearchRoute
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/orange/ods/app/ui/BottomBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.orange.ods.app.ui.components.ComponentsScreen
import com.orange.ods.app.ui.guidelines.GuidelinesScreen
import com.orange.ods.app.ui.modules.ModulesScreen
import com.orange.ods.compose.component.bottomnavigation.OdsBottomNavigation
import com.orange.ods.module.about.navigation.OdsAboutRoute
import com.orange.ods.module.about.navigation.aboutGraph

@Composable
fun BottomBar(items: Array<BottomBarItem>, currentRoute: String, navigateToRoute: (String) -> Unit) {
Expand Down Expand Up @@ -53,6 +53,7 @@ fun NavGraphBuilder.addBottomBarGraph(navController: NavController) {
ModulesScreen(onModuleClick = { route -> navController.navigateToElement(route, null, from) })
}

aboutGraph(navController)
}

enum class BottomBarItem(
Expand All @@ -63,5 +64,5 @@ enum class BottomBarItem(
Guidelines(R.string.navigation_item_guidelines, R.drawable.ic_guideline_dna, "main/guidelines"),
Components(R.string.navigation_item_components, R.drawable.ic_component_atom, "main/components"),
Modules(R.string.navigation_item_modules, R.drawable.ic_module_molecule, "main/modules"),
About(R.string.navigation_item_about, R.drawable.ic_info, OdsAboutRoute);
About(R.string.navigation_item_about, R.drawable.ic_info, "ods/module/about/home");
}
27 changes: 22 additions & 5 deletions app/src/main/java/com/orange/ods/app/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import com.google.accompanist.systemuicontroller.rememberSystemUiController
Expand All @@ -43,6 +45,7 @@ import com.orange.ods.app.domain.recipes.LocalRecipes
import com.orange.ods.app.ui.about.aboutConfiguration
import com.orange.ods.app.ui.components.tabs.MainTabsCustomizationState
import com.orange.ods.app.ui.components.tabs.tabs
import com.orange.ods.app.ui.modules.about.AboutCustomizationViewModel
import com.orange.ods.app.ui.utilities.extension.isDarkModeEnabled
import com.orange.ods.app.ui.utilities.extension.isOrange
import com.orange.ods.compose.component.listitem.OdsListItem
Expand All @@ -51,7 +54,8 @@ import com.orange.ods.compose.component.tab.OdsTabRow
import com.orange.ods.compose.text.OdsTextH6
import com.orange.ods.compose.theme.OdsTheme
import com.orange.ods.extension.orElse
import com.orange.ods.module.about.configuration.LocalOdsAboutModuleConfiguration
import com.orange.ods.module.about.navigation.navigateToOdsAbout
import com.orange.ods.module.about.odsAboutModule
import com.orange.ods.theme.OdsThemeConfigurationContract
import com.orange.ods.xml.theme.OdsXml
import com.orange.ods.xml.utilities.extension.xml
Expand Down Expand Up @@ -96,8 +100,7 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
LocalOdsGuideline provides mainState.themeState.currentThemeConfiguration.guideline,
LocalRecipes provides mainViewModel.recipes,
LocalCategories provides mainViewModel.categories,
LocalUiFramework provides mainState.uiFramework,
LocalOdsAboutModuleConfiguration provides aboutConfiguration()
LocalUiFramework provides mainState.uiFramework
) {
AppBarActionsHandler(navigate = mainState.navController::navigate, onChangeThemeActionClick = { changeThemeDialogVisible = true })
OdsTheme(
Expand All @@ -116,6 +119,11 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
modifier = Modifier
}

val context = LocalContext.current
val aboutConfiguration = aboutConfiguration()
val aboutModule = odsAboutModule(context = context, configuration = aboutConfiguration)
val aboutCustomizationViewModel = viewModel<AboutCustomizationViewModel>(context as ViewModelStoreOwner)
val customAboutConfiguration = aboutCustomizationViewModel.aboutModuleConfiguration()
Scaffold(
modifier = modifier,
topBar = {
Expand All @@ -142,7 +150,12 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
BottomBar(
items = mainState.bottomBarItems,
currentRoute = mainState.currentRoute!!,
navigateToRoute = mainState::navigateToBottomBarRoute
navigateToRoute = { route ->
if (route == BottomBarItem.About.route) {
aboutModule.configuration = aboutConfiguration
}
mainState.navigateToBottomBarRoute(route)
}
)
}
}
Expand All @@ -153,7 +166,11 @@ fun MainScreen(themeConfigurations: Set<OdsThemeConfigurationContract>, mainView
appNavGraph(
navController = mainState.navController,
navigateToElement = mainState::navigateToElement,
upPress = mainState::upPress
upPress = mainState::upPress,
navigateToAboutModule = {
aboutModule.configuration = customAboutConfiguration
mainState.navController.navigateToOdsAbout()
}
)
}

Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/orange/ods/app/ui/MainState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController

import com.orange.ods.app.ui.modules.ModuleDemoDestinations

class MainState(
val themeState: ThemeState,
Expand All @@ -34,13 +34,16 @@ class MainState(
// ----------------------------------------------------------

val bottomBarItems = BottomBarItem.values()
private val bottomBarRoutes = bottomBarItems.map { it.route }
private val bottomBarRoutes: List<String> = bottomBarItems.map { it.route }


// Reading this attribute will cause recompositions when the bottom bar needs shown, or not.
// Not all routes need to show the bottom bar.
val shouldShowBottomBar: Boolean
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination?.route in bottomBarRoutes
@Composable
get() = navController.currentBackStackEntryAsState().value?.destination?.route in bottomBarRoutes
&& navController.previousBackStackEntry?.destination?.route != ModuleDemoDestinations.AboutModuleCustomizationRoute


// ----------------------------------------------------------
// Navigation state source of truth
Expand Down Expand Up @@ -84,4 +87,4 @@ fun rememberMainState(
*
* This is used to de-duplicate navigation events.
*/
private fun NavBackStackEntry.lifecycleIsResumed() = this.getLifecycle().currentState == Lifecycle.State.RESUMED
private fun NavBackStackEntry.lifecycleIsResumed() = this.getLifecycle().currentState == Lifecycle.State.RESUMED
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,39 @@ package com.orange.ods.app.ui.about

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.orange.ods.app.R
import com.orange.ods.module.about.configuration.OdsAbout
import com.orange.ods.module.about.configuration.OdsAboutModuleConfiguration
import com.orange.ods.module.about.utilities.VersionHelper

@Composable
fun aboutConfiguration() = OdsAboutModuleConfiguration(
appName = stringResource(id = R.string.about_app_name),
privacyPolicyMenuItemFileRes = R.raw.about_privacy_policy,
termsOfServiceMenuItemFileRes = R.raw.about_terms_of_service,
appVersion = VersionHelper.getFromPackageInfo(context = LocalContext.current),
appDescription = stringResource(id = R.string.about_description)
)
appDescription = stringResource(id = R.string.about_description),
customMenuItems = listOf(
OdsAbout.UrlMenuItem(
painterResource(id = R.drawable.ic_tools),
stringResource(id = R.string.about_menu_design_guidelines),
1,
"https://system.design.orange.com/0c1af118d/p/019ecc-android/"
),
OdsAbout.FileMenuItem(
painterResource(id = com.orange.ods.module.about.R.drawable.ic_tasklist),
stringResource(id = R.string.about_menu_changelog),
2,
R.raw.changelog,
OdsAbout.FileMenuItem.FileFormat.Markdown
),
OdsAbout.UrlMenuItem(
painterResource(id = R.drawable.ic_comments),
stringResource(id = R.string.about_menu_report_issue),
3,
"https://github.com/Orange-OpenSource/ods-android/issues/new/choose"
),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,5 @@ sealed class Variant(

data object TabsFixed : Variant(R.string.component_tabs_fixed, OdsComposable.OdsTabRow.name)
data object TabsScrollable : Variant(R.string.component_tabs_scrollable, OdsComposable.OdsScrollableTabRow.name)
}

}
3 changes: 3 additions & 0 deletions app/src/main/java/com/orange/ods/app/ui/modules/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.orange.ods.app.ui.modules

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import com.orange.ods.app.R

Expand All @@ -22,6 +23,7 @@ sealed class Module(
@DrawableRes val imageRes: Int,
@StringRes val descriptionRes: Int,
val route: String,
val demoScreen: @Composable (upPress: () -> Unit) -> Unit,
val imageAlignment: Alignment = Alignment.Center,
) {
val id: Long = Module::class.sealedSubclasses.indexOf(this::class).toLong()
Expand All @@ -31,5 +33,6 @@ sealed class Module(
R.drawable.il_about,
R.string.module_about_description,
route = ModuleDemoDestinations.AboutModuleCustomizationRoute,
demoScreen = { _ -> },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ fun ModuleDetailColumn(
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(bottom = dimensionResource(id = com.orange.ods.R.dimen.screen_vertical_margin))
.padding(bottom = dimensionResource(id = R.dimen.screen_vertical_margin))
) {
DetailScreenHeader(
imageRes = DrawableManager.getDrawableResIdForCurrentTheme(resId = module.imageRes),
imageAlignment = module.imageAlignment,
descriptionRes = module.descriptionRes
)

Column(modifier = Modifier.padding(dimensionResource(id = com.orange.ods.R.dimen.screen_horizontal_margin))) {
Column(modifier = Modifier.padding(dimensionResource(id = R.dimen.screen_horizontal_margin))) {
Subtitle(textRes = com.orange.ods.app.R.string.module_customize)
content()

OdsButton(
modifier = Modifier
.padding(top = dimensionResource(id = R.dimen.spacing_m))
Expand Down
30 changes: 8 additions & 22 deletions app/src/main/java/com/orange/ods/app/ui/modules/ModulesNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,14 @@

package com.orange.ods.app.ui.modules

import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.orange.ods.app.ui.modules.ModuleDemoDestinations.AboutModuleCustomizationRoute
import com.orange.ods.app.ui.modules.about.AboutCustomizationScreen
import com.orange.ods.module.about.OdsAboutViewModel
import com.orange.ods.module.about.navigation.aboutScreen
import com.orange.ods.module.about.navigation.navigateToOdsAboutDemo

object ModulesNavigation {
const val ModuleDetailRoute = "component"
const val ModuleDemoRoute = "module/demo"

const val ModuleIdKey = "moduleId"
}
import com.orange.ods.app.ui.modules.about.AboutCustomizationViewModel

/**
* Modules demo destinations.
Expand All @@ -34,18 +26,12 @@ object ModuleDemoDestinations {
const val AboutModuleCustomizationRoute = "module/about/customization"
}

fun NavGraphBuilder.addModulesGraph(navController: NavController) {

fun NavGraphBuilder.addModulesGraph(navigateToAboutModule: () -> Unit) {
composable(
route = AboutModuleCustomizationRoute
) { navBackStackEntry ->
/* LocalMainTopAppBarManager.current.updateTopAppBar(MainTopAppBarState.DefaultConfiguration)
LocalMainTopAppBarManager.current.updateTopAppBarTitle(Module.About.titleRes)*/

val viewModel: OdsAboutViewModel = viewModel(navBackStackEntry)
AboutCustomizationScreen(navigateToAboutModule = navController::navigateToOdsAboutDemo, configureAboutModule = viewModel::configureAboutModule)
) { _ ->
val viewModelStoreOwner = LocalContext.current as ViewModelStoreOwner
val viewModel = viewModel<AboutCustomizationViewModel>(viewModelStoreOwner)
AboutCustomizationScreen(navigateToAboutModule = navigateToAboutModule, viewModel = viewModel)
}

aboutScreen(navController = navController)

}
Loading

0 comments on commit 908c18c

Please sign in to comment.