Create video edit activity
For now, it just launches a video player
This commit is contained in:
parent
01b099e5eb
commit
af8a5c355a
|
@ -33,6 +33,7 @@
|
||||||
android:screenOrientation="sensorPortrait"
|
android:screenOrientation="sensorPortrait"
|
||||||
tools:ignore="LockedOrientationActivity" />
|
tools:ignore="LockedOrientationActivity" />
|
||||||
<activity android:name=".postCreation.photoEdit.PhotoEditActivity" />
|
<activity android:name=".postCreation.photoEdit.PhotoEditActivity" />
|
||||||
|
<activity android:name=".postCreation.photoEdit.VideoEditActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".postCreation.PostCreationActivity"
|
android:name=".postCreation.PostCreationActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.pixeldroid.app.postCreation.camera.CameraActivity
|
||||||
import org.pixeldroid.app.postCreation.carousel.CarouselItem
|
import org.pixeldroid.app.postCreation.carousel.CarouselItem
|
||||||
import org.pixeldroid.app.postCreation.carousel.ImageCarousel
|
import org.pixeldroid.app.postCreation.carousel.ImageCarousel
|
||||||
import org.pixeldroid.app.postCreation.photoEdit.PhotoEditActivity
|
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.BaseActivity
|
||||||
import org.pixeldroid.app.utils.api.objects.Attachment
|
import org.pixeldroid.app.utils.api.objects.Attachment
|
||||||
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
|
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
|
||||||
|
@ -67,6 +68,11 @@ class PostCreationActivity : BaseActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityPostCreationBinding
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityPostCreationBinding.inflate(layoutInflater)
|
binding = ActivityPostCreationBinding.inflate(layoutInflater)
|
||||||
|
@ -430,9 +436,9 @@ class PostCreationActivity : BaseActivity() {
|
||||||
private val editResultContract: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
|
private val editResultContract: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
|
||||||
result: ActivityResult? ->
|
result: ActivityResult? ->
|
||||||
if (result?.resultCode == Activity.RESULT_OK && result.data != null) {
|
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 {
|
photoData.getOrNull(position)?.apply {
|
||||||
imageUri = result.data!!.getStringExtra(PhotoEditActivity.PICTURE_URI)!!.toUri()
|
imageUri = result.data!!.getStringExtra(PICTURE_URI)!!.toUri()
|
||||||
val (imageSize, imageVideo) = imageUri.getSizeAndVideoValidate()
|
val (imageSize, imageVideo) = imageUri.getSizeAndVideoValidate()
|
||||||
size = imageSize
|
size = imageSize
|
||||||
video = imageVideo
|
video = imageVideo
|
||||||
|
@ -447,15 +453,15 @@ class PostCreationActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun edit(position: Int) {
|
private fun edit(position: Int) {
|
||||||
if(photoData[position].video){
|
if (photoData[position].video){
|
||||||
AlertDialog.Builder(this).apply {
|
val intent = Intent(this, VideoEditActivity::class.java)
|
||||||
setMessage(R.string.video_edit_not_yet_supported)
|
.putExtra(PICTURE_URI, photoData[position].imageUri)
|
||||||
setNegativeButton(android.R.string.ok) { _, _ -> }
|
.putExtra(PICTURE_POSITION, position)
|
||||||
}.show()
|
editResultContract.launch(intent)
|
||||||
} else {
|
} else {
|
||||||
val intent = Intent(this, PhotoEditActivity::class.java)
|
val intent = Intent(this, PhotoEditActivity::class.java)
|
||||||
.putExtra(PhotoEditActivity.PICTURE_URI, photoData[position].imageUri)
|
.putExtra(PICTURE_URI, photoData[position].imageUri)
|
||||||
.putExtra(PhotoEditActivity.PICTURE_POSITION, position)
|
.putExtra(PICTURE_POSITION, position)
|
||||||
editResultContract.launch(intent)
|
editResultContract.launch(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,6 @@ class PhotoEditActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object{
|
companion object{
|
||||||
internal const val PICTURE_URI = "picture_uri"
|
|
||||||
internal const val PICTURE_POSITION = "picture_position"
|
|
||||||
|
|
||||||
private var executor: ExecutorService = newSingleThreadExecutor()
|
private var executor: ExecutorService = newSingleThreadExecutor()
|
||||||
private var future: Future<*>? = null
|
private var future: Future<*>? = null
|
||||||
|
|
||||||
|
@ -99,8 +96,8 @@ class PhotoEditActivity : BaseActivity() {
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setHomeButtonEnabled(true)
|
supportActionBar?.setHomeButtonEnabled(true)
|
||||||
|
|
||||||
initialUri = intent.getParcelableExtra(PICTURE_URI)
|
initialUri = intent.getParcelableExtra(PostCreationActivity.PICTURE_URI)
|
||||||
picturePosition = intent.getIntExtra(PICTURE_POSITION, 0)
|
picturePosition = intent.getIntExtra(PostCreationActivity.PICTURE_POSITION, 0)
|
||||||
imageUri = initialUri
|
imageUri = initialUri
|
||||||
|
|
||||||
// Crop button on-click listener
|
// Crop button on-click listener
|
||||||
|
@ -345,8 +342,8 @@ class PhotoEditActivity : BaseActivity() {
|
||||||
private fun sendBackImage(file: String) {
|
private fun sendBackImage(file: String) {
|
||||||
val intent = Intent(this, PostCreationActivity::class.java)
|
val intent = Intent(this, PostCreationActivity::class.java)
|
||||||
.apply {
|
.apply {
|
||||||
putExtra(PICTURE_URI, file)
|
putExtra(PostCreationActivity.PICTURE_URI, file)
|
||||||
putExtra(PICTURE_POSITION, picturePosition)
|
putExtra(PostCreationActivity.PICTURE_POSITION, picturePosition)
|
||||||
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
Loading…
Reference in New Issue