Skip to content

Commit

Permalink
change the camera screen, its permissions and component visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lokified committed Sep 19, 2023
1 parent 79ab382 commit dcbc1e2
Show file tree
Hide file tree
Showing 23 changed files with 591 additions and 333 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- 'master'
tags:
- 'v*'
pull_request:
types:
- closed

jobs:
apk:
Expand Down Expand Up @@ -34,7 +37,7 @@ jobs:
run: bash ./gradlew assembleDebug --stacktrace

- name: Upload APK
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: apk
path: app/build/outputs/apk/debug/app-debug.apk
Expand All @@ -46,7 +49,7 @@ jobs:

steps:
- name: Download APK from build
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: apk

Expand All @@ -56,12 +59,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v1.2.0
release_name: ${{ github.event.repository.name }} v1.2.0
tag_name: v0.3.0-beta
release_name: ${{ github.event.repository.name }} v0.3.0-beta

- name: Upload Release APK
id: upload_release_asset
uses: actions/upload-release-asset@v1.0.1
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
96 changes: 81 additions & 15 deletions core/navigation/src/main/java/com/loki/navigation/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import com.loki.report.ReportScreen
import com.loki.report.ReportViewModel
import com.loki.settings.SettingsScreen
import com.loki.settings.SettingsViewModel
import com.loki.ui.utils.Constants.CAMERA_SCREEN_TYPE
import com.loki.ui.utils.Constants.REPORT_ID
import com.loki.ui.utils.Constants.SCREEN_TYPE_PROFILE_CAMERA
import com.loki.ui.utils.Constants.SCREEN_TYPE_REPORT_CAMERA
import com.loki.ui.utils.Constants.VIDEO_URI
import kotlinx.coroutines.delay

Expand Down Expand Up @@ -153,30 +156,60 @@ fun NavGraphBuilder.reportListScreen(onNavigateTo: (Screen) -> Unit, viewModel:
}
}

fun NavGraphBuilder.newReportScreen(onNavigateTo: (Screen) -> Unit, viewModel: NavigationViewModel) {
fun NavGraphBuilder.newReportScreen(
onNavigateTo: (Screen) -> Unit,
viewModel: NavigationViewModel,
newReportViewModel: NewReportViewModel
) {
composable(
route = Screen.NewReportScreen.route,
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Up,
animationSpec = tween(600)
)
when(initialState.destination.route) {
Screen.CameraScreen.route -> {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(600)
)
}

Screen.ReportListScreen.route -> {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Up,
animationSpec = tween(600)
)
}
else -> null
}
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Down,
animationSpec = tween(200)
)
when(targetState.destination.route) {
Screen.ReportListScreen.route -> {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Down,
animationSpec = tween(200)
)
}

Screen.CameraScreen.route -> {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(200)
)
}
else -> null
}
}
) {
LaunchedEffect(key1 = viewModel.isBottomBarVisible.value) {
viewModel.setBottomBarVisible(false)
}
val newReportViewModel = hiltViewModel<NewReportViewModel>()
NewReportScreen(
viewModel = newReportViewModel,
navigateToHome = {
onNavigateTo(Screen.ReportListScreen)
},
navigateToCamera = {
onNavigateTo(Screen.CameraScreen.navWith(SCREEN_TYPE_REPORT_CAMERA))
}
)
}
Expand Down Expand Up @@ -234,7 +267,11 @@ fun NavGraphBuilder.accountNavGraph(viewModel: NavigationViewModel, onNavigateTo
}
}

