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

check description #34

Merged
merged 5 commits into from
Jun 14, 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
15 changes: 14 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
deployments: write

steps:
- name: Checkout repository
Expand Down Expand Up @@ -70,6 +75,12 @@ jobs:
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
issues: write
deployments: write

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -120,7 +131,9 @@ jobs:

- name: Get commit title
id: get_commit_title
run: echo "COMMIT_TITLE=$(git log -1 --pretty=%s | tr -d '\n' | tr -d '\r')" >> $GITHUB_ENV
run: |
COMMIT_TITLE=$(git log -1 --pretty=%s)
echo "COMMIT_TITLE=$(echo $COMMIT_TITLE | tr -d '\n' | tr -d '\r')" >> $GITHUB_ENV
shell: bash

- name: Create GitHub Release
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/singa/asl/MainActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MainActivityViewModel(


fun logout(
navigateToWelcome: () -> Unit
navigateToLogin: () -> Unit
) {
viewModelScope.launch {
singaUseCase.logout().collect {
Expand All @@ -96,7 +96,7 @@ class MainActivityViewModel(
showAlert("Success", "Logout success")
_logoutIsLoading.value = false
_authUser.value = Resource.Empty()
navigateToWelcome()
navigateToLogin()
}

is Resource.Empty -> {
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/singa/asl/ui/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun MainApp(
getAuthUser: () -> Unit,
isSecondLaunch: Boolean,
onLogouts: (
navigateToWelcome: () -> Unit,
navigateToLogin: () -> Unit,
) -> Unit,
logoutIsLoading: Boolean,
onUpdateProfile: (
Expand Down Expand Up @@ -154,7 +154,7 @@ fun MainApp(
},
resetForm = viewModel::resetForm,
navigateBack = {
navController.popBackStack()
navController.navigateUp()
}
)
}
Expand Down Expand Up @@ -361,7 +361,7 @@ fun MainApp(
},
onConfirmLogout = {
onLogouts {
navController.navigate(Screen.Welcome.route)
navController.navigate(Screen.Login.route)
}
},
onNavigateToDetail = {
Expand Down Expand Up @@ -390,7 +390,7 @@ fun MainApp(
isSignUser = isSignUser,
onChangeIsSignUser = viewModel::onChangeSignUser,
navigateBack = {
navController.popBackStack()
navController.navigateUp()
},
onUpdate = { uri, setLoadingState ->
onUpdateProfile(
Expand Down Expand Up @@ -421,7 +421,7 @@ fun MainApp(
isConfirmPasswordError = viewModel.validationState.confirmPasswordError != null,
confirmPasswordError = viewModel.validationState.confirmPasswordError ?: "",
navigateBack = {
navController.popBackStack()
navController.navigateUp()
},
resetForm = viewModel::clearPasswordAndConfirmPassword,
onUpdatePassword = { setLoadingState ->
Expand Down Expand Up @@ -460,7 +460,7 @@ fun MainApp(
saveRefreshToken = saveRefreshToken,
getAuthUser = getAuthUser,
navigateBack = {
navController.popBackStack()
navController.navigateUp()
}
)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ fun MainApp(
title = title,
showDialog = showDialog,
onNavigateBack = {
navController.popBackStack()
navController.navigateUp()
}
)
}
Expand All @@ -532,7 +532,7 @@ fun MainApp(
id = id.toInt(),
showDialog = showDialog,
onNavigateBack = {
navController.popBackStack()
navController.navigateUp()
}
)
}
Expand Down
55 changes: 37 additions & 18 deletions app/src/main/java/com/singa/asl/ui/components/ModalNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fun ModalNavigation(
viewModelConversation: ConversationViewModel = koinViewModel(),
viewModelStatic: HistoryScreenViewModel = koinViewModel()
) {
val storagePermissionState = rememberPermissionState(Manifest.permission.READ_EXTERNAL_STORAGE)
val cameraPermissionState = rememberPermissionState(Manifest.permission.CAMERA)

val cameraPermissionLauncher = rememberLauncherForActivityResult(
Expand All @@ -67,11 +66,11 @@ fun ModalNavigation(
}
}

val readStoragePermissionLauncher = rememberLauncherForActivityResult(
val cameraPermissionLauncherWithoutRedirect = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) {
if (it) {
navigateToRealtimeCamera()
Toast.makeText(context, "Permission granted", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(context, "Permission denied", Toast.LENGTH_SHORT).show()
}
Expand All @@ -91,8 +90,24 @@ fun ModalNavigation(
) {
Button(
onClick = {
when {
cameraPermissionState.hasPermission -> {
staticDialog = true
}

cameraPermissionState.shouldShowRationale -> {
Toast.makeText(
context,
"Permission denied",
Toast.LENGTH_SHORT
).show()
}

staticDialog = true
else -> {
cameraPermissionLauncherWithoutRedirect.launch(Manifest.permission.CAMERA)
staticDialog = true
}
}
},
shape = RoundedCornerShape(20),
colors = ButtonDefaults.buttonColors(
Expand All @@ -118,7 +133,24 @@ fun ModalNavigation(
Spacer(modifier = Modifier.height(12.dp))
OutlinedButton(
onClick = {
conversationDialog = true
when {
cameraPermissionState.hasPermission -> {
conversationDialog = true
}

cameraPermissionState.shouldShowRationale -> {
Toast.makeText(
context,
"Permission denied",
Toast.LENGTH_SHORT
).show()
}

else -> {
cameraPermissionLauncherWithoutRedirect.launch(Manifest.permission.CAMERA)
conversationDialog = true
}
}
},
shape = RoundedCornerShape(20),
colors = ButtonDefaults.outlinedButtonColors(
Expand Down Expand Up @@ -160,21 +192,8 @@ fun ModalNavigation(
).show()
}

storagePermissionState.hasPermission -> {
navigateToRealtimeCamera()
}

storagePermissionState.shouldShowRationale -> {
Toast.makeText(
context,
"Permission denied",
Toast.LENGTH_SHORT
).show()
}

else -> {
cameraPermissionLauncher.launch(Manifest.permission.CAMERA)
readStoragePermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -84,7 +85,7 @@ fun OnBoardingItem(
),
style = MaterialTheme.typography.headlineMedium,
// fontSize = 24.sp,
color = MaterialTheme.colorScheme.onBackground,
color = Color.Black,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
letterSpacing = 1.sp,
Expand All @@ -98,7 +99,7 @@ fun OnBoardingItem(
id = items.description
),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onBackground,
color = Color.Black,
fontWeight = FontWeight.Light,
textAlign = TextAlign.Center,
modifier = Modifier.padding(10.dp),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.singa.asl.ui.screen.history_camera

import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.os.Environment
Expand Down Expand Up @@ -53,6 +54,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.app.ActivityCompat
import androidx.lifecycle.LifecycleOwner
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberPermissionState
import com.singa.asl.R
import com.singa.asl.ui.screen.history.HistoryScreenViewModel
import com.singa.asl.ui.theme.Color1
Expand Down Expand Up @@ -93,6 +96,7 @@ fun HistoryCameraScreen(
)
}

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun HistoryCameraContent(
modifier: Modifier = Modifier,
Expand All @@ -116,16 +120,7 @@ fun HistoryCameraContent(
}
}


val recordAudioPermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) {
if (it) {
return@rememberLauncherForActivityResult
} else {
Toast.makeText(context, "Permission denied", Toast.LENGTH_SHORT).show()
}
}
val recordPermissionState = rememberPermissionState(Manifest.permission.RECORD_AUDIO)

var recording by remember {
mutableStateOf<Recording?>(null)
Expand All @@ -145,6 +140,7 @@ fun HistoryCameraContent(
var isProcessingVideo by remember { mutableStateOf(false) }
var processingVideoProgress by remember { mutableIntStateOf(0) }


fun recordVideo() {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
val outputFile =
Expand All @@ -154,16 +150,7 @@ fun HistoryCameraContent(
"video_${timeStamp}_processed.mp4"
)


if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.RECORD_AUDIO
) != PackageManager.PERMISSION_GRANTED
) {
recordAudioPermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
return
}

@SuppressLint("MissingPermission")
recording = cameraController.startRecording(
FileOutputOptions.Builder(outputFile).build(),
AudioConfig.create(true),
Expand Down Expand Up @@ -204,6 +191,19 @@ fun HistoryCameraContent(
}
}

val recordAudioPermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) {
if (it) {
Toast.makeText(context, "Permission granted", Toast.LENGTH_SHORT).show()
isRecording = true
recordVideo()
} else {
Toast.makeText(context, "Permission denied", Toast.LENGTH_SHORT).show()
return@rememberLauncherForActivityResult
}
}

LaunchedEffect(isFrontCamera) {
if (isFrontCamera) {
cameraController.bindToLifecycle(lifecycleOwner)
Expand Down Expand Up @@ -339,8 +339,22 @@ fun HistoryCameraContent(
modifier = Modifier
.padding(10.dp),
onClick = {
isRecording = true
recordVideo()
when {
recordPermissionState.hasPermission -> {
isRecording = true
recordVideo()
}
recordPermissionState.shouldShowRationale -> {
Toast.makeText(
context,
"Permission denied",
Toast.LENGTH_SHORT
).show()
}
else -> {
recordAudioPermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
}
}
},
colors = IconButtonDefaults.iconButtonColors(
contentColor = Color.White
Expand Down
Loading
Loading