Add video play support
This commit is contained in:
parent
277dd3c66e
commit
81d73b7a38
|
@ -22,6 +22,10 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:replace="android:allowBackup">
|
||||
<activity
|
||||
android:name=".posts.MediaViewerActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity android:name=".postCreation.camera.CameraActivity" />
|
||||
<activity
|
||||
android:name=".posts.ReportActivity"
|
||||
|
@ -30,18 +34,22 @@
|
|||
<activity android:name=".postCreation.photoEdit.PhotoEditActivity" />
|
||||
<activity
|
||||
android:name=".postCreation.PostCreationActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="sensorPortrait"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
tools:ignore="LockedOrientationActivity"
|
||||
android:exported="true">
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:mimeType="image/*" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:mimeType="image/*" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
|
@ -83,11 +91,11 @@
|
|||
tools:ignore="LockedOrientationActivity" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="sensorPortrait"
|
||||
android:theme="@style/AppTheme.Launcher"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
tools:ignore="LockedOrientationActivity"
|
||||
android:exported="true">
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
@ -100,11 +108,11 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".LoginActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="sensorPortrait"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
tools:ignore="LockedOrientationActivity"
|
||||
android:exported="true">
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
|
@ -118,16 +126,16 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name="com.yalantis.ucrop.UCropActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="sensorPortrait"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
tools:ignore="LockedOrientationActivity"
|
||||
android:exported="true"/>
|
||||
tools:ignore="LockedOrientationActivity" />
|
||||
<activity
|
||||
android:name=".searchDiscover.SearchActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="sensorPortrait"
|
||||
tools:ignore="LockedOrientationActivity"
|
||||
android:exported="true">
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
|
@ -156,7 +164,6 @@
|
|||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,42 @@
|
|||
package org.pixeldroid.app.posts
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.core.net.toUri
|
||||
import androidx.media2.common.MediaMetadata
|
||||
import androidx.media2.common.UriMediaItem
|
||||
import androidx.media2.player.MediaPlayer
|
||||
import org.pixeldroid.app.databinding.ActivityMediaviewerBinding
|
||||
import org.pixeldroid.app.utils.BaseActivity
|
||||
|
||||
class MediaViewerActivity : BaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMediaviewerBinding
|
||||
|
||||
companion object {
|
||||
const val VIDEO_URL_TAG = "video_url_mediavieweractivity"
|
||||
const val VIDEO_DESCRIPTION_TAG = "video_description_mediavieweractivity"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMediaviewerBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val uri: String = intent.getStringExtra(VIDEO_URL_TAG).orEmpty()
|
||||
val description: String? = intent.getStringExtra(VIDEO_DESCRIPTION_TAG)
|
||||
|
||||
val mediaItem: UriMediaItem = UriMediaItem.Builder(uri.toUri()).build()
|
||||
mediaItem.metadata = MediaMetadata.Builder()
|
||||
.putString(MediaMetadata.METADATA_KEY_TITLE, description ?: "")
|
||||
.build()
|
||||
|
||||
val mediaPlayer = MediaPlayer(this)
|
||||
mediaPlayer.setMediaItem(mediaItem)
|
||||
mediaPlayer.prepare()
|
||||
|
||||
binding.videoView.setPlayer(mediaPlayer)
|
||||
|
||||
// Start actually playing the video
|
||||
mediaPlayer.play()
|
||||
}
|
||||
}
|
|
@ -37,6 +37,8 @@ import com.karumi.dexter.listener.PermissionDeniedResponse
|
|||
import com.karumi.dexter.listener.PermissionGrantedResponse
|
||||
import com.karumi.dexter.listener.single.BasePermissionListener
|
||||
import kotlinx.coroutines.launch
|
||||
import org.pixeldroid.app.posts.MediaViewerActivity.Companion.VIDEO_DESCRIPTION_TAG
|
||||
import org.pixeldroid.app.posts.MediaViewerActivity.Companion.VIDEO_URL_TAG
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import kotlin.math.roundToInt
|
||||
|
@ -594,6 +596,7 @@ private class AlbumViewPagerAdapter(private val media_attachments: List<Attachme
|
|||
override fun getItemCount() = media_attachments.size
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
media_attachments[position].apply {
|
||||
val video = type == Attachment.AttachmentType.video
|
||||
val blurhashBitMap = blurhash?.let {
|
||||
BlurHashDecoder.blurHashBitmap(
|
||||
holder.binding.root.resources,
|
||||
|
@ -603,16 +606,30 @@ private class AlbumViewPagerAdapter(private val media_attachments: List<Attachme
|
|||
)
|
||||
}
|
||||
if (sensitive == false) {
|
||||
val imageUrl = if(video) preview_url else url
|
||||
Glide.with(holder.binding.root)
|
||||
.asDrawable().fitCenter()
|
||||
.placeholder(blurhashBitMap)
|
||||
.load(url).into(holder.image)
|
||||
.load(imageUrl).into(holder.image)
|
||||
} else {
|
||||
Glide.with(holder.binding.root)
|
||||
.asDrawable().fitCenter()
|
||||
.load(blurhashBitMap).into(holder.image)
|
||||
}
|
||||
|
||||
holder.videoPlayButton.visibility = if(video) View.VISIBLE else View.GONE
|
||||
|
||||
if(video){
|
||||
fun openActivity(){
|
||||
val intent = Intent(holder.binding.root.context, MediaViewerActivity::class.java)
|
||||
intent.putExtra(VIDEO_URL_TAG, url)
|
||||
intent.putExtra(VIDEO_DESCRIPTION_TAG, description)
|
||||
holder.binding.root.context.startActivity(intent)
|
||||
}
|
||||
holder.videoPlayButton.setOnClickListener {openActivity()}
|
||||
holder.image.setOnClickListener {openActivity()}
|
||||
}
|
||||
|
||||
val description = description
|
||||
.orEmpty()
|
||||
.ifEmpty { holder.binding.root.context.getString(R.string.no_description) }
|
||||
|
@ -633,5 +650,6 @@ private class AlbumViewPagerAdapter(private val media_attachments: List<Attachme
|
|||
|
||||
class ViewHolder(val binding: AlbumImageViewBinding) : RecyclerView.ViewHolder(binding.root){
|
||||
val image: ImageView = binding.imageImageView
|
||||
val videoPlayButton: ImageView = binding.videoPlayButton
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@ import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
|
|||
import org.pixeldroid.app.utils.openUrl
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.pixeldroid.app.utils.api.objects.Attachment
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
|
@ -340,6 +341,7 @@ class ProfileViewModelFactory @ExperimentalPagingApi constructor(
|
|||
class ProfilePostsViewHolder(binding: FragmentProfilePostsBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
private val postPreview: ImageView = binding.postPreview
|
||||
private val albumIcon: ImageView = binding.albumIcon
|
||||
private val videoIcon: ImageView = binding.videoIcon
|
||||
|
||||
fun bind(post: Status) {
|
||||
|
||||
|
@ -352,11 +354,14 @@ class ProfilePostsViewHolder(binding: FragmentProfilePostsBinding) : RecyclerVie
|
|||
} else {
|
||||
ImageConverter.setSquareImageFromURL(itemView, post.getPostPreviewURL(), postPreview)
|
||||
}
|
||||
|
||||
if(post.media_attachments?.size ?: 0 > 1) {
|
||||
albumIcon.visibility = View.VISIBLE
|
||||
} else {
|
||||
albumIcon.visibility = View.GONE
|
||||
if(post.media_attachments?.get(0)?.type == Attachment.AttachmentType.video) {
|
||||
videoIcon.visibility = View.VISIBLE
|
||||
} else videoIcon.visibility = View.GONE
|
||||
|
||||
}
|
||||
|
||||
postPreview.setOnClickListener {
|
||||
|
|
|
@ -8,4 +8,5 @@ import org.pixeldroid.app.R
|
|||
class ProfilePostViewHolder(val postView: View) : RecyclerView.ViewHolder(postView) {
|
||||
val postPreview: ImageView = postView.findViewById(R.id.postPreview)
|
||||
val albumIcon: ImageView = postView.findViewById(R.id.albumIcon)
|
||||
val videoIcon: ImageView = postView.findViewById(R.id.albumIcon)
|
||||
}
|
|
@ -19,6 +19,7 @@ import org.pixeldroid.app.utils.api.objects.Status
|
|||
import org.pixeldroid.app.posts.PostActivity
|
||||
import org.pixeldroid.app.utils.BaseFragment
|
||||
import org.pixeldroid.app.utils.ImageConverter
|
||||
import org.pixeldroid.app.utils.api.objects.Attachment
|
||||
import org.pixeldroid.app.utils.bindingLifecycleAware
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
@ -120,6 +121,10 @@ class SearchDiscoverFragment : BaseFragment() {
|
|||
holder.albumIcon.visibility = View.VISIBLE
|
||||
} else {
|
||||
holder.albumIcon.visibility = View.GONE
|
||||
if(post?.media_attachments?.get(0)?.type == Attachment.AttachmentType.video) {
|
||||
holder.videoIcon.visibility = View.VISIBLE
|
||||
} else holder.videoIcon.visibility = View.GONE
|
||||
|
||||
}
|
||||
ImageConverter.setSquareImageFromURL(holder.postView, post?.getPostPreviewURL(), holder.postPreview, post?.media_attachments?.firstOrNull()?.blurhash)
|
||||
holder.postPreview.setOnClickListener {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,16.5v-9l6,4.5 -6,4.5z"/>
|
||||
</vector>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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>
|
|
@ -14,4 +14,15 @@
|
|||
android:adjustViewBounds="true"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/videoPlayButton"
|
||||
android:visibility="gone"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/play_circle_filled"
|
||||
android:contentDescription="@string/play_video" />
|
||||
|
||||
</FrameLayout>
|
|
@ -38,9 +38,24 @@
|
|||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible"
|
||||
tools:visibility="gone"
|
||||
android:contentDescription="@string/post_is_album" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/videoIcon"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:foreground="@drawable/play_circle_filled"
|
||||
android:foregroundGravity="center"
|
||||
android:foregroundTint="#FFFFFF"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible"
|
||||
android:contentDescription="@string/post_is_video" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.gridlayout.widget.GridLayout>
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<string name="poll_notification_channel">"Polls"</string>
|
||||
<string name="other_notification_channel">"Other"</string>
|
||||
|
||||
<plurals name="notification_title_summary" >
|
||||
<plurals name="notification_title_summary">
|
||||
<item quantity="one">"%d new notification"</item>
|
||||
<item quantity="other">"%d new notifications"</item>
|
||||
</plurals>
|
||||
|
@ -73,8 +73,6 @@
|
|||
<string name="notification_summary_small">%1$s and %2$s</string>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Login page -->
|
||||
<string name="whats_an_instance">"What's an instance?"</string>
|
||||
<string name="whats_an_instance_explanation">"You might be confused by the text field asking for the domain of your 'instance'.
|
||||
|
@ -174,6 +172,8 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
|
|||
<string name="add_comment">Add a comment</string>
|
||||
<string name="submit_comment">Submit comment</string>
|
||||
<string name="post_is_album">This post is an album</string>
|
||||
<string name="post_is_video">This post is a video</string>
|
||||
|
||||
<!-- Profile page -->
|
||||
<plurals name="nb_posts">
|
||||
<item quantity="one">"%d\nPost"</item>
|
||||
|
@ -259,4 +259,5 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
|
|||
<string name="login_notifications">Couldn\'t fetch latest notifications</string>
|
||||
<string name="no_camera_permission">Camera permission not granted, grant the permission in settings if you want to let PixelDroid use the camera</string>
|
||||
<string name="no_storage_permission">Storage permission not granted, grant the permission in settings if you want to let PixelDroid show the thumbnail</string>
|
||||
<string name="play_video">Play video</string>
|
||||
</resources>
|
Loading…
Reference in New Issue