From d58725495b2fc87b2d21ad69f1d1160ba140647a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 7 May 2022 23:44:29 +0200 Subject: [PATCH 01/15] Comments API --- .../java/com/github/libretube/PipedApi.kt | 3 +++ .../com/github/libretube/PlayerFragment.kt | 13 +++++++++++ .../com/github/libretube/obj/Comment.java | 22 ------------------- .../java/com/github/libretube/obj/Comment.kt | 20 +++++++++++++++++ .../github/libretube/obj/CommentsPage.java | 16 -------------- .../com/github/libretube/obj/CommentsPage.kt | 12 ++++++++++ 6 files changed, 48 insertions(+), 38 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/obj/Comment.java create mode 100644 app/src/main/java/com/github/libretube/obj/Comment.kt delete mode 100644 app/src/main/java/com/github/libretube/obj/CommentsPage.java create mode 100644 app/src/main/java/com/github/libretube/obj/CommentsPage.kt diff --git a/app/src/main/java/com/github/libretube/PipedApi.kt b/app/src/main/java/com/github/libretube/PipedApi.kt index bfd9a71cb..f7ada33c9 100644 --- a/app/src/main/java/com/github/libretube/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/PipedApi.kt @@ -10,6 +10,9 @@ interface PipedApi { @GET("streams/{videoId}") suspend fun getStreams(@Path("videoId") videoId: String): Streams + @GET("comments/{videoId}") + suspend fun getComments(@Path("videoId") videoId: String): CommentsPage + @GET("search") suspend fun getSearchResults( @Query("q") searchQuery: String, diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index c08ac332f..3f00d1560 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -253,6 +253,19 @@ class PlayerFragment : Fragment() { Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } + val commentsResponse = try { + RetrofitInstance.api.getComments(videoId!!) + } catch (e: IOException) { + println(e) + Log.e(TAG, "IOException, you might not have internet connection") + Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() + return@launchWhenCreated + } catch (e: HttpException) { + Log.e(TAG, "HttpException, unexpected response") + Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() + return@launchWhenCreated + } + Toast.makeText(context, commentsResponse.disabled.toString(), Toast.LENGTH_LONG).show() var videosNameArray: Array = arrayOf() videosNameArray += "HLS" for (vid in response.videoStreams!!) { diff --git a/app/src/main/java/com/github/libretube/obj/Comment.java b/app/src/main/java/com/github/libretube/obj/Comment.java deleted file mode 100644 index 953bb7bdf..000000000 --- a/app/src/main/java/com/github/libretube/obj/Comment.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.libretube.obj; - -public class Comment { - public String author, thumbnail, commentId, commentText, commentedTime, commentorUrl, repliesPage; - public int likeCount; - public boolean hearted, pinned, verified; - - public Comment(String author, String thumbnail, String commentId, String commentText, String commentedTime, - String commentorUrl, String repliesPage, int likeCount, boolean hearted, boolean pinned, boolean verified) { - this.author = author; - this.thumbnail = thumbnail; - this.commentId = commentId; - this.commentText = commentText; - this.commentedTime = commentedTime; - this.commentorUrl = commentorUrl; - this.repliesPage = repliesPage; - this.likeCount = likeCount; - this.hearted = hearted; - this.pinned = pinned; - this.verified = verified; - } -} diff --git a/app/src/main/java/com/github/libretube/obj/Comment.kt b/app/src/main/java/com/github/libretube/obj/Comment.kt new file mode 100644 index 000000000..2e015acc8 --- /dev/null +++ b/app/src/main/java/com/github/libretube/obj/Comment.kt @@ -0,0 +1,20 @@ +package com.github.libretube.obj + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties + +@JsonIgnoreProperties(ignoreUnknown = true) +data class Comment( + val author: String?, + val commentId: String?, + val commentText: String?, + val commentedTime: String?, + val commentorUrl: String?, + val hearted: Boolean?, + val likeCount: Int?, + val pinned: Boolean?, + val thumbnail: String?, + val verified: Boolean? +){ + constructor(): this("", "","","","",null,0,null,"",null) +} + diff --git a/app/src/main/java/com/github/libretube/obj/CommentsPage.java b/app/src/main/java/com/github/libretube/obj/CommentsPage.java deleted file mode 100644 index a8fb24b20..000000000 --- a/app/src/main/java/com/github/libretube/obj/CommentsPage.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.libretube.obj; - -import java.util.List; - -public class CommentsPage { - - public List comments; - public String nextpage; - public boolean disabled; - - public CommentsPage(List comments, String nextpage, boolean disabled) { - this.comments = comments; - this.nextpage = nextpage; - this.disabled = disabled; - } -} diff --git a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt new file mode 100644 index 000000000..c1e32a16b --- /dev/null +++ b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt @@ -0,0 +1,12 @@ +package com.github.libretube.obj + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties + +@JsonIgnoreProperties(ignoreUnknown = true) +data class CommentsPage( + val comments: List? = listOf(), + val disabled: Boolean? = null, + val nextpage: String? = "", +){ + constructor(): this(emptyList(),null,"") +} From 8b09b6ad429b8a25acfb785d94a29eb587618ff0 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 12:33:01 +0200 Subject: [PATCH 02/15] Basic Comments Impletation --- .../com/github/libretube/PlayerFragment.kt | 8 +++- .../libretube/adapters/CommentsAdapter.kt | 37 +++++++++++++++ .../com/github/libretube/obj/CommentsPage.kt | 2 +- app/src/main/res/layout/comments_row.xml | 47 +++++++++++++++++++ app/src/main/res/layout/fragment_player.xml | 23 +++++---- app/src/main/res/values/strings.xml | 1 + 6 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt create mode 100644 app/src/main/res/layout/comments_row.xml diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 3f00d1560..288dc89a5 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -31,7 +31,9 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.adapters.CommentsAdapter import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.obj.PipedStream import com.github.libretube.obj.Subscribe @@ -75,6 +77,7 @@ class PlayerFragment : Fragment() { var isSubscribed: Boolean = false private lateinit var relatedRecView: RecyclerView + private lateinit var commentsRecView: RecyclerView private lateinit var exoPlayerView: StyledPlayerView private lateinit var motionLayout: MotionLayout private lateinit var exoPlayer: ExoPlayer @@ -221,6 +224,9 @@ class PlayerFragment : Fragment() { isFullScreen = false } } + commentsRecView = view.findViewById(R.id.comments_recView) + commentsRecView.layoutManager = LinearLayoutManager(view.context) + relatedRecView = view.findViewById(R.id.player_recView) relatedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items)) @@ -265,7 +271,6 @@ class PlayerFragment : Fragment() { Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } - Toast.makeText(context, commentsResponse.disabled.toString(), Toast.LENGTH_LONG).show() var videosNameArray: Array = arrayOf() videosNameArray += "HLS" for (vid in response.videoStreams!!) { @@ -489,6 +494,7 @@ class PlayerFragment : Fragment() { } } }) + commentsRecView.adapter = CommentsAdapter(commentsResponse.comments) relatedRecView.adapter = TrendingAdapter(response.relatedStreams!!) view.findViewById(R.id.player_description).text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt new file mode 100644 index 000000000..110877852 --- /dev/null +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -0,0 +1,37 @@ +package com.github.libretube.adapters + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.R +import com.github.libretube.obj.Comment +import com.squareup.picasso.Picasso + +class CommentsAdapter(private val comments: List): RecyclerView.Adapter(){ + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + var commentsView = LayoutInflater.from(parent.context).inflate(R.layout.comments_row, parent, false) + return ViewHolder(commentsView) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.v.findViewById(R.id.comment_author).text = comments[position].author.toString() + holder.v.findViewById(R.id.comment_text).text = comments[position].commentText.toString() + val thumbnailImage = holder.v.findViewById(R.id.commentor_image) + Picasso.get().load(comments[position].thumbnail).into(thumbnailImage) + } + + override fun getItemCount(): Int { + return comments.size + } + +} + +class ViewHolder(val v: View): RecyclerView.ViewHolder(v){ + init { + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt index c1e32a16b..1125d55eb 100644 --- a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt +++ b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties @JsonIgnoreProperties(ignoreUnknown = true) data class CommentsPage( - val comments: List? = listOf(), + val comments: List = listOf(), val disabled: Boolean? = null, val nextpage: String? = "", ){ diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml new file mode 100644 index 000000000..f2c32d1fc --- /dev/null +++ b/app/src/main/res/layout/comments_row.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index d3057fba0..b6272fc5c 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -254,19 +254,26 @@ android:id="@+id/tv_suggestion" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="10dp" - android:layout_marginTop="10dp" - android:layout_marginRight="10dp" - android:text="More like that" - android:textSize="17sp" - android:visibility="gone"/> + android:layout_margin="10dp" + android:text="@string/comments" + android:textSize="17sp" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 48c6e8bc7..c6d5b8e2e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,4 +63,5 @@ Light Theme Dark Theme %1$s subscribers + Comments From 46f7681522daa39f56bdffb9fd42fe1c36e01c73 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 12:59:44 +0200 Subject: [PATCH 03/15] Added Toggle --- .../com/github/libretube/PlayerFragment.kt | 6 +++ app/src/main/res/layout/fragment_player.xml | 41 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 288dc89a5..58f5390b7 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -199,6 +199,12 @@ class PlayerFragment : Fragment() { playerDescription.visibility = if (visible) View.GONE else View.VISIBLE } + + view.findViewById(R.id.comments_toggle).setOnClickListener { + var visible = commentsRecView.isVisible + commentsRecView.visibility = if (visible) View.GONE else View.VISIBLE + } + // FullScreen button trigger view.findViewById(R.id.fullscreen).setOnClickListener { // remember to hide everything when new thing added diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index b6272fc5c..92074f605 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -250,20 +250,43 @@ android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants"> - + + + + + + + + android:layout_margin="20dp" + android:layout_below="@id/comments_toggle" + android:visibility="gone" /> Date: Sun, 8 May 2022 13:19:50 +0200 Subject: [PATCH 04/15] Added Likes and Creation Time --- .../libretube/adapters/CommentsAdapter.kt | 3 ++- app/src/main/res/drawable/ic_thumb_up.xml | 10 +++++++ app/src/main/res/layout/comments_row.xml | 27 +++++++++++++++++-- app/src/main/res/layout/fragment_player.xml | 4 ++- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_thumb_up.xml diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 110877852..aebd66a93 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -19,10 +19,11 @@ class CommentsAdapter(private val comments: List): RecyclerView.Adapte } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.v.findViewById(R.id.comment_author).text = comments[position].author.toString() + holder.v.findViewById(R.id.comment_author).text = comments[position].author.toString() + " • " + comments[position].commentedTime.toString() holder.v.findViewById(R.id.comment_text).text = comments[position].commentText.toString() val thumbnailImage = holder.v.findViewById(R.id.commentor_image) Picasso.get().load(comments[position].thumbnail).into(thumbnailImage) + holder.v.findViewById(R.id.likes_textView).text = comments[position].likeCount.toString() } override fun getItemCount(): Int { diff --git a/app/src/main/res/drawable/ic_thumb_up.xml b/app/src/main/res/drawable/ic_thumb_up.xml new file mode 100644 index 000000000..6a39a3934 --- /dev/null +++ b/app/src/main/res/drawable/ic_thumb_up.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml index f2c32d1fc..4d4e7dbe1 100644 --- a/app/src/main/res/layout/comments_row.xml +++ b/app/src/main/res/layout/comments_row.xml @@ -10,7 +10,9 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:paddingBottom="16dp" + > + + + + + + + + diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 92074f605..3230423a9 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -284,7 +284,9 @@ android:id="@+id/comments_recView" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="20dp" + android:layout_marginTop="20dp" + android:layout_marginLeft="20dp" + android:layout_marginRight="20dp" android:layout_below="@id/comments_toggle" android:visibility="gone" /> From 8c99f56f43f0eeb15b95a99b55ef616a1ede5caf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 14:14:06 +0200 Subject: [PATCH 05/15] Added Hearted and Pinned --- .../libretube/adapters/CommentsAdapter.kt | 12 ++++- app/src/main/res/drawable/ic_hearted.xml | 9 ++++ app/src/main/res/drawable/ic_pinned.xml | 11 ++++ app/src/main/res/drawable/ic_verified.xml | 10 ++++ app/src/main/res/layout/comments_row.xml | 52 +++++++++++++++---- 5 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/drawable/ic_hearted.xml create mode 100644 app/src/main/res/drawable/ic_pinned.xml create mode 100644 app/src/main/res/drawable/ic_verified.xml diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index aebd66a93..0dbb3ca28 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import android.widget.Toast import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R import com.github.libretube.obj.Comment @@ -19,11 +20,20 @@ class CommentsAdapter(private val comments: List): RecyclerView.Adapte } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.v.findViewById(R.id.comment_author).text = comments[position].author.toString() + " • " + comments[position].commentedTime.toString() + holder.v.findViewById(R.id.comment_infos).text = comments[position].author.toString() + " • " + comments[position].commentedTime.toString() holder.v.findViewById(R.id.comment_text).text = comments[position].commentText.toString() val thumbnailImage = holder.v.findViewById(R.id.commentor_image) Picasso.get().load(comments[position].thumbnail).into(thumbnailImage) holder.v.findViewById(R.id.likes_textView).text = comments[position].likeCount.toString() + if (comments[position].verified == true) { + holder.v.findViewById(R.id.verified_imageView).visibility = View.VISIBLE + } + if (comments[position].pinned == true) { + holder.v.findViewById(R.id.pinned_imageView).visibility = View.VISIBLE + } + if (comments[position].hearted == true) { + holder.v.findViewById(R.id.hearted_imageView).visibility = View.VISIBLE + } } override fun getItemCount(): Int { diff --git a/app/src/main/res/drawable/ic_hearted.xml b/app/src/main/res/drawable/ic_hearted.xml new file mode 100644 index 000000000..f690e38fd --- /dev/null +++ b/app/src/main/res/drawable/ic_hearted.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_pinned.xml b/app/src/main/res/drawable/ic_pinned.xml new file mode 100644 index 000000000..f1e14a868 --- /dev/null +++ b/app/src/main/res/drawable/ic_pinned.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_verified.xml b/app/src/main/res/drawable/ic_verified.xml new file mode 100644 index 000000000..bbb482627 --- /dev/null +++ b/app/src/main/res/drawable/ic_verified.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml index 4d4e7dbe1..878a2841e 100644 --- a/app/src/main/res/layout/comments_row.xml +++ b/app/src/main/res/layout/comments_row.xml @@ -26,15 +26,39 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + + + + + + + + + android:text="LikeCount" /> + From 4a03b2209c89243d00388464818e198d4655a59c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 17:12:03 +0200 Subject: [PATCH 06/15] Use formatShort() for Like Count --- .../java/com/github/libretube/adapters/CommentsAdapter.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 0dbb3ca28..d3760dcda 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -1,14 +1,13 @@ package com.github.libretube.adapters -import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView -import android.widget.Toast import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R +import com.github.libretube.formatShort import com.github.libretube.obj.Comment import com.squareup.picasso.Picasso @@ -24,7 +23,7 @@ class CommentsAdapter(private val comments: List): RecyclerView.Adapte holder.v.findViewById(R.id.comment_text).text = comments[position].commentText.toString() val thumbnailImage = holder.v.findViewById(R.id.commentor_image) Picasso.get().load(comments[position].thumbnail).into(thumbnailImage) - holder.v.findViewById(R.id.likes_textView).text = comments[position].likeCount.toString() + holder.v.findViewById(R.id.likes_textView).text = comments[position].likeCount?.toLong().formatShort() if (comments[position].verified == true) { holder.v.findViewById(R.id.verified_imageView).visibility = View.VISIBLE } From 39439039af943aba626b0a988544d3364118ec3f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 18:25:22 +0200 Subject: [PATCH 07/15] Fixed minimize on scroll --- app/src/main/res/layout/fragment_player.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 3230423a9..c4ad18253 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -288,6 +288,7 @@ android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_below="@id/comments_toggle" + android:nestedScrollingEnabled="false" android:visibility="gone" /> Date: Sun, 8 May 2022 19:32:13 +0200 Subject: [PATCH 08/15] Added ability to load more comments through scrolling --- .../java/com/github/libretube/PipedApi.kt | 3 ++ .../com/github/libretube/PlayerFragment.kt | 50 ++++++++++++++++--- .../libretube/adapters/CommentsAdapter.kt | 8 ++- .../com/github/libretube/obj/CommentsPage.kt | 4 +- app/src/main/res/layout/fragment_player.xml | 2 +- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PipedApi.kt b/app/src/main/java/com/github/libretube/PipedApi.kt index f7ada33c9..94c2a65b5 100644 --- a/app/src/main/java/com/github/libretube/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/PipedApi.kt @@ -13,6 +13,9 @@ interface PipedApi { @GET("comments/{videoId}") suspend fun getComments(@Path("videoId") videoId: String): CommentsPage + @GET("nextpage/comments/{videoId}") + suspend fun getCommentsNextPage(@Path("videoId") videoId: String, @Query("nextpage") nextPage: String): CommentsPage + @GET("search") suspend fun getSearchResults( @Query("q") searchQuery: String, diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 58f5390b7..ae43231d0 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -33,6 +33,7 @@ import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.adapters.ChannelAdapter import com.github.libretube.adapters.CommentsAdapter import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.obj.PipedStream @@ -78,6 +79,8 @@ class PlayerFragment : Fragment() { private lateinit var relatedRecView: RecyclerView private lateinit var commentsRecView: RecyclerView + private var nextPage: String? = null + var commentsAdapter: CommentsAdapter? = null private lateinit var exoPlayerView: StyledPlayerView private lateinit var motionLayout: MotionLayout private lateinit var exoPlayer: ExoPlayer @@ -195,14 +198,13 @@ class PlayerFragment : Fragment() { } view.findViewById(R.id.player_title_layout).setOnClickListener { - var visible = playerDescription.isVisible - - playerDescription.visibility = if (visible) View.GONE else View.VISIBLE + playerDescription.visibility = + if (playerDescription.isVisible) View.GONE else View.VISIBLE } view.findViewById(R.id.comments_toggle).setOnClickListener { - var visible = commentsRecView.isVisible - commentsRecView.visibility = if (visible) View.GONE else View.VISIBLE + commentsRecView.visibility = if (commentsRecView.isVisible) View.GONE else View.VISIBLE + relatedRecView.visibility = if (relatedRecView.isVisible) View.GONE else View.VISIBLE } // FullScreen button trigger @@ -230,6 +232,18 @@ class PlayerFragment : Fragment() { isFullScreen = false } } + + val scrollView = view.findViewById(R.id.player_scrollView) + scrollView.viewTreeObserver + .addOnScrollChangedListener { + if (scrollView.getChildAt(0).bottom + == (scrollView.height + scrollView.scrollY) + ) { + fetchNextComments() + } + + } + commentsRecView = view.findViewById(R.id.comments_recView) commentsRecView.layoutManager = LinearLayoutManager(view.context) @@ -500,8 +514,11 @@ class PlayerFragment : Fragment() { } } }) - commentsRecView.adapter = CommentsAdapter(commentsResponse.comments) + commentsAdapter = CommentsAdapter(commentsResponse.comments) + commentsRecView.adapter = commentsAdapter + nextPage = commentsResponse.nextpage relatedRecView.adapter = TrendingAdapter(response.relatedStreams!!) + view.findViewById(R.id.player_description).text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Html.fromHtml(response.description, Html.FROM_HTML_MODE_COMPACT) @@ -761,4 +778,25 @@ class PlayerFragment : Fragment() { override fun onResume() { super.onResume() } + + private fun fetchNextComments(){ + fun run() { + + lifecycleScope.launchWhenCreated { + val response = try { + RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!) + } catch (e: IOException) { + println(e) + Log.e(TAG, "IOException, you might not have internet connection") + return@launchWhenCreated + } catch (e: HttpException) { + Log.e(TAG, "HttpException, unexpected response,"+e.response()) + return@launchWhenCreated + } + nextPage = response.nextpage + commentsAdapter?.updateItems(response.comments!!) + } + } + run() + } } diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index d3760dcda..06dd1d65e 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -9,9 +9,15 @@ import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R import com.github.libretube.formatShort import com.github.libretube.obj.Comment +import com.github.libretube.obj.StreamItem import com.squareup.picasso.Picasso -class CommentsAdapter(private val comments: List): RecyclerView.Adapter(){ +class CommentsAdapter(private val comments: MutableList): RecyclerView.Adapter(){ + + fun updateItems(newItems: List){ + comments.addAll(newItems) + notifyDataSetChanged() + } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { var commentsView = LayoutInflater.from(parent.context).inflate(R.layout.comments_row, parent, false) diff --git a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt index 1125d55eb..54b5519d0 100644 --- a/app/src/main/java/com/github/libretube/obj/CommentsPage.kt +++ b/app/src/main/java/com/github/libretube/obj/CommentsPage.kt @@ -4,9 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties @JsonIgnoreProperties(ignoreUnknown = true) data class CommentsPage( - val comments: List = listOf(), + val comments: MutableList = arrayListOf(), val disabled: Boolean? = null, val nextpage: String? = "", ){ - constructor(): this(emptyList(),null,"") + constructor(): this(arrayListOf(),null,"") } diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index c4ad18253..e92513b53 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -9,7 +9,7 @@ tools:context=".PlayerFragment"> Date: Sun, 8 May 2022 19:51:20 +0200 Subject: [PATCH 09/15] Removed unneeded dependency --- app/src/main/java/com/github/libretube/PlayerFragment.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index ae43231d0..78955d01f 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -33,7 +33,6 @@ import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.github.libretube.adapters.ChannelAdapter import com.github.libretube.adapters.CommentsAdapter import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.obj.PipedStream @@ -780,8 +779,6 @@ class PlayerFragment : Fragment() { } private fun fetchNextComments(){ - fun run() { - lifecycleScope.launchWhenCreated { val response = try { RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!) @@ -796,7 +793,5 @@ class PlayerFragment : Fragment() { nextPage = response.nextpage commentsAdapter?.updateItems(response.comments!!) } - } - run() } } From dfb32d4b64637fb479a91790fb72b1a5d1be82c2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 21:18:04 +0200 Subject: [PATCH 10/15] Prevent using multiple nextpages at the same time --- .../com/github/libretube/PlayerFragment.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 78955d01f..9bb52aba8 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -78,8 +78,9 @@ class PlayerFragment : Fragment() { private lateinit var relatedRecView: RecyclerView private lateinit var commentsRecView: RecyclerView + private var commentsAdapter: CommentsAdapter? = null private var nextPage: String? = null - var commentsAdapter: CommentsAdapter? = null + private var isLoading = true private lateinit var exoPlayerView: StyledPlayerView private lateinit var motionLayout: MotionLayout private lateinit var exoPlayer: ExoPlayer @@ -290,6 +291,7 @@ class PlayerFragment : Fragment() { Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } + isLoading = false var videosNameArray: Array = arrayOf() videosNameArray += "HLS" for (vid in response.videoStreams!!) { @@ -780,18 +782,22 @@ class PlayerFragment : Fragment() { private fun fetchNextComments(){ lifecycleScope.launchWhenCreated { - val response = try { - RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!) - } catch (e: IOException) { - println(e) - Log.e(TAG, "IOException, you might not have internet connection") - return@launchWhenCreated - } catch (e: HttpException) { - Log.e(TAG, "HttpException, unexpected response,"+e.response()) - return@launchWhenCreated + if (!isLoading) { + isLoading = true + val response = try { + RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!) + } catch (e: IOException) { + println(e) + Log.e(TAG, "IOException, you might not have internet connection") + return@launchWhenCreated + } catch (e: HttpException) { + Log.e(TAG, "HttpException, unexpected response," + e.response()) + return@launchWhenCreated + } + nextPage = response.nextpage + commentsAdapter?.updateItems(response.comments!!) + isLoading = false } - nextPage = response.nextpage - commentsAdapter?.updateItems(response.comments!!) } } } From 2d4e70bd69033a067b41bea0fd092a62ee130b67 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 8 May 2022 21:35:45 +0200 Subject: [PATCH 11/15] Replace notifyDataSetChanged --- .../main/java/com/github/libretube/adapters/CommentsAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 06dd1d65e..6c3c18911 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -16,7 +16,7 @@ class CommentsAdapter(private val comments: MutableList): RecyclerView fun updateItems(newItems: List){ comments.addAll(newItems) - notifyDataSetChanged() + notifyItemRangeInserted(comments.size, newItems.size) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { From 48a0fd0724431a5d97eccf4fe7477e8b97db5c51 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 9 May 2022 15:32:40 +0200 Subject: [PATCH 12/15] Added var for commentSize --- .../java/com/github/libretube/adapters/CommentsAdapter.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 6c3c18911..33567187a 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -9,18 +9,18 @@ import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R import com.github.libretube.formatShort import com.github.libretube.obj.Comment -import com.github.libretube.obj.StreamItem import com.squareup.picasso.Picasso class CommentsAdapter(private val comments: MutableList): RecyclerView.Adapter(){ fun updateItems(newItems: List){ comments.addAll(newItems) - notifyItemRangeInserted(comments.size, newItems.size) + var commentsSize = comments.size + notifyItemRangeInserted(commentsSize, newItems.size) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - var commentsView = LayoutInflater.from(parent.context).inflate(R.layout.comments_row, parent, false) + var commentsView = LayoutInflater.from(parent.context).inflate(R.layout.comments_row, parent, false) return ViewHolder(commentsView) } From 6ed2fabd274156a4e7ec7a1dced54a028700061d Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 9 May 2022 16:25:44 +0200 Subject: [PATCH 13/15] Limited Image Quality and Cache in Comments --- app/src/main/java/com/github/libretube/PlayerFragment.kt | 5 +++++ .../java/com/github/libretube/adapters/CommentsAdapter.kt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 9bb52aba8..f1b91b5ba 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -247,6 +247,11 @@ class PlayerFragment : Fragment() { commentsRecView = view.findViewById(R.id.comments_recView) commentsRecView.layoutManager = LinearLayoutManager(view.context) + commentsRecView.setItemViewCacheSize(20); + commentsRecView.setDrawingCacheEnabled(true); + commentsRecView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); + + relatedRecView = view.findViewById(R.id.player_recView) relatedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items)) diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 33567187a..61a8df2b3 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -28,7 +28,7 @@ class CommentsAdapter(private val comments: MutableList): RecyclerView holder.v.findViewById(R.id.comment_infos).text = comments[position].author.toString() + " • " + comments[position].commentedTime.toString() holder.v.findViewById(R.id.comment_text).text = comments[position].commentText.toString() val thumbnailImage = holder.v.findViewById(R.id.commentor_image) - Picasso.get().load(comments[position].thumbnail).into(thumbnailImage) + Picasso.get().load(comments[position].thumbnail).resize(50,50).centerCrop().into(thumbnailImage) holder.v.findViewById(R.id.likes_textView).text = comments[position].likeCount?.toLong().formatShort() if (comments[position].verified == true) { holder.v.findViewById(R.id.verified_imageView).visibility = View.VISIBLE From 28e8533f658302b9821a19f153bbbc55e64ceda4 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 9 May 2022 17:15:32 +0200 Subject: [PATCH 14/15] Small Performance Improvement --- app/src/main/java/com/github/libretube/PlayerFragment.kt | 7 +++---- .../java/com/github/libretube/adapters/CommentsAdapter.kt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index f1b91b5ba..fa6c60caf 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -247,10 +247,9 @@ class PlayerFragment : Fragment() { commentsRecView = view.findViewById(R.id.comments_recView) commentsRecView.layoutManager = LinearLayoutManager(view.context) - commentsRecView.setItemViewCacheSize(20); - commentsRecView.setDrawingCacheEnabled(true); - commentsRecView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); - + commentsRecView.setItemViewCacheSize(20) + commentsRecView.setDrawingCacheEnabled(true) + commentsRecView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH) relatedRecView = view.findViewById(R.id.player_recView) relatedRecView.layoutManager = diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 61a8df2b3..31c076eb7 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -28,7 +28,7 @@ class CommentsAdapter(private val comments: MutableList): RecyclerView holder.v.findViewById(R.id.comment_infos).text = comments[position].author.toString() + " • " + comments[position].commentedTime.toString() holder.v.findViewById(R.id.comment_text).text = comments[position].commentText.toString() val thumbnailImage = holder.v.findViewById(R.id.commentor_image) - Picasso.get().load(comments[position].thumbnail).resize(50,50).centerCrop().into(thumbnailImage) + Picasso.get().load(comments[position].thumbnail).fit().centerCrop().into(thumbnailImage) holder.v.findViewById(R.id.likes_textView).text = comments[position].likeCount?.toLong().formatShort() if (comments[position].verified == true) { holder.v.findViewById(R.id.verified_imageView).visibility = View.VISIBLE From 4152f9193200cbe36797988e7e285bf98e094aec Mon Sep 17 00:00:00 2001 From: Bnyro <82752168+Bnyro@users.noreply.github.com> Date: Tue, 10 May 2022 06:23:44 +0200 Subject: [PATCH 15/15] Update CommentsAdapter.kt --- .../java/com/github/libretube/adapters/CommentsAdapter.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 31c076eb7..bdd0f0811 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -14,8 +14,8 @@ import com.squareup.picasso.Picasso class CommentsAdapter(private val comments: MutableList): RecyclerView.Adapter(){ fun updateItems(newItems: List){ - comments.addAll(newItems) var commentsSize = comments.size + comments.addAll(newItems) notifyItemRangeInserted(commentsSize, newItems.size) } @@ -50,4 +50,4 @@ class CommentsAdapter(private val comments: MutableList): RecyclerView class ViewHolder(val v: View): RecyclerView.ViewHolder(v){ init { } -} \ No newline at end of file +}