Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started documenting the code in app module. #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/src/main/java/com/guru/composecookbook/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@ package com.guru.composecookbook
import android.app.Application
import android.content.Context

/**
* Custom Application class for initializing global application state.
*/
class App : Application() {

/**
* Initializes the singleton instance of the App class and ensuring it is non-null.
*/
init {
instance = requireNotNull(this)
}

companion object {
// Singleton instance of the App class
private lateinit var instance: App

/**
* Provides the application context.
*
* @return Context of the application.
*/
fun applicationContext(): Context {
return instance
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/guru/composecookbook/BottomNavType.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
package com.guru.composecookbook

/**
* Enum class representing the different types of bottom navigation items.
*/
enum class BottomNavType {
/**
* Represents the Home screen in the bottom navigation.
*/
HOME,
/**
* Represents the Widgets screen in the bottom navigation.
*/
WIDGETS,
/**
* Represents the Animation screen in the bottom navigation.
*/
ANIMATION,
/**
* Represents the Demo UI screen in the bottom navigation.
*/
DEMOUI,
/**
* Represents the Template screen in the bottom navigation.
*/
TEMPLATE
}
51 changes: 51 additions & 0 deletions app/src/main/java/com/guru/composecookbook/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ import com.guru.composecookbook.ui.utils.TestTags
import com.guru.fontawesomecomposelib.FaIcon
import kotlinx.coroutines.launch

/**
* Main activity of the application.
*/
class MainActivity : ComponentActivity() {

/**
* Sets up the main activity. Initializes the mobile ads and sets the content view.
*
* @param savedInstanceState Saved instance state.
*/

@OptIn(ExperimentalAnimationApi::class,
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class)
Expand All @@ -86,6 +96,14 @@ class MainActivity : ComponentActivity() {
}
}


/**
* Composable function for the base view of the app.
*
* @param appThemeState Current app theme state.
* @param systemUiController Controller for system UI.
* @param content Composable content to be displayed.
*/
@Composable
fun BaseView(
appThemeState: AppThemeState,
Expand All @@ -108,6 +126,15 @@ fun BaseView(
}
}


/**
* Composable function for the home screen content.
*
* @param homeScreen Current home screen type.
* @param appThemeState Current app theme state.
* @param chooseColorBottomModalState State of the bottom modal sheet for color selection.
* @param modifier Modifier to be applied to the layout.
*/
@OptIn(ExperimentalAnimationApi::class,
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class)
Expand All @@ -134,6 +161,12 @@ fun HomeScreenContent(
}
}


/**
* Composable function for the main app content.
*
* @param appThemeState Current app theme state.
*/
@OptIn(ExperimentalAnimationApi::class,
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class)
Expand Down Expand Up @@ -197,6 +230,13 @@ fun MainAppContent(appThemeState: MutableState<AppThemeState>) {

}


/**
* Composable function for the bottom navigation content.
*
* @param modifier Modifier to be applied to the layout.
* @param homeScreenState Current home screen state.
*/
@Composable
fun BottomNavigationContent(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -321,6 +361,13 @@ fun BottomNavigationContent(
}
}


/**
* Composable function for the navigation rail content.
*
* @param modifier Modifier to be applied to the layout.
* @param homeScreenState Current home screen state.
*/
@Composable
private fun NavigationRailContent(
modifier: Modifier,
Expand Down Expand Up @@ -445,6 +492,10 @@ private fun NavigationRailContent(
}
}


/**
* Preview function for the main app content.
*/
@OptIn(ExperimentalAnimationApi::class,
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class)
Expand Down
59 changes: 56 additions & 3 deletions app/src/main/java/com/guru/composecookbook/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import java.util.*


/**
* Sets up the home screen UI with a top bar and content area.
* The top bar includes buttons for toggling the dark theme and opening a color selection menu.
* The content area displays the home screen content, including a list of items and a color palette menu.
*
* @param appThemeState: A mutable state holding the current theme state (light or dark) and color palette.
* @param chooseColorBottomModalState: State for controlling the bottom modal sheet used for choosing colors.
*/
@OptIn(
ExperimentalMaterialApi::class,
ExperimentalMaterial3Api::class
Expand Down Expand Up @@ -119,7 +126,14 @@ fun HomeScreen(
)
}


/**
* Adds an icon button that, when clicked, toggles the visibility of the color palette menu or
* shows the modal bottom sheet for color selection if accessibility settings are enabled.
*
* @param coroutineScope: Scope for launching coroutines.
* @param chooseColorBottomModalState: State for controlling the color selection modal bottom sheet.
* @param showMenu: Mutable state to control the visibility of the color palette menu.
*/
@SuppressLint("ServiceCast")
@OptIn(ExperimentalMaterialApi::class)
@Composable
Expand Down Expand Up @@ -148,6 +162,15 @@ private fun ChangeColorIconButton(
}
}

/**
* Displays a list of home screen items, adapting the layout based on screen width.
* Shows a color palette menu if showMenu is true.
*
* @param isDarkTheme: Boolean indicating whether the dark theme is active.
* @param showMenu: Mutable state to control the visibility of the color palette menu.
* @param onPalletChange: Callback invoked when a new color palette is selected.
* @param modifier: Modifier for styling the composable.
*/
@Composable
fun HomeScreenContent(
isDarkTheme: Boolean,
Expand Down Expand Up @@ -191,6 +214,12 @@ fun HomeScreenContent(
}
}

/**
* Displays a list of color options for the user to choose from, invoking onPalletChange when a selection is made.
*
* @param modifier: Modifier for styling the composable.
* @param onPalletChange: Callback invoked when a new color palette is selected.
*/
@Composable
fun PalletMenu(
modifier: Modifier,
Expand Down Expand Up @@ -224,6 +253,13 @@ fun PalletMenu(
}
}

/**
* Displays a row with an icon and text, triggering the onPalletChange callback when clicked.
*
* @param color: Color of the icon representing the palette.
* @param name: Name of the color palette.
* @param onPalletChange: Callback invoked when the menu item is clicked.
*/
@Composable
fun MenuItem(color: Color, name: String, onPalletChange: () -> Unit) {
Row(
Expand All @@ -241,7 +277,14 @@ fun MenuItem(color: Color, name: String, onPalletChange: () -> Unit) {
}
}


/**
* Displays a card or button for each home screen item, adjusting the layout based on screen width.
*
* @param homeScreenItems: Item to display in the list.
* @param context: Context for starting activities.
* @param isDarkTheme: Boolean indicating whether the dark theme is active.
* @param isWiderScreen: Boolean indicating if the screen width is wider than a certain threshold.
*/
@Composable
fun HomeScreenListView(
homeScreenItems: HomeScreenItems, context: Context, isDarkTheme: Boolean,
Expand Down Expand Up @@ -281,6 +324,13 @@ fun HomeScreenListView(
}
}

/**
* Starts a new activity based on the clicked home screen item, passing the theme state to the new activity.
*
* @param homeScreenItems: Item that was clicked.
* @param context: Context for starting activities.
* @param isDarkTheme: Boolean indicating whether the dark theme is active.
*/
fun homeItemClicked(homeScreenItems: HomeScreenItems, context: Context, isDarkTheme: Boolean) {
//TODO pass theme to following screens
val intent = when (homeScreenItems) {
Expand Down Expand Up @@ -340,6 +390,9 @@ fun homeItemClicked(homeScreenItems: HomeScreenItems, context: Context, isDarkTh
context.startActivity(intent)
}

/**
* Provides a preview of the HomeScreen composable with default theme state and modal bottom sheet state.
*/
@OptIn(ExperimentalMaterialApi::class)
@Preview
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import com.guru.composecookbook.theme.ComposeCookBookTheme
import com.guru.composecookbook.theme.components.Material3Card
import com.guru.composecookbook.ui.utils.TestTags

/**
* Composable function to display a grid list item.
*
* @param item The item to display, which contains information such as title, subtitle, source, and image.
* @param modifier The modifier to be applied to the layout of the grid list item.
*/
@Composable
fun GridListItem(
item: Item,
Expand Down Expand Up @@ -66,6 +72,9 @@ fun GridListItem(
}
}

/**
* Preview function for GridListItem composable.
*/
@Preview
@Composable
fun PreviewGridListItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import com.guru.composecookbook.theme.ComposeCookBookTheme
import com.guru.composecookbook.theme.components.Material3Card
import com.guru.composecookbook.ui.utils.TestTags

/**
* Composable function to display a horizontal list item.
*
* @param item The item to display, which contains information such as title, subtitle, source, and image.
* @param modifier The modifier to be applied to the layout of the grid list item.
*/
@Composable
fun HorizontalListItem(
item: Item,
Expand Down Expand Up @@ -63,6 +69,9 @@ fun HorizontalListItem(
}
}

/**
* Preview function for HorizontalListItem composable.
*/
@Preview
@Composable
fun PreviewHorizontalListItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ import com.guru.composecookbook.theme.typography
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
* Composable function demonstrating various types of buttons and their customization options.
*/
@OptIn(ExperimentalMaterialApi::class,
ExperimentalAnimationApi::class)
@Composable
fun AllButtons() {
Text(text = "Buttons", style = typography.h5, modifier = Modifier.padding(8.dp))

// Row 1: Basic Buttons
Row {
Button(onClick = {}, modifier = Modifier.padding(8.dp)) {
Text(text = "Main Button")
Expand All @@ -44,6 +48,8 @@ fun AllButtons() {
Text(text = "Text Disabled")
}
}

// Row 2: More Button Variations
Row {
Button(onClick = {}, modifier = Modifier.padding(8.dp), enabled = false) {
Text(text = "Disabled")
Expand All @@ -63,6 +69,8 @@ fun AllButtons() {
Text(text = "Rounded")
}
}

// Row 3: Other Button Types
Row {
OutlinedButton(onClick = {}, modifier = Modifier.padding(8.dp)) {
Text(text = "Outline")
Expand Down Expand Up @@ -106,6 +114,8 @@ fun AllButtons() {
Text(text = "Custom colors")
}
}

// Gradient Background Buttons
Row {
val horizontalGradient = Brush.horizontalGradient(
colors = listOf(MaterialTheme.colorScheme.primary, MaterialTheme.colorScheme.inversePrimary),
Expand Down Expand Up @@ -139,6 +149,7 @@ fun AllButtons() {
)
}

// Swipe Button Examples
val swipeButtonState = remember {
mutableStateOf(SwipeButtonState.INITIAL)
}
Expand Down Expand Up @@ -175,6 +186,10 @@ fun AllButtons() {
}
}


/**
* A Composable function to preview the AllButtons Composable.
*/
@OptIn(ExperimentalAnimationApi::class,
ExperimentalMaterialApi::class)
@Preview
Expand Down
Loading