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

Development #327

Merged
merged 4 commits into from
Jan 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

defaultConfig {
applicationId = "com.joeloewi.croissant"
versionCode = 49
versionCode = 50
versionName = "1.2.2"
targetSdk = 34

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
<meta-data
android:name="com.joeloewi.croissant.initializer.NotificationChannelInitializer"
android:value="androidx.startup" />
<meta-data
android:name="com.joeloewi.croissant.initializer.DynamicColorInitializer"
android:value="androidx.startup" />
<meta-data
android:name="com.joeloewi.croissant.initializer.WorkManagerInitializer"
android:value="androidx.startup" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.joeloewi.croissant

import android.app.Application
import com.google.android.material.color.DynamicColors
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class CroissantApplication : Application()
class CroissantApplication : Application() {
override fun onCreate() {
super.onCreate()
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
126 changes: 69 additions & 57 deletions app/src/main/kotlin/com/joeloewi/croissant/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.window.DialogProperties
import androidx.core.os.bundleOf
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
Expand All @@ -62,7 +63,6 @@ import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink
import com.google.android.material.color.DynamicColors
import com.google.firebase.Firebase
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.analytics
Expand Down Expand Up @@ -108,10 +108,9 @@ class MainActivity : AppCompatActivity() {
@SuppressLint("HardwareIds")
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
enableEdgeToEdge()
super.onCreate(savedInstanceState)

DynamicColors.applyToActivityIfAvailable(this)
enableEdgeToEdge()

lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
Expand All @@ -125,12 +124,14 @@ class MainActivity : AppCompatActivity() {
}
}

Firebase.analytics.setUserId(
Settings.Secure.getString(
contentResolver,
Settings.Secure.ANDROID_ID
lifecycleScope.launch(Dispatchers.IO + CoroutineExceptionHandler { _, _ -> }) {
Firebase.analytics.setUserId(
Settings.Secure.getString(
contentResolver,
Settings.Secure.ANDROID_ID
)
)
)
}

setContent {
CroissantTheme {
Expand All @@ -155,7 +156,6 @@ class MainActivity : AppCompatActivity() {
}
}

@SuppressLint("RestrictedApi")
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable
fun CroissantApp(
Expand All @@ -179,7 +179,6 @@ fun CroissantApp(
GlobalDestination.EmptyScreen.route
).toImmutableList()
}
val currentBackStack by navController.currentBackStack.collectAsStateWithLifecycle()
val windowSizeClass = calculateWindowSizeClass(activity = activity)
val croissantNavigations = remember {
listOf(
Expand All @@ -206,9 +205,9 @@ fun CroissantApp(
Scaffold(
contentWindowInsets = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal),
bottomBar = {
val currentBackStackEntry by navController.currentBackStackEntryFlow.collectAsStateWithLifecycle(
initialValue = null,
)
val currentBackStackEntry by remember(navController) {
navController.currentBackStackEntryFlow
}.collectAsStateWithLifecycle(initialValue = null)
val isBottomNavigationBarVisible by remember {
derivedStateOf {
!fullScreenDestinations.any { route ->
Expand All @@ -226,26 +225,7 @@ fun CroissantApp(
currentBackStackEntry = { currentBackStackEntry },
onClickNavigationButton = { route ->
navController.navigate(route) {
val startDestination =
navController.graph.findStartDestination()

val popUpToDestination =
if (currentBackStack.any {
it.destination == startDestination
}) {

startDestination.route
?: activity::class.java.simpleName
} else if (currentBackStack.any {
it.destination.route == AttendancesDestination.AttendancesScreen.route
}) {

AttendancesDestination.AttendancesScreen.route
} else {
activity::class.java.simpleName
}

popUpTo(popUpToDestination) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
Expand Down Expand Up @@ -372,7 +352,7 @@ fun CroissantNavHost(
},
onClickAttendance = {
navController.value.navigate(
AttendancesDestination.AttendanceDetailScreen().generateRoute(it.id)
AttendancesDestination.AttendanceDetailScreen.generateRoute(it.id)
)
}
)
Expand All @@ -390,7 +370,7 @@ fun CroissantNavHost(
},
onNavigateToAttendanceDetailScreen = {
navController.value.navigate(
AttendancesDestination.AttendanceDetailScreen().generateRoute(it)
AttendancesDestination.AttendanceDetailScreen.generateRoute(it)
) {
popUpTo(AttendancesDestination.CreateAttendanceScreen.route) {
inclusive = true
Expand Down Expand Up @@ -420,32 +400,54 @@ fun CroissantNavHost(
}

composable(
route = AttendancesDestination.AttendanceDetailScreen().route,
arguments = AttendancesDestination.AttendanceDetailScreen().arguments.map { argument ->
navArgument(argument.first) {
type = argument.second
}
route = AttendancesDestination.AttendanceDetailScreen.route,
arguments = AttendancesDestination.AttendanceDetailScreen.arguments.map { argument ->
navArgument(argument.first, argument.second)
},
deepLinks = listOf(
navDeepLink {
uriPattern =
"$deepLinkUri/${AttendancesDestination.AttendanceDetailScreen().route}"
"$deepLinkUri/${AttendancesDestination.AttendanceDetailScreen.route}"
}
)
) {
) { navBackStackEntry ->
val fromDeeplink = remember(navBackStackEntry.arguments) {
navBackStackEntry.arguments?.getBoolean(AttendancesDestination.AttendanceDetailScreen.FROM_DEEPLINK)
?: false
}
val newCookie by remember {
it.savedStateHandle.getStateFlow(COOKIE, "")
navBackStackEntry.savedStateHandle.getStateFlow(COOKIE, "")
}.collectAsStateWithLifecycle()

LaunchedEffect(fromDeeplink) {
if (fromDeeplink) {
with(navController.value.graph) {
findNode(CroissantNavigation.Attendances.route)?.id?.let {
setStartDestination(
it
)
}
}
}
}

AttendanceDetailScreen(
newCookie = { newCookie },
onNavigateUp = { navController.value.navigateUp() },
onNavigateUp = {
if (fromDeeplink) {
with(navController.value) {
popBackStack(graph.findStartDestination().id, inclusive = true)
}
} else {
navController.value.navigateUp()
}
},
onClickRefreshSession = {
navController.value.navigate(AttendancesDestination.LoginHoYoLabScreen.route)
},
onClickLogSummary = { attendanceId, loggableWorker ->
navController.value.navigate(
AttendancesDestination.AttendanceLogsCalendarScreen().generateRoute(
AttendancesDestination.AttendanceLogsCalendarScreen.generateRoute(
attendanceId,
loggableWorker
)
Expand All @@ -455,18 +457,16 @@ fun CroissantNavHost(
}

composable(
route = AttendancesDestination.AttendanceLogsCalendarScreen().route,
arguments = AttendancesDestination.AttendanceLogsCalendarScreen().arguments.map { argument ->
navArgument(argument.first) {
type = argument.second
}
route = AttendancesDestination.AttendanceLogsCalendarScreen.route,
arguments = AttendancesDestination.AttendanceLogsCalendarScreen.arguments.map { argument ->
navArgument(argument.first, argument.second)
}
) {
AttendanceLogsCalendarScreen(
onNavigateUp = { navController.value.navigateUp() },
onClickDay = { attendanceId, loggableWorker, localDate ->
navController.value.navigate(
AttendancesDestination.AttendanceLogsDayScreen().generateRoute(
AttendancesDestination.AttendanceLogsDayScreen.generateRoute(
attendanceId = attendanceId,
loggableWorker = loggableWorker,
localDate = localDate,
Expand All @@ -477,11 +477,9 @@ fun CroissantNavHost(
}

composable(
route = AttendancesDestination.AttendanceLogsDayScreen().route,
arguments = AttendancesDestination.AttendanceLogsDayScreen().arguments.map { argument ->
navArgument(argument.first) {
type = argument.second
}
route = AttendancesDestination.AttendanceLogsDayScreen.route,
arguments = AttendancesDestination.AttendanceLogsDayScreen.arguments.map { argument ->
navArgument(argument.first, argument.second)
}
) {
AttendanceLogsDayScreen(
Expand Down Expand Up @@ -534,6 +532,13 @@ fun CroissantNavHost(
}
},
onShowDefaultScreen = {
with(navController.value.graph) {
findNode(CroissantNavigation.Attendances.route)?.id?.let {
setStartDestination(
it
)
}
}
navController.value.navigate(AttendancesDestination.AttendancesScreen.route) {
popUpTo(activity::class.java.simpleName) {
inclusive = true
Expand All @@ -546,6 +551,13 @@ fun CroissantNavHost(
composable(route = GlobalDestination.FirstLaunchScreen.route) {
FirstLaunchScreen(
onNavigateToAttendances = {
with(navController.value.graph) {
findNode(CroissantNavigation.Attendances.route)?.id?.let {
setStartDestination(
it
)
}
}
navController.value.navigate(AttendancesDestination.AttendancesScreen.route) {
popUpTo(activity::class.java.simpleName) {
inclusive = true
Expand Down Expand Up @@ -615,7 +627,7 @@ private fun CroissantBottomNavigationBar(
NavigationBar(
modifier = modifier
) {
croissantNavigations.forEach { croissantNavigation ->
croissantNavigations.fastForEach { croissantNavigation ->
key(croissantNavigation.route) {
val isSelected by remember(croissantNavigation.route) {
derivedStateOf { currentBackStackEntry()?.destination?.hierarchy?.any { it.route == croissantNavigation.route } == true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.google.android.material.color.DynamicColors
import com.google.firebase.Firebase
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.analytics
Expand Down Expand Up @@ -61,7 +60,6 @@ class ResinStatusWidgetConfigurationActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
DynamicColors.applyToActivityIfAvailable(this)

lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
Expand Down Expand Up @@ -143,10 +141,7 @@ fun ResinStatusWidgetConfigurationApp() {
composable(
route = ResinStatusWidgetConfigurationDestination.LoadingScreen().route,
arguments = ResinStatusWidgetConfigurationDestination.LoadingScreen().arguments.map { argument ->
navArgument(argument.first) {
type = argument.second
defaultValue = AppWidgetManager.INVALID_APPWIDGET_ID
}
navArgument(argument.first, argument.second)
}
) {
val loadingViewModel: LoadingViewModel = hiltViewModel()
Expand All @@ -160,9 +155,7 @@ fun ResinStatusWidgetConfigurationApp() {
composable(
route = ResinStatusWidgetConfigurationDestination.CreateResinStatusWidgetScreen().route,
arguments = ResinStatusWidgetConfigurationDestination.CreateResinStatusWidgetScreen().arguments.map { argument ->
navArgument(argument.first) {
type = argument.second
}
navArgument(argument.first, argument.second)
},
) {
val newCookie by remember {
Expand Down Expand Up @@ -196,9 +189,7 @@ fun ResinStatusWidgetConfigurationApp() {
composable(
route = ResinStatusWidgetConfigurationDestination.ResinStatusWidgetDetailScreen().route,
arguments = ResinStatusWidgetConfigurationDestination.ResinStatusWidgetDetailScreen().arguments.map { argument ->
navArgument(argument.first) {
type = argument.second
}
navArgument(argument.first, argument.second)
}
) {
ResinStatusWidgetDetailScreen()
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/kotlin/com/joeloewi/croissant/di/EntryPoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.joeloewi.croissant.di

import android.app.Application
import android.content.Context
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.RunnableScheduler
Expand All @@ -35,7 +34,6 @@ import kotlin.reflect.KClass
interface InitializerEntryPoint {
fun imageLoader(): ImageLoader
fun hiltWorkerFactory(): HiltWorkerFactory
fun application(): Application

@DefaultDispatcherExecutor
fun executor(): Executor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object UtilModule {
@ApplicationContext context: Context
): TextToSpeechFactory = TextToSpeechFactory(context)

@Singleton
@Provides
fun provideNotificationGenerator(
@ApplicationContext context: Context
Expand Down

This file was deleted.

Loading