-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ndiritumichael/calorie-test
Unit Test
- Loading branch information
Showing
142 changed files
with
4,344 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/devmike/caloriebytez/CalorieApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.devmike.caloriebytez | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
import timber.log.Timber | ||
|
||
@HiltAndroidApp | ||
class CalorieApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
} | ||
} |
41 changes: 22 additions & 19 deletions
41
app/src/main/java/com/devmike/caloriebytez/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
package com.devmike.caloriebytez | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.rememberNavController | ||
import com.devmike.caloriebytez.navigation.AppNavigation | ||
import com.devmike.caloriebytez.navigation.CalorieBottomBar | ||
import com.devmike.caloriebytez.ui.theme.CalorieBytezTheme | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") | ||
@AndroidEntryPoint | ||
class MainActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
setContent { | ||
CalorieBytezTheme { | ||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | ||
Greeting( | ||
name = "Android", | ||
modifier = Modifier.padding(innerPadding), | ||
) | ||
} | ||
CalorieApp() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun Greeting( | ||
name: String, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Text(text = "Hello $name!", modifier = modifier) | ||
} | ||
fun CalorieApp() { | ||
val navHostController: NavHostController = rememberNavController() | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun GreetingPreview() { | ||
CalorieBytezTheme { Greeting("Android") } | ||
Scaffold(bottomBar = { | ||
CalorieBottomBar(navHostController) | ||
}) { | ||
AppNavigation( | ||
modifier = | ||
Modifier.padding( | ||
bottom = it.calculateBottomPadding(), | ||
), | ||
navController = navHostController, | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/devmike/caloriebytez/navigation/AppNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.devmike.caloriebytez.navigation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import com.devmike.domain.models.AppDestinations | ||
import com.devmike.fooddetails.FoodDetailsScreen | ||
import com.devmike.saveditems.SavedItemsScreen | ||
import com.devmike.search.SearchScreen | ||
|
||
@Composable | ||
fun AppNavigation( | ||
modifier: Modifier = Modifier, | ||
navController: NavHostController, | ||
startDestination: AppDestinations = AppDestinations.SearchScreen, | ||
) { | ||
NavHost(modifier = modifier, navController = navController, startDestination = startDestination) { | ||
composable<AppDestinations.SearchScreen> { | ||
SearchScreen { foodName -> | ||
navController.navigate(AppDestinations.FoodDetails(name = foodName)) | ||
} | ||
} | ||
|
||
composable<AppDestinations.FoodDetails> { backStackEntry -> | ||
FoodDetailsScreen { | ||
navController.navigateUp() | ||
} | ||
} | ||
|
||
composable<AppDestinations.SavedFood> { | ||
SavedItemsScreen { foodName -> | ||
navController.navigate(AppDestinations.FoodDetails(name = foodName)) | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/devmike/caloriebytez/navigation/CalorieBottomBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.devmike.caloriebytez.navigation | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.material3.BottomAppBar | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.NavigationBarItem | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavDestination.Companion.hasRoute | ||
import androidx.navigation.NavDestination.Companion.hierarchy | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.currentBackStackEntryAsState | ||
|
||
@Composable | ||
fun CalorieBottomBar(navController: NavHostController) { | ||
val navBackStackEntry by navController.currentBackStackEntryAsState() | ||
val currentDestination: NavDestination? = navBackStackEntry?.destination | ||
|
||
val showBottomNav = | ||
TopLevelDestinations.entries.map { it.route::class }.any { route -> | ||
currentDestination?.hierarchy?.any { | ||
it.hasRoute(route) | ||
} == true | ||
} | ||
|
||
AnimatedVisibility(visible = showBottomNav) { | ||
BottomAppBar { | ||
TopLevelDestinations.entries.map { bottomNavigationItem -> | ||
val isSelected = | ||
currentDestination?.hierarchy?.any { it.hasRoute(bottomNavigationItem.route::class) } == true | ||
|
||
if (currentDestination != null) { | ||
NavigationBarItem( | ||
selected = isSelected, | ||
onClick = { | ||
navController.navigate(bottomNavigationItem.route) { | ||
popUpTo(navController.graph.startDestinationId) { | ||
saveState = true | ||
} | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
}, | ||
icon = { | ||
Icon( | ||
imageVector = | ||
if (isSelected) { | ||
bottomNavigationItem.selectedIcon | ||
} else { | ||
bottomNavigationItem.unselectedIcon | ||
}, | ||
contentDescription = bottomNavigationItem.label, | ||
) | ||
}, | ||
alwaysShowLabel = isSelected, | ||
label = { | ||
Text(bottomNavigationItem.label) | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/devmike/caloriebytez/navigation/TopLevelDestinations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.devmike.caloriebytez.navigation | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Bookmarks | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material.icons.outlined.Bookmarks | ||
import androidx.compose.material.icons.outlined.Search | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import com.devmike.domain.models.AppDestinations | ||
|
||
enum class TopLevelDestinations( | ||
val label: String, | ||
val selectedIcon: ImageVector, | ||
val unselectedIcon: ImageVector, | ||
val route: AppDestinations, | ||
) { | ||
Search( | ||
label = "Search", | ||
selectedIcon = Icons.Filled.Search, | ||
unselectedIcon = Icons.Outlined.Search, | ||
route = AppDestinations.SearchScreen, | ||
), | ||
|
||
SavedItems( | ||
label = "Saved", | ||
selectedIcon = Icons.Filled.Bookmarks, | ||
unselectedIcon = Icons.Outlined.Bookmarks, | ||
route = AppDestinations.SavedFood, | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.gradle | ||
/convention/build |
Oops, something went wrong.