Skip to content

Commit 400185f

Browse files
param-paramGurupreet
authored andcommitted
Started documenting the code in app module.
1 parent 25c6c5b commit 400185f

File tree

21 files changed

+493
-11
lines changed

21 files changed

+493
-11
lines changed

app/src/main/java/com/guru/composecookbook/App.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ package com.guru.composecookbook
33
import android.app.Application
44
import android.content.Context
55

6+
/**
7+
* Custom Application class for initializing global application state.
8+
*/
69
class App : Application() {
710

11+
/**
12+
* Initializes the singleton instance of the App class and ensuring it is non-null.
13+
*/
814
init {
915
instance = requireNotNull(this)
1016
}
1117

1218
companion object {
19+
// Singleton instance of the App class
1320
private lateinit var instance: App
1421

22+
/**
23+
* Provides the application context.
24+
*
25+
* @return Context of the application.
26+
*/
1527
fun applicationContext(): Context {
1628
return instance
1729
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
package com.guru.composecookbook
22

3+
/**
4+
* Enum class representing the different types of bottom navigation items.
5+
*/
36
enum class BottomNavType {
7+
/**
8+
* Represents the Home screen in the bottom navigation.
9+
*/
410
HOME,
11+
/**
12+
* Represents the Widgets screen in the bottom navigation.
13+
*/
514
WIDGETS,
15+
/**
16+
* Represents the Animation screen in the bottom navigation.
17+
*/
618
ANIMATION,
19+
/**
20+
* Represents the Demo UI screen in the bottom navigation.
21+
*/
722
DEMOUI,
23+
/**
24+
* Represents the Template screen in the bottom navigation.
25+
*/
826
TEMPLATE
927
}

app/src/main/java/com/guru/composecookbook/MainActivity.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ import com.guru.fontawesomecomposelib.FaIcon
6565
import com.guru.fontawesomecomposelib.FaIcons
6666
import kotlinx.coroutines.launch
6767

68+
/**
69+
* Main activity of the application.
70+
*/
6871
class MainActivity : ComponentActivity() {
72+
73+
/**
74+
* Sets up the main activity. Initializes the mobile ads and sets the content view.
75+
*
76+
* @param savedInstanceState Saved instance state.
77+
*/
78+
6979
@OptIn(ExperimentalAnimationApi::class,
7080
ExperimentalFoundationApi::class,
7181
ExperimentalMaterialApi::class)
@@ -83,6 +93,14 @@ class MainActivity : ComponentActivity() {
8393
}
8494
}
8595

96+
97+
/**
98+
* Composable function for the base view of the app.
99+
*
100+
* @param appThemeState Current app theme state.
101+
* @param systemUiController Controller for system UI.
102+
* @param content Composable content to be displayed.
103+
*/
86104
@Composable
87105
fun BaseView(
88106
appThemeState: AppThemeState,
@@ -105,6 +123,15 @@ fun BaseView(
105123
}
106124
}
107125

126+
127+
/**
128+
* Composable function for the home screen content.
129+
*
130+
* @param homeScreen Current home screen type.
131+
* @param appThemeState Current app theme state.
132+
* @param chooseColorBottomModalState State of the bottom modal sheet for color selection.
133+
* @param modifier Modifier to be applied to the layout.
134+
*/
108135
@OptIn(ExperimentalAnimationApi::class,
109136
ExperimentalFoundationApi::class,
110137
ExperimentalMaterialApi::class)
@@ -131,6 +158,12 @@ fun HomeScreenContent(
131158
}
132159
}
133160

161+
162+
/**
163+
* Composable function for the main app content.
164+
*
165+
* @param appThemeState Current app theme state.
166+
*/
134167
@OptIn(ExperimentalAnimationApi::class,
135168
ExperimentalFoundationApi::class,
136169
ExperimentalMaterialApi::class)
@@ -194,6 +227,13 @@ fun MainAppContent(appThemeState: MutableState<AppThemeState>) {
194227

195228
}
196229

230+
231+
/**
232+
* Composable function for the bottom navigation content.
233+
*
234+
* @param modifier Modifier to be applied to the layout.
235+
* @param homeScreenState Current home screen state.
236+
*/
197237
@Composable
198238
fun BottomNavigationContent(
199239
modifier: Modifier = Modifier,
@@ -318,6 +358,13 @@ fun BottomNavigationContent(
318358
}
319359
}
320360

361+
362+
/**
363+
* Composable function for the navigation rail content.
364+
*
365+
* @param modifier Modifier to be applied to the layout.
366+
* @param homeScreenState Current home screen state.
367+
*/
321368
@Composable
322369
private fun NavigationRailContent(
323370
modifier: Modifier,
@@ -442,6 +489,10 @@ private fun NavigationRailContent(
442489
}
443490
}
444491

492+
493+
/**
494+
* Preview function for the main app content.
495+
*/
445496
@OptIn(ExperimentalAnimationApi::class,
446497
ExperimentalFoundationApi::class,
447498
ExperimentalMaterialApi::class)

app/src/main/java/com/guru/composecookbook/ui/home/HomeScreen.kt

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ import kotlinx.coroutines.CoroutineScope
7171
import kotlinx.coroutines.launch
7272
import java.util.*
7373

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

122-
129+
/**
130+
* Adds an icon button that, when clicked, toggles the visibility of the color palette menu or
131+
* shows the modal bottom sheet for color selection if accessibility settings are enabled.
132+
*
133+
* @param coroutineScope: Scope for launching coroutines.
134+
* @param chooseColorBottomModalState: State for controlling the color selection modal bottom sheet.
135+
* @param showMenu: Mutable state to control the visibility of the color palette menu.
136+
*/
123137
@SuppressLint("ServiceCast")
124138
@OptIn(ExperimentalMaterialApi::class)
125139
@Composable
@@ -148,6 +162,15 @@ private fun ChangeColorIconButton(
148162
}
149163
}
150164

165+
/**
166+
* Displays a list of home screen items, adapting the layout based on screen width.
167+
* Shows a color palette menu if showMenu is true.
168+
*
169+
* @param isDarkTheme: Boolean indicating whether the dark theme is active.
170+
* @param showMenu: Mutable state to control the visibility of the color palette menu.
171+
* @param onPalletChange: Callback invoked when a new color palette is selected.
172+
* @param modifier: Modifier for styling the composable.
173+
*/
151174
@Composable
152175
fun HomeScreenContent(
153176
isDarkTheme: Boolean,
@@ -191,6 +214,12 @@ fun HomeScreenContent(
191214
}
192215
}
193216

217+
/**
218+
* Displays a list of color options for the user to choose from, invoking onPalletChange when a selection is made.
219+
*
220+
* @param modifier: Modifier for styling the composable.
221+
* @param onPalletChange: Callback invoked when a new color palette is selected.
222+
*/
194223
@Composable
195224
fun PalletMenu(
196225
modifier: Modifier,
@@ -224,6 +253,13 @@ fun PalletMenu(
224253
}
225254
}
226255

256+
/**
257+
* Displays a row with an icon and text, triggering the onPalletChange callback when clicked.
258+
*
259+
* @param color: Color of the icon representing the palette.
260+
* @param name: Name of the color palette.
261+
* @param onPalletChange: Callback invoked when the menu item is clicked.
262+
*/
227263
@Composable
228264
fun MenuItem(color: Color, name: String, onPalletChange: () -> Unit) {
229265
Row(
@@ -241,7 +277,14 @@ fun MenuItem(color: Color, name: String, onPalletChange: () -> Unit) {
241277
}
242278
}
243279

244-
280+
/**
281+
* Displays a card or button for each home screen item, adjusting the layout based on screen width.
282+
*
283+
* @param homeScreenItems: Item to display in the list.
284+
* @param context: Context for starting activities.
285+
* @param isDarkTheme: Boolean indicating whether the dark theme is active.
286+
* @param isWiderScreen: Boolean indicating if the screen width is wider than a certain threshold.
287+
*/
245288
@Composable
246289
fun HomeScreenListView(
247290
homeScreenItems: HomeScreenItems, context: Context, isDarkTheme: Boolean,
@@ -281,6 +324,13 @@ fun HomeScreenListView(
281324
}
282325
}
283326

327+
/**
328+
* Starts a new activity based on the clicked home screen item, passing the theme state to the new activity.
329+
*
330+
* @param homeScreenItems: Item that was clicked.
331+
* @param context: Context for starting activities.
332+
* @param isDarkTheme: Boolean indicating whether the dark theme is active.
333+
*/
284334
fun homeItemClicked(homeScreenItems: HomeScreenItems, context: Context, isDarkTheme: Boolean) {
285335
//TODO pass theme to following screens
286336
val intent = when (homeScreenItems) {
@@ -340,6 +390,9 @@ fun homeItemClicked(homeScreenItems: HomeScreenItems, context: Context, isDarkTh
340390
context.startActivity(intent)
341391
}
342392

393+
/**
394+
* Provides a preview of the HomeScreen composable with default theme state and modal bottom sheet state.
395+
*/
343396
@OptIn(ExperimentalMaterialApi::class)
344397
@Preview
345398
@Composable

app/src/main/java/com/guru/composecookbook/ui/home/lists/GridListItem.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import com.guru.composecookbook.theme.ComposeCookBookTheme
2424
import com.guru.composecookbook.theme.components.Material3Card
2525
import com.guru.composecookbook.ui.utils.TestTags
2626

27+
/**
28+
* Composable function to display a grid list item.
29+
*
30+
* @param item The item to display, which contains information such as title, subtitle, source, and image.
31+
* @param modifier The modifier to be applied to the layout of the grid list item.
32+
*/
2733
@Composable
2834
fun GridListItem(
2935
item: Item,
@@ -70,6 +76,9 @@ fun GridListItem(
7076
}
7177
}
7278

79+
/**
80+
* Preview function for GridListItem composable.
81+
*/
7382
@Preview
7483
@Composable
7584
fun PreviewGridListItem() {

app/src/main/java/com/guru/composecookbook/ui/home/lists/HorizontalListItem.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import com.guru.composecookbook.theme.ComposeCookBookTheme
2323
import com.guru.composecookbook.theme.components.Material3Card
2424
import com.guru.composecookbook.ui.utils.TestTags
2525

26+
/**
27+
* Composable function to display a horizontal list item.
28+
*
29+
* @param item The item to display, which contains information such as title, subtitle, source, and image.
30+
* @param modifier The modifier to be applied to the layout of the grid list item.
31+
*/
2632
@Composable
2733
fun HorizontalListItem(
2834
item: Item,
@@ -67,6 +73,9 @@ fun HorizontalListItem(
6773
}
6874
}
6975

76+
/**
77+
* Preview function for HorizontalListItem composable.
78+
*/
7079
@Preview
7180
@Composable
7281
fun PreviewHorizontalListItem() {

app/src/main/java/com/guru/composecookbook/ui/learnwidgets/AllButtons.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ import com.guru.composecookbook.theme.typography
3838
import kotlinx.coroutines.delay
3939
import kotlinx.coroutines.launch
4040

41+
/**
42+
* Composable function demonstrating various types of buttons and their customization options.
43+
*/
4144
@OptIn(ExperimentalMaterialApi::class,
4245
ExperimentalAnimationApi::class)
4346
@Composable
4447
fun AllButtons() {
4548
Text(text = "Buttons", style = typography.h5, modifier = Modifier.padding(8.dp))
4649

50+
// Row 1: Basic Buttons
4751
Row {
4852
Button(onClick = {}, modifier = Modifier.padding(8.dp)) {
4953
Text(text = "Main Button")
@@ -55,6 +59,8 @@ fun AllButtons() {
5559
Text(text = "Text Disabled")
5660
}
5761
}
62+
63+
// Row 2: More Button Variations
5864
Row {
5965
Button(onClick = {}, modifier = Modifier.padding(8.dp), enabled = false) {
6066
Text(text = "Disabled")
@@ -74,6 +80,8 @@ fun AllButtons() {
7480
Text(text = "Rounded")
7581
}
7682
}
83+
84+
// Row 3: Other Button Types
7785
Row {
7886
OutlinedButton(onClick = {}, modifier = Modifier.padding(8.dp)) {
7987
Text(text = "Outline")
@@ -117,6 +125,8 @@ fun AllButtons() {
117125
Text(text = "Custom colors")
118126
}
119127
}
128+
129+
// Gradient Background Buttons
120130
Row {
121131
val horizontalGradient = Brush.horizontalGradient(
122132
colors = listOf(MaterialTheme.colorScheme.primary, MaterialTheme.colorScheme.inversePrimary),
@@ -150,6 +160,7 @@ fun AllButtons() {
150160
)
151161
}
152162

163+
// Swipe Button Examples
153164
val swipeButtonState = remember {
154165
mutableStateOf(SwipeButtonState.INITIAL)
155166
}
@@ -186,6 +197,10 @@ fun AllButtons() {
186197
}
187198
}
188199

200+
201+
/**
202+
* A Composable function to preview the AllButtons Composable.
203+
*/
189204
@OptIn(ExperimentalAnimationApi::class,
190205
ExperimentalMaterialApi::class)
191206
@Preview

0 commit comments

Comments
 (0)