Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
Suhas Dissanayake edited this page May 30, 2023 · 1 revision

Welcome to Food-E wiki

I created this wiki to help contributors easily understand my code :)

Directory Structure

+---app
|   \---src
|       \---main
|           +---assets
|           |   \---databases                      # Contains the main database
|           +---java
|           |   \---app
|           |       \---suhasdissa
|           |           \---foode
|           |               +---backend             # Files Related to databases/repositories/viewmodels
|           |               |   +---database
|           |               |   |   +---dao         # Data access objects for Room
|           |               |   |   \---entities    # Database Entities (Represents a single row in the database)
|           |               |   +---repositories    # Repositories get data from database and pass them to viewmodels with additional processing
|           |               |   \---viewmodels      # Viewmodels expose data to the ui elements. Data is persisted across recompositions
|           |               |       \---states
|           |               +---ui                  # Ui elements
|           |               |   +---components      # Reusable components that can go inside main screens
|           |               |   +---screens         # Main Screens
|           |               |   \---theme
|           |               \---utils               # Small utility functions and objects
|           \---res
|               +---drawable
|               +---mipmap-anydpi-v26
|               +---mipmap-hdpi
|               +---mipmap-mdpi
|               +---mipmap-xhdpi
|               +---mipmap-xxhdpi
|               +---mipmap-xxxhdpi
|               \---values                         # Mainly contains the string values with translations
\---screenshots

What each file does

AppContainer.kt         # Contains code for DI
Destinations.kt         # Navigation Destinations
FoodeApplication.kt     # Main Application class that also creates the app contaienr
NavHost.kt              # Navigation Graph

How I implemented the large screen support

I couldn't find good documentation about this feature. So I took my own approach at this. I created TwoPane.kt component that can hold two composable screens side by side

@Composable
fun TwoPaneScreen(
    PaneOne: @Composable () -> Unit,
    PaneTwo: @Composable () -> Unit
) {
    Row(Modifier.fillMaxSize()) {
        Column(
            Modifier
                .weight(0.5f)
                .fillMaxHeight()
        ) {
            PaneOne()
        }
        Column(
            Modifier
                .weight(0.5f)
                .fillMaxHeight()
        ) {
            PaneTwo()
        }

    }

}

So, the two pane layout is handled by the NavHost. For example this is what I'm doing to show two panels in home screen

composable(route = Home.route) {
            var additiveID by remember { mutableStateOf(0) }
            if (isLargeScreen) {
                TwoPaneScreen(PaneOne = {
                    HomeScreen(onClickTextCard = {
                        additiveID = it
                    }, onClickSearch = {
                        navController.navigateTo(SearchView.route)
                    }, onClickSettings = {
                        navController.navigateTo(Settings.route)
                    })
                }, PaneTwo = {
                    AdditiveDetailScreen(additiveID)
                })
            } else {
                HomeScreen(onClickTextCard = { id ->
                    navController.navigateTo("${AdditiveDetail.route}/$id")
                }, onClickSearch = {
                    navController.navigateTo(SearchView.route)
                }, onClickSettings = {
                    navController.navigateTo(Settings.route)
                })
            }
        }
Clone this wiki locally