Skip to content

Commit

Permalink
Merge pull request #178 from aarash709/ui/type-safe-navigation
Browse files Browse the repository at this point in the history
Type safe navigation
  • Loading branch information
aarash709 authored Sep 11, 2024
2 parents 60505e1 + d6c7b68 commit e5e8b9d
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 238 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ android {
buildFeatures {
compose = true
}
composeCompiler{
enableStrongSkippingMode = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.experiment.voicerecorder.ui

import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import com.google.accompanist.permissions.ExperimentalPermissionsApi

@OptIn(ExperimentalMaterialApi::class)
@ExperimentalPermissionsApi
@Composable
fun RecorderApp() {
VoiceRecorderPermissionsHandler {
VoiceRecorderNavigation()
}
VoiceRecorderNavigation()
}


Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package com.experiment.voicerecorder.ui

import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.recorder.core.designsystem.theme.LocalSharedTransitionScope
import com.recorder.feature.playlist.PLAYLIST_ROUTE
import com.recorder.feature.playlist.PlaylistRoute
import com.recorder.feature.playlist.playlist
import com.recorder.feature.playlist.toPlaylist
import com.recorder.feature.record.RECORDER_ROUTE
import com.recorder.feature.record.RecorderRoute
import com.recorder.feature.record.recorder
import com.recorder.feature.record.toRecorder
import com.recorder.feature.settings.settings
Expand All @@ -31,21 +29,21 @@ fun VoiceRecorderNavigation(
CompositionLocalProvider(value = LocalSharedTransitionScope provides this) {
NavHost(
navController = navController,
startDestination = PLAYLIST_ROUTE
startDestination = PlaylistRoute
) {
playlist(
onNavigateToSettings = { navController.toSettings() },
onNavigateToRecorder = {
navController.toRecorder(navOptions = navOptions {
popUpTo(route = PLAYLIST_ROUTE, popUpToBuilder = { inclusive = true })
popUpTo(route = PlaylistRoute, popUpToBuilder = { inclusive = true })
})
},
onBackPressed = { navController.popBackStack() },
)
recorder(onNavigateToPlaylist = {
navController.toPlaylist(
navOptions = navOptions {
popUpTo(route = RECORDER_ROUTE, popUpToBuilder = { inclusive = true })
popUpTo(route = RecorderRoute, popUpToBuilder = { inclusive = true })
}
)
})
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ android {
buildFeatures {
compose = true
}
composeCompiler{
enableStrongSkippingMode = true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ object ServiceModule {
return MediaRecorder(context)

}
// @AndroidSDK30MediaRecorder

// @AndroidSDK30MediaRecorder
@Provides
fun providesMediaRecorderForAndroidR(): MediaRecorder {
@Suppress("DEPRECATION")
return MediaRecorder()
}

@Provides
fun providesNotificationManager(
@ApplicationContext context: Context,
): NotificationManager {
return context.
getSystemService(NotificationManager::class.java) as NotificationManager
return context.getSystemService(NotificationManager::class.java) as NotificationManager
}
}

Expand Down
4 changes: 1 addition & 3 deletions feature/playlist/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.compose)
alias(libs.plugins.hilt)
alias(libs.plugins.kotlinx.ksp)
alias(libs.plugins.kotlin.serialization)
}

android {
Expand All @@ -23,9 +24,6 @@ android {
buildFeatures{
compose = true
}
composeCompiler{
enableStrongSkippingMode = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,40 @@ package com.recorder.feature.playlist

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import kotlinx.serialization.Serializable

const val PLAYLIST_ROUTE = "PLAYLIST_ROUTE"
@Serializable
object PlaylistRoute

fun NavController.toPlaylist(navOptions: NavOptions? = null) {
navigate(PLAYLIST_ROUTE, navOptions)
navigate(PlaylistRoute, navOptions)
}

fun NavGraphBuilder.playlist(
onNavigateToSettings: () -> Unit,
onNavigateToRecorder: () -> Unit,
onBackPressed: () -> Unit,
) {
composable(
route = PLAYLIST_ROUTE,
composable<PlaylistRoute>(
enterTransition = {
when (initialState.destination.route) {
"RECORDER_ROUTE" -> {
fadeIn(initialAlpha = 0.5f) + scaleIn(initialScale = 0.9f)
}
else -> slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(400),
initialOffset = { it / 3 }
)
}
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(400),
initialOffset = { it / 3 }
)
// }
},
exitTransition = {
when (targetState.destination.route) {
"RECORDER_ROUTE" -> {
fadeOut(targetAlpha = 0f) + scaleOut(targetScale = 0.9f)
}
else -> slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(400),
targetOffset = { it / 3 }
)
}
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(400),
targetOffset = { it / 3 }
)
// }
}) {

Playlist(
Expand Down
4 changes: 1 addition & 3 deletions feature/record/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.compose)
alias(libs.plugins.hilt)
alias(libs.plugins.kotlinx.ksp)
alias(libs.plugins.kotlin.serialization)
}

android {
Expand All @@ -22,9 +23,6 @@ android {
buildFeatures{
compose = true
}
composeCompiler{
enableStrongSkippingMode = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
Loading

0 comments on commit e5e8b9d

Please sign in to comment.