1
0
mirror of https://gitlab.shinice.net/pixeldroid/PixelDroid synced 2024-12-25 22:43:30 +01:00

Create video edit activity

For now, it just launches a video player
This commit is contained in:
Frédéric Gerber 2022-03-13 18:35:03 +01:00
parent 01b099e5eb
commit af8a5c355a
5 changed files with 119 additions and 16 deletions

View File

@ -33,6 +33,7 @@
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity android:name=".postCreation.photoEdit.PhotoEditActivity" />
<activity android:name=".postCreation.photoEdit.VideoEditActivity" />
<activity
android:name=".postCreation.PostCreationActivity"
android:exported="true"

View File

@ -32,6 +32,7 @@ import org.pixeldroid.app.postCreation.camera.CameraActivity
import org.pixeldroid.app.postCreation.carousel.CarouselItem
import org.pixeldroid.app.postCreation.carousel.ImageCarousel
import org.pixeldroid.app.postCreation.photoEdit.PhotoEditActivity
import org.pixeldroid.app.postCreation.photoEdit.VideoEditActivity
import org.pixeldroid.app.utils.BaseActivity
import org.pixeldroid.app.utils.api.objects.Attachment
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
@ -67,6 +68,11 @@ class PostCreationActivity : BaseActivity() {
private lateinit var binding: ActivityPostCreationBinding
companion object {
internal const val PICTURE_URI = "picture_uri"
internal const val PICTURE_POSITION = "picture_position"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPostCreationBinding.inflate(layoutInflater)
@ -430,9 +436,9 @@ class PostCreationActivity : BaseActivity() {
private val editResultContract: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
result: ActivityResult? ->
if (result?.resultCode == Activity.RESULT_OK && result.data != null) {
val position: Int = result.data!!.getIntExtra(PhotoEditActivity.PICTURE_POSITION, 0)
val position: Int = result.data!!.getIntExtra(PICTURE_POSITION, 0)
photoData.getOrNull(position)?.apply {
imageUri = result.data!!.getStringExtra(PhotoEditActivity.PICTURE_URI)!!.toUri()
imageUri = result.data!!.getStringExtra(PICTURE_URI)!!.toUri()
val (imageSize, imageVideo) = imageUri.getSizeAndVideoValidate()
size = imageSize
video = imageVideo
@ -447,15 +453,15 @@ class PostCreationActivity : BaseActivity() {
}
private fun edit(position: Int) {
if(photoData[position].video){
AlertDialog.Builder(this).apply {
setMessage(R.string.video_edit_not_yet_supported)
setNegativeButton(android.R.string.ok) { _, _ -> }
}.show()
if (photoData[position].video){
val intent = Intent(this, VideoEditActivity::class.java)
.putExtra(PICTURE_URI, photoData[position].imageUri)
.putExtra(PICTURE_POSITION, position)
editResultContract.launch(intent)
} else {
val intent = Intent(this, PhotoEditActivity::class.java)
.putExtra(PhotoEditActivity.PICTURE_URI, photoData[position].imageUri)
.putExtra(PhotoEditActivity.PICTURE_POSITION, position)
.putExtra(PICTURE_URI, photoData[position].imageUri)
.putExtra(PICTURE_POSITION, position)
editResultContract.launch(intent)
}
}

View File

@ -73,9 +73,6 @@ class PhotoEditActivity : BaseActivity() {
}
companion object{
internal const val PICTURE_URI = "picture_uri"
internal const val PICTURE_POSITION = "picture_position"
private var executor: ExecutorService = newSingleThreadExecutor()
private var future: Future<*>? = null
@ -99,8 +96,8 @@ class PhotoEditActivity : BaseActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeButtonEnabled(true)
initialUri = intent.getParcelableExtra(PICTURE_URI)
picturePosition = intent.getIntExtra(PICTURE_POSITION, 0)
initialUri = intent.getParcelableExtra(PostCreationActivity.PICTURE_URI)
picturePosition = intent.getIntExtra(PostCreationActivity.PICTURE_POSITION, 0)
imageUri = initialUri
// Crop button on-click listener
@ -345,8 +342,8 @@ class PhotoEditActivity : BaseActivity() {
private fun sendBackImage(file: String) {
val intent = Intent(this, PostCreationActivity::class.java)
.apply {
putExtra(PICTURE_URI, file)
putExtra(PICTURE_POSITION, picturePosition)
putExtra(PostCreationActivity.PICTURE_URI, file)
putExtra(PostCreationActivity.PICTURE_POSITION, picturePosition)
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
}

View File

@ -0,0 +1,85 @@
package org.pixeldroid.app.postCreation.photoEdit
import android.content.pm.ActivityInfo
import android.media.AudioManager
import android.net.Uri
import android.os.Bundle
import androidx.core.net.toUri
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.media.AudioAttributesCompat
import androidx.media2.common.MediaMetadata
import androidx.media2.common.UriMediaItem
import androidx.media2.player.MediaPlayer
import com.bumptech.glide.Glide
import org.pixeldroid.app.R
import org.pixeldroid.app.databinding.ActivityVideoEditBinding
import org.pixeldroid.app.postCreation.PostCreationActivity
import org.pixeldroid.app.posts.MediaViewerActivity
import org.pixeldroid.app.utils.BaseActivity
class VideoEditActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityVideoEditBinding.inflate(layoutInflater)
setContentView(binding.root)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setTitle(R.string.edit)
val videoUri: Uri? = intent.getParcelableExtra(PostCreationActivity.PICTURE_URI)
val videoPosition: Int = intent.getIntExtra(PostCreationActivity.PICTURE_POSITION, 0)
val description: String? = intent.getStringExtra(MediaViewerActivity.VIDEO_DESCRIPTION_TAG)
val mediaItem: UriMediaItem = UriMediaItem.Builder(videoUri!!).build() // TODO: remove !!
mediaItem.metadata = MediaMetadata.Builder()
.putString(MediaMetadata.METADATA_KEY_TITLE, description ?: "")
.build()
val mediaPlayer = MediaPlayer(this)
mediaPlayer.setMediaItem(mediaItem)
binding.videoView.mediaControlView?.setOnFullScreenListener{ view, fullscreen ->
val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView)
if (!fullscreen) {
// Configure the behavior of the hidden system bars
windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Hide both the status bar and the navigation bar
windowInsetsController?.show(WindowInsetsCompat.Type.systemBars())
supportActionBar?.show()
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
} else {
// Configure the behavior of the hidden system bars
windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Hide both the status bar and the navigation bar
windowInsetsController?.hide(WindowInsetsCompat.Type.systemBars())
requestedOrientation =
if (mediaPlayer.videoSize.height < mediaPlayer.videoSize.width) {
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
} else {
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
supportActionBar?.hide()
}
}
// Configure audio
mediaPlayer.setAudioAttributes(
AudioAttributesCompat.Builder()
.setLegacyStreamType(AudioManager.STREAM_MUSIC)
.setUsage(AudioAttributesCompat.USAGE_MEDIA)
.setContentType(AudioAttributesCompat.CONTENT_TYPE_MOVIE)
.build()
)
mediaPlayer.prepare()
binding.videoView.setPlayer(mediaPlayer)
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.media2.widget.VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" />
</androidx.constraintlayout.widget.ConstraintLayout>