From d58725495b2fc87b2d21ad69f1d1160ba140647a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 7 May 2022 23:44:29 +0200 Subject: [PATCH] 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,"") +}