Aperture: Don't use library only functions
Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
Change-Id: I0a525145786b0b76c857a81033ef69e7fb0c88b5
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index 7de7fa2..75dd8c4 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -46,6 +46,7 @@
import androidx.camera.view.CameraController
import androidx.camera.view.LifecycleCameraController
import androidx.camera.view.PreviewView
+import androidx.camera.view.video.Metadata
import androidx.camera.view.video.OnVideoSavedCallback
import androidx.camera.view.video.OutputFileResults
import androidx.core.app.ActivityCompat
@@ -371,8 +372,12 @@
shutterButton.isEnabled = false
// Create output options object which contains file + metadata
- val outputOptions = StorageUtils.getPhotoMediaStoreOutputOptions(contentResolver)
- outputOptions.metadata.location = location
+ val outputOptions = StorageUtils.getPhotoMediaStoreOutputOptions(
+ contentResolver,
+ ImageCapture.Metadata().apply {
+ location = this@MainActivity.location
+ }
+ )
// Set up image capture listener, which is triggered after photo has
// been taken
@@ -415,7 +420,12 @@
}
// Create output options object which contains file + metadata
- val outputOptions = StorageUtils.getVideoMediaStoreOutputOptions(contentResolver)
+ val outputOptions = StorageUtils.getVideoMediaStoreOutputOptions(
+ contentResolver,
+ Metadata.builder().apply {
+ setLocation(location)
+ }.build()
+ )
// Play shutter sound
if (cameraSoundsUtils.playStartVideoRecording()) {
diff --git a/app/src/main/java/org/lineageos/aperture/utils/StorageUtils.kt b/app/src/main/java/org/lineageos/aperture/utils/StorageUtils.kt
index cbfd4c0..efa29f7 100644
--- a/app/src/main/java/org/lineageos/aperture/utils/StorageUtils.kt
+++ b/app/src/main/java/org/lineageos/aperture/utils/StorageUtils.kt
@@ -10,7 +10,7 @@
import android.content.ContentValues
import android.provider.MediaStore
import androidx.camera.core.ImageCapture
-import androidx.camera.video.MediaStoreOutputOptions
+import androidx.camera.view.video.Metadata
import androidx.camera.view.video.OutputFileOptions
import java.text.SimpleDateFormat
import java.util.Locale
@@ -23,7 +23,8 @@
* Returns a new ImageCapture.OutputFileOptions to use to store a JPEG photo
*/
fun getPhotoMediaStoreOutputOptions(
- contentResolver: ContentResolver
+ contentResolver: ContentResolver,
+ metadata: ImageCapture.Metadata
): ImageCapture.OutputFileOptions {
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, getCurrentTimeString())
@@ -36,6 +37,7 @@
contentResolver, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
contentValues
)
+ .setMetadata(metadata)
.build()
}
@@ -43,7 +45,10 @@
* Returns a new MediaStoreOutputOptions to use to store a MP4 video
*/
@androidx.camera.view.video.ExperimentalVideo
- fun getVideoMediaStoreOutputOptions(contentResolver: ContentResolver): OutputFileOptions {
+ fun getVideoMediaStoreOutputOptions(
+ contentResolver: ContentResolver,
+ metadata: Metadata
+ ): OutputFileOptions {
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, getCurrentTimeString())
put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4")
@@ -52,6 +57,7 @@
return OutputFileOptions
.builder(contentResolver, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues)
+ .setMetadata(metadata)
.build()
}