From 2fcd3b21f8709667b7e2a07c1b6c56e2cb25ff6d Mon Sep 17 00:00:00 2001 From: Ivan Agosto Date: Mon, 25 Mar 2024 19:57:49 -0600 Subject: [PATCH] Add isLive indicator --- .../agosto/p2play/adapters/VideosAdapter.kt | 8 +++- .../agosto/p2play/models/StreamingModel.kt | 25 ++++++++++++ .../libre/agosto/p2play/models/VideoModel.kt | 40 +++++++++++++------ app/src/main/res/drawable/live_shape.xml | 14 +++++++ app/src/main/res/layout/view_video.xml | 17 ++++++++ app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 +- 7 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/org/libre/agosto/p2play/models/StreamingModel.kt create mode 100644 app/src/main/res/drawable/live_shape.xml diff --git a/app/src/main/java/org/libre/agosto/p2play/adapters/VideosAdapter.kt b/app/src/main/java/org/libre/agosto/p2play/adapters/VideosAdapter.kt index ecfde66..de04ae0 100644 --- a/app/src/main/java/org/libre/agosto/p2play/adapters/VideosAdapter.kt +++ b/app/src/main/java/org/libre/agosto/p2play/adapters/VideosAdapter.kt @@ -9,7 +9,6 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.view_video.view.duration import org.libre.agosto.p2play.* import org.libre.agosto.p2play.helpers.mapSeconds import org.libre.agosto.p2play.models.VideoModel @@ -30,6 +29,7 @@ class VideosAdapter(private val myDataset: ArrayList) : val description: TextView val context: Context val duration: TextView + val isLive: TextView init { // Define click listener for the ViewHolder's View @@ -38,7 +38,8 @@ class VideosAdapter(private val myDataset: ArrayList) : thumb = view.findViewById(R.id.thumb) userImg = view.findViewById(R.id.userImg) context = view.context - duration = view.duration + duration = view.findViewById(R.id.duration) + isLive = view.findViewById(R.id.isLive) } } @@ -83,6 +84,9 @@ class VideosAdapter(private val myDataset: ArrayList) : holder.description.text = myDataset[position].username+" - "+myDataset[position].views+" "+viewsText + if (myDataset[position].isLive) { + holder.isLive.visibility = View.VISIBLE + } } // Return the size of your dataset (invoked by the layout manager) diff --git a/app/src/main/java/org/libre/agosto/p2play/models/StreamingModel.kt b/app/src/main/java/org/libre/agosto/p2play/models/StreamingModel.kt new file mode 100644 index 0000000..5438b5f --- /dev/null +++ b/app/src/main/java/org/libre/agosto/p2play/models/StreamingModel.kt @@ -0,0 +1,25 @@ +package org.libre.agosto.p2play.models + +import android.util.JsonReader + +class StreamingModel( + var playlistUrl: String = "", + var segmentsSha256Url: String = "", + // TODO: Download Files +) { + fun parse(data: JsonReader) { + data.beginObject() + while (data.hasNext()) { + val key = data.nextName() + when (key.toString()) { + "playlistUrl"->{ + this.playlistUrl = data.nextString() + } + "segmentsSha256Url"->{ + this.segmentsSha256Url = data.nextString() + } + else -> data.skipValue() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt b/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt index 74fce53..5062faa 100644 --- a/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt +++ b/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt @@ -5,19 +5,21 @@ import android.util.JsonToken import java.io.Serializable class VideoModel( - var id: Int = 0, - var uuid: String = "", - var name: String = "", - var description: String = "", - var thumbUrl: String = "", - var userImageUrl: String = "", - var embedUrl: String = "", - var duration: Number = 0, - var username: String = "", - var views: Number = 0, - var userUuid: String = "", - var userHost: String = "", - var nameChannel: String = "" + var id: Int = 0, + var uuid: String = "", + var name: String = "", + var description: String = "", + var thumbUrl: String = "", + var userImageUrl: String = "", + var embedUrl: String = "", + var duration: Number = 0, + var username: String = "", + var views: Number = 0, + var userUuid: String = "", + var userHost: String = "", + var nameChannel: String = "", + var isLive: Boolean = false, + var streamingData: StreamingModel? = null ):Serializable { fun getChannel(): String { return "$nameChannel@$userHost" @@ -55,6 +57,18 @@ class VideoModel( "views"->{ this.views = data.nextInt() } + "isLive"-> { + this.isLive = data.nextBoolean() + } + "streamingPlaylists"-> { + data.beginArray() + if (data.hasNext()) { + val streamingData = StreamingModel() + streamingData.parse(data) + this.streamingData = streamingData + } + data.endArray() + } "channel"->{ data.beginObject() while (data.hasNext()){ diff --git a/app/src/main/res/drawable/live_shape.xml b/app/src/main/res/drawable/live_shape.xml new file mode 100644 index 0000000..fd5f4ca --- /dev/null +++ b/app/src/main/res/drawable/live_shape.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/view_video.xml b/app/src/main/res/layout/view_video.xml index fef3772..db6d5d6 100644 --- a/app/src/main/res/layout/view_video.xml +++ b/app/src/main/res/layout/view_video.xml @@ -30,6 +30,23 @@ app:layout_constraintTop_toTopOf="parent" app:srcCompat="@android:drawable/ic_menu_gallery" /> + + minutos horas Inicia session + En vivo Te has desconectado diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index af45e67..502467a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,7 +9,6 @@ Loading… - https://gitlab.com/agosto182/p2play/ https://personaljournal.ca/p2play/ @@ -60,6 +59,7 @@ hours Log In P2Play + Live You are now disconnected