-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏗️Restructured the app using Jetpack Navigation
- Loading branch information
1 parent
cb85980
commit 8e56514
Showing
48 changed files
with
1,658 additions
and
1,657 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/lorenzovainigli/foodexpirationdates/view/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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.lorenzovainigli.foodexpirationdates.view | ||
|
||
import android.os.Build | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.viewModels | ||
import androidx.annotation.RequiresApi | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
import androidx.core.view.WindowCompat | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import androidx.navigation.compose.rememberNavController | ||
import com.lorenzovainigli.foodexpirationdates.di.AppModule | ||
import com.lorenzovainigli.foodexpirationdates.di.DaggerAppComponent | ||
import com.lorenzovainigli.foodexpirationdates.model.NotificationManager | ||
import com.lorenzovainigli.foodexpirationdates.model.repository.PreferencesRepository | ||
import com.lorenzovainigli.foodexpirationdates.ui.theme.FoodExpirationDatesTheme | ||
import com.lorenzovainigli.foodexpirationdates.view.composable.MyScaffold | ||
import com.lorenzovainigli.foodexpirationdates.viewmodel.ExpirationDatesViewModel | ||
import com.lorenzovainigli.foodexpirationdates.viewmodel.PreferencesViewModel | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class MainActivity : ComponentActivity() { | ||
|
||
val viewModel: ExpirationDatesViewModel by viewModels() | ||
val preferencesViewModel: PreferencesViewModel by viewModels() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
|
||
val splashScreen = installSplashScreen() | ||
splashScreen.setKeepOnScreenCondition { viewModel.isSplashScreenLoading.value } | ||
|
||
DaggerAppComponent.builder() | ||
.appModule(AppModule()) | ||
.build() | ||
NotificationManager.setupNotificationChannel(this) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
override fun onResume() { | ||
super.onResume() | ||
val context = this | ||
setContent { | ||
val viewModel: ExpirationDatesViewModel = viewModel() | ||
val prefsViewModel: PreferencesViewModel = viewModel() | ||
val darkThemeState = prefsViewModel.getThemeMode(context).collectAsState().value | ||
val dynamicColorsState = prefsViewModel.getDynamicColors(context).collectAsState().value | ||
val isInDarkTheme = when (darkThemeState) { | ||
PreferencesRepository.Companion.ThemeMode.LIGHT.ordinal -> false | ||
PreferencesRepository.Companion.ThemeMode.DARK.ordinal -> true | ||
else -> isSystemInDarkTheme() | ||
} | ||
FoodExpirationDatesTheme( | ||
darkTheme = isInDarkTheme, | ||
dynamicColor = dynamicColorsState | ||
) { | ||
Surface( | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
val navController = rememberNavController() | ||
val showSnackbar = remember { | ||
mutableStateOf(false) | ||
} | ||
MyScaffold( | ||
activity = this, | ||
navController = navController, | ||
showSnackbar = showSnackbar | ||
) { | ||
Navigation( | ||
activity = this, | ||
navController = navController, | ||
showSnackbar = showSnackbar | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/lorenzovainigli/foodexpirationdates/view/Navigation.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,76 @@ | ||
package com.lorenzovainigli.foodexpirationdates.view | ||
|
||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.ui.Modifier | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.NavType | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.navArgument | ||
import com.lorenzovainigli.foodexpirationdates.view.composable.screen.InfoScreen | ||
import com.lorenzovainigli.foodexpirationdates.view.composable.screen.InsertScreen | ||
import com.lorenzovainigli.foodexpirationdates.view.composable.screen.MainScreen | ||
import com.lorenzovainigli.foodexpirationdates.view.composable.screen.Screen | ||
import com.lorenzovainigli.foodexpirationdates.view.composable.screen.SettingsScreen | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
@Composable | ||
fun Navigation( | ||
activity: MainActivity? = null, | ||
navController: NavHostController, | ||
showSnackbar: MutableState<Boolean> | ||
) { | ||
NavHost( | ||
modifier = Modifier.fillMaxSize(), | ||
navController = navController, | ||
startDestination = Screen.MainScreen.route | ||
) { | ||
composable(route = Screen.MainScreen.route) { | ||
MainScreen( | ||
activity = activity, | ||
navController = navController, | ||
showSnackbar = showSnackbar | ||
) | ||
} | ||
composable( | ||
route = Screen.InsertScreen.route + "?itemId={itemId}", | ||
arguments = listOf( | ||
navArgument("itemId"){ | ||
type = NavType.StringType | ||
nullable = true | ||
} | ||
) | ||
){ entry -> | ||
InsertScreen( | ||
activity = activity, | ||
navController = navController, | ||
itemId = entry.arguments?.getString("itemId") | ||
) | ||
} | ||
composable(route = Screen.AboutScreen.route){ | ||
InfoScreen() | ||
} | ||
composable(route = Screen.SettingsScreen.route){ | ||
SettingsScreen(activity = activity) | ||
} | ||
} | ||
} | ||
|
||
//@RequiresApi(Build.VERSION_CODES.O) | ||
//@Preview | ||
//@Composable | ||
//fun NavigationPreview(){ | ||
// FoodExpirationDatesTheme { | ||
// Surface(modifier = Modifier.fillMaxSize()) { | ||
// Navigation( | ||
// navController = rememberNavController(), | ||
// coroutineScope = rememberCoroutineScope(), | ||
// snackbarHostState = SnackbarHostState() | ||
// ) | ||
// } | ||
// } | ||
//} |
Oops, something went wrong.