fun NavGraphBuilder.profileScreen(onNavigateTo: (Screen) -> Unit, onNavigateToLogin: (Screen) -> Unit, viewModel: NavigationViewModel) {
fun NavGraphBuilder.profileScreen(
onNavigateTo: (Screen) -> Unit,
onNavigateToLogin: (Screen) -> Unit,
viewModel: NavigationViewModel
) {
composable(route = Screen.ProfileScreen.route) {
LaunchedEffect(key1 = viewModel.isBottomBarVisible.value) {
viewModel.setBottomBarVisible(true)
Expand All @@ -246,7 +283,7 @@ fun NavGraphBuilder.profileScreen(onNavigateTo: (Screen) -> Unit, onNavigateToLo
navigateToSettings = { onNavigateTo(Screen.SettingsScreen) },
navigateToChangeUsername = { onNavigateTo(Screen.UsernameChangeScreen) },
navigateToLogin = { onNavigateToLogin(Screen.LoginScreen) },
navigateToCamera = { onNavigateTo(Screen.CameraScreen) }
navigateToCamera = { onNavigateTo(Screen.CameraScreen.navWith(SCREEN_TYPE_PROFILE_CAMERA)) }
)
}
}
Expand Down Expand Up @@ -305,9 +342,19 @@ fun NavGraphBuilder.settingsScreen(onNavigateBack: () -> Unit, viewModel: Naviga
}
}

fun NavGraphBuilder.cameraScreen(onNavigateBack: () -> Unit, onNavigateTo: (Screen) -> Unit, viewModel: NavigationViewModel) {
fun NavGraphBuilder.cameraScreen(
onNavigateBack: () -> Unit,
onNavigateTo: (Screen) -> Unit,
viewModel: NavigationViewModel,
newReportViewModel: NewReportViewModel
) {
composable(
route = Screen.CameraScreen.route,
route = Screen.CameraScreen.withCameraScreenType(),
arguments = listOf(
navArgument(CAMERA_SCREEN_TYPE) {
type = NavType.StringType
}
),
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
Expand All @@ -324,12 +371,31 @@ fun NavGraphBuilder.cameraScreen(onNavigateBack: () -> Unit, onNavigateTo: (Scre
LaunchedEffect(key1 = viewModel.isBottomBarVisible.value) {
viewModel.setBottomBarVisible(false)
}

val profileViewModel = hiltViewModel<ProfileViewModel>()
val screenType = it.arguments?.getString(CAMERA_SCREEN_TYPE)!!

CameraScreen(
navigateBack = onNavigateBack,
screenType = screenType,
profileViewModel = profileViewModel,
navigateToVideoPlayer = { videoUri ->
onNavigateTo(Screen.VideoPlayerScreen.navWith(videoUri))
},
onSaveImage = { uri, screenSource ->

when(screenSource) {
SCREEN_TYPE_PROFILE_CAMERA -> {
profileViewModel.updateProfilePicture(
imageUri = uri,
onSuccess = onNavigateBack
)
}
SCREEN_TYPE_REPORT_CAMERA -> {
newReportViewModel.onChangeImageUri(uri)
onNavigateBack()
}
}
}
)
}
Expand All @@ -345,7 +411,7 @@ fun NavGraphBuilder.videoPlayerScreen(viewModel: NavigationViewModel) {
),
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Down,
towards = AnimatedContentTransitionScope.SlideDirection.Up,
animationSpec = tween(500)
)
},
Expand Down
7 changes: 6 additions & 1 deletion core/navigation/src/main/java/com/loki/navigation/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Newspaper
import androidx.compose.ui.graphics.vector.ImageVector
import com.loki.ui.utils.Constants.CAMERA_SCREEN_TYPE
import com.loki.ui.utils.Constants.REPORT_ID
import com.loki.ui.utils.Constants.VIDEO_URI

Expand All @@ -25,6 +26,10 @@ sealed class Screen(
return "${ReportScreen.route}/{$REPORT_ID}"
}

fun withCameraScreenType(): String {
return "${CameraScreen.route}/{$CAMERA_SCREEN_TYPE}"
}

fun withVideoUri(): String {
return "${VideoPlayerScreen.route}/{$VIDEO_URI}"
}
Expand All @@ -33,7 +38,7 @@ sealed class Screen(
object RegisterScreen: Screen("register_screen")
object ForgotPasswordScreen: Screen("forgot_password_screen")
object HomeScreen: Screen("home_screen")
object ReportListScreen: Screen(route = "report_list_screen", title = "Home", icon = Icons.Filled.Home, restoreState = false)
object ReportListScreen: Screen(route = "report_list_screen", title = "Home", icon = Icons.Filled.Home)
object NewsScreen: Screen(route = "news_screen", title = "News", restoreState = false, icon = Icons.Filled.Newspaper)
object NewReportScreen: Screen("new_report_screen")
object ReportScreen: Screen("report_screen", restoreState = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.loki.navigation.ext

import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import com.loki.navigation.Screen

fun NavController.navigateTo(
Expand All @@ -15,8 +14,10 @@ fun NavController.navigateTo(
} ?: screen.route

navigate(route) {
popUpTo(graph.findStartDestination().id) {
saveState = true
if (screen.icon != null) {
popUpTo(Screen.ReportListScreen.route) {
saveState = true
}
}
launchSingleTop = true
restoreState = screen.restoreState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.loki.navigation.graph

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.loki.navigation.NavigationViewModel
Expand All @@ -12,6 +13,7 @@ import com.loki.navigation.profileScreen
import com.loki.navigation.settingsScreen
import com.loki.navigation.usernameChangeScreen
import com.loki.navigation.videoPlayerScreen
import com.loki.new_report.NewReportViewModel

@Composable
fun AccountNavGraph(
Expand All @@ -20,16 +22,25 @@ fun AccountNavGraph(
viewModel: NavigationViewModel,
onNavigateToLogin: (Screen) -> Unit
) {
val newReportViewModel = hiltViewModel<NewReportViewModel>()

NavHost(
navController = navController,
startDestination = Screen.ProfileScreen.route,
modifier = modifier
) {
profileScreen(onNavigateTo = navController::navigateTo, viewModel = viewModel, onNavigateToLogin = onNavigateToLogin)
profileScreen(
onNavigateTo = navController::navigateTo,
viewModel = viewModel,
onNavigateToLogin = onNavigateToLogin
)
usernameChangeScreen(onNavigateBack = navController::navigateUp, viewModel = viewModel)
settingsScreen(onNavigateBack = navController::navigateUp, viewModel = viewModel)
cameraScreen(onNavigateBack = navController::navigateUp, onNavigateTo = navController::navigateTo, viewModel = viewModel)
videoPlayerScreen(viewModel = viewModel)
cameraScreen(
onNavigateBack = navController::navigateUp,
onNavigateTo = navController::navigateTo,
viewModel = viewModel,
newReportViewModel = newReportViewModel
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ package com.loki.navigation.graph

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.loki.navigation.NavigationViewModel
import com.loki.navigation.Screen
import com.loki.navigation.cameraScreen
import com.loki.navigation.ext.navigateTo
import com.loki.navigation.newReportScreen
import com.loki.navigation.reportListScreen
import com.loki.navigation.reportScreen
import com.loki.new_report.NewReportViewModel

@Composable
fun ReportNavGraph(
modifier: Modifier = Modifier,
navController: NavHostController,
viewModel: NavigationViewModel
) {
val newReportViewModel = hiltViewModel<NewReportViewModel>()

NavHost(
navController = navController,
Expand All @@ -25,7 +29,17 @@ fun ReportNavGraph(
) {

reportListScreen(onNavigateTo = navController::navigateTo, viewModel = viewModel)
reportScreen(onNavigateBack = { navController.popBackStack() }, viewModel = viewModel)
newReportScreen(onNavigateTo = navController::navigateTo, viewModel = viewModel)
reportScreen(onNavigateBack = navController::navigateUp, viewModel = viewModel)
newReportScreen(
onNavigateTo = navController::navigateTo,
viewModel = viewModel,
newReportViewModel = newReportViewModel
)
cameraScreen(
onNavigateBack = navController::navigateUp,
onNavigateTo = navController::navigateTo,
viewModel = viewModel,
newReportViewModel = newReportViewModel
)
}
}
5 changes: 3 additions & 2 deletions core/ui/src/main/java/com/loki/ui/components/Loading.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import androidx.compose.ui.Modifier

@Composable
fun Loading(
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.Center
) {
Box(
modifier = modifier.fillMaxSize()
.background(
MaterialTheme.colorScheme.background.copy(.5f)
),
contentAlignment = Alignment.Center
contentAlignment = alignment
) {
CircularProgressIndicator()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package com.loki.ui.permission
sealed class PermissionAction {
object PermissionGranted: PermissionAction()
object PermissionDenied: PermissionAction()
object PermissionAlreadyGranted: PermissionAction()
}
Loading

0 comments on commit dcbc1e2

Please sign in to comment.