Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package chat.revolt.screens.chat.views.channel

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.ContentValues
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Environment
Expand Down Expand Up @@ -103,6 +105,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
import androidx.documentfile.provider.DocumentFile
import androidx.hilt.navigation.compose.hiltViewModel
import chat.revolt.R
Expand Down Expand Up @@ -374,6 +377,38 @@ fun ChannelScreen(
}
}

val cameraPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission()
) { isGranted ->
if (isGranted) {
openCameraCallback()
}
else {
Toast.makeText(
context,
context.getString(
R.string.file_picker_chip_camera_permission_denied
),
Toast.LENGTH_SHORT
).show()
}

}

val checkAndRequestCameraPermission = {
when {
ContextCompat.checkSelfPermission(
context,
Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED -> {
openCameraCallback()
}
else -> {
cameraPermissionLauncher.launch(Manifest.permission.CAMERA)
}
}
}

val openDocumentPickerCallback = {
pickFileLauncher.launch(arrayOf("*/*"))
}
Expand Down Expand Up @@ -1114,7 +1149,7 @@ fun ChannelScreen(
},
text = { Text(stringResource(R.string.file_picker_chip_camera)) },
onClick = {
openCameraCallback()
checkAndRequestCameraPermission()
viewModel.activePane =
ChannelScreenActivePane.None
}
Expand Down Expand Up @@ -1230,7 +1265,7 @@ fun ChannelScreen(
ChannelScreenActivePane.None
},
onOpenCamera = {
openCameraCallback()
checkAndRequestCameraPermission()
viewModel.activePane =
ChannelScreenActivePane.None
},
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
<string name="file_picker_chip_camera">Camera</string>
<string name="file_picker_chip_camera_none_installed">No camera app installed</string>
<string name="file_picker_chip_camera_failed">Failed to open camera</string>
<string name="file_picker_chip_camera_permission_denied">Camera permission is required to take photos</string>

<string name="inline_media_picker_current_description">Currently selected media</string>
<string name="inline_media_picker_no_media_placeholder">Pick media…</string>
Expand Down