feat: "take a photo" button
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
0d17f8c9cf
commit
ab67ca35e1
|
|
@ -118,8 +118,9 @@ fun InbuiltMediaPicker(
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
MediaStore.Images.ImageColumns._ID,
|
MediaStore.Images.ImageColumns._ID,
|
||||||
MediaStore.Images.ImageColumns.RESOLUTION,
|
MediaStore.Images.ImageColumns.RESOLUTION,
|
||||||
|
MediaStore.Images.ImageColumns.ORIENTATION,
|
||||||
MediaStore.Images.ImageColumns.MIME_TYPE,
|
MediaStore.Images.ImageColumns.MIME_TYPE,
|
||||||
MediaStore.Video.VideoColumns.DURATION
|
MediaStore.Video.VideoColumns.DURATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
val selection: String? = null
|
val selection: String? = null
|
||||||
|
|
@ -143,6 +144,10 @@ fun InbuiltMediaPicker(
|
||||||
cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns._ID))
|
cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns._ID))
|
||||||
val resolution =
|
val resolution =
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.RESOLUTION))
|
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.RESOLUTION))
|
||||||
|
val orientation =
|
||||||
|
cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION))
|
||||||
|
|
||||||
|
val swapDimensions = orientation == 90 || orientation == 270
|
||||||
|
|
||||||
val isVideo =
|
val isVideo =
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.MIME_TYPE))
|
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.MIME_TYPE))
|
||||||
|
|
@ -164,11 +169,13 @@ fun InbuiltMediaPicker(
|
||||||
|
|
||||||
if (resolution == null) continue
|
if (resolution == null) continue
|
||||||
|
|
||||||
|
val (width, height) = resolution.split("×").map { it.toInt() }
|
||||||
|
|
||||||
images.add(
|
images.add(
|
||||||
Media(
|
Media(
|
||||||
uri = contentUri,
|
uri = contentUri,
|
||||||
width = resolution.split("×")[0].toInt(),
|
width = if (swapDimensions) height else width,
|
||||||
height = resolution.split("×")[1].toInt(),
|
height = if (swapDimensions) width else height,
|
||||||
duration = videoDuration
|
duration = videoDuration
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package chat.revolt.screens.chat.views.channel
|
package chat.revolt.screens.chat.views.channel
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Environment
|
||||||
|
import android.provider.MediaStore
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
|
@ -40,6 +43,7 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.runtime.snapshotFlow
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
|
@ -153,6 +157,17 @@ fun ChannelScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val capturedPhotoUri = rememberSaveable { mutableStateOf<Uri?>(null) }
|
||||||
|
val pickCameraLauncher = rememberLauncherForActivityResult(
|
||||||
|
contract = ActivityResultContracts.TakePicture()
|
||||||
|
) { uriUpdated ->
|
||||||
|
if (uriUpdated) {
|
||||||
|
capturedPhotoUri.value?.let { uri ->
|
||||||
|
processFileUri(uri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val scrollDownFABPadding by animateDpAsState(
|
val scrollDownFABPadding by animateDpAsState(
|
||||||
if (viewModel.typingUsers.isNotEmpty()) 25.dp else 0.dp,
|
if (viewModel.typingUsers.isNotEmpty()) 25.dp else 0.dp,
|
||||||
animationSpec = RevoltTweenDp,
|
animationSpec = RevoltTweenDp,
|
||||||
|
|
@ -472,11 +487,26 @@ fun ChannelScreen(
|
||||||
viewModel.inbuiltFilePickerOpen = false
|
viewModel.inbuiltFilePickerOpen = false
|
||||||
},
|
},
|
||||||
onOpenCamera = {
|
onOpenCamera = {
|
||||||
Toast.makeText(
|
// Create a new content URI to store the captured image.
|
||||||
context,
|
val contentResolver = context.contentResolver
|
||||||
"This will open the camera one day",
|
val contentValues = ContentValues().apply {
|
||||||
Toast.LENGTH_SHORT
|
put(
|
||||||
).show()
|
MediaStore.MediaColumns.DISPLAY_NAME,
|
||||||
|
"RVL_${System.currentTimeMillis()}.jpg"
|
||||||
|
)
|
||||||
|
put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")
|
||||||
|
put(
|
||||||
|
MediaStore.MediaColumns.RELATIVE_PATH,
|
||||||
|
Environment.DIRECTORY_PICTURES
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
capturedPhotoUri.value = contentResolver.insert(
|
||||||
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
|
contentValues
|
||||||
|
)
|
||||||
|
|
||||||
|
pickCameraLauncher.launch(capturedPhotoUri.value)
|
||||||
viewModel.inbuiltFilePickerOpen = false
|
viewModel.inbuiltFilePickerOpen = false
|
||||||
},
|
},
|
||||||
onClose = {
|
onClose = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue