mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
codebase
This commit is contained in:
parent
e7f6706c05
commit
a821515175
@ -1,5 +1,6 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -12,10 +13,24 @@ import com.github.libretube.MainActivity
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.formatShort
|
||||
import com.github.libretube.obj.Comment
|
||||
import com.github.libretube.obj.CommentsPage
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
import com.squareup.picasso.Picasso
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class CommentsAdapter(private val comments: MutableList<Comment>) :
|
||||
RecyclerView.Adapter<CommentsViewHolder>() {
|
||||
class CommentsAdapter(
|
||||
private val videoId: String,
|
||||
private val comments: MutableList<Comment>
|
||||
) : RecyclerView.Adapter<CommentsViewHolder>() {
|
||||
|
||||
private val TAG = "CommentsAdapter"
|
||||
private var isLoading = false
|
||||
private var nextPage = ""
|
||||
private lateinit var repliesRecView: RecyclerView
|
||||
|
||||
fun updateItems(newItems: List<Comment>) {
|
||||
var commentsSize = comments.size
|
||||
@ -61,11 +76,45 @@ class CommentsAdapter(private val comments: MutableList<Comment>) :
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
repliesRecView = holder.v.findViewById(R.id.replies_recView)
|
||||
// repliesRecView.layoutManager = LinearLayoutManager(holder.v.context)
|
||||
holder.v.setOnClickListener {
|
||||
if (repliesRecView.visibility == View.GONE) {
|
||||
repliesRecView.visibility = View.VISIBLE
|
||||
nextPage = comments[position].repliesPage!!
|
||||
repliesRecView.adapter = CommentsAdapter(videoId, comments)
|
||||
// fetchReplies()
|
||||
} else {
|
||||
repliesRecView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return comments.size
|
||||
}
|
||||
|
||||
private fun fetchReplies() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
if (!isLoading && nextPage != null) {
|
||||
var response = CommentsPage()
|
||||
isLoading = true
|
||||
try {
|
||||
response = RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response," + e.response())
|
||||
}
|
||||
nextPage = if (response.nextpage != null) response.nextpage!!
|
||||
else ""
|
||||
// commentsAdapter?.updateItems(response.comments)
|
||||
repliesRecView.adapter = RepliesAdapter(response.comments)
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CommentsViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
|
@ -0,0 +1,79 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.MainActivity
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.formatShort
|
||||
import com.github.libretube.obj.Comment
|
||||
import com.squareup.picasso.Picasso
|
||||
|
||||
class RepliesAdapter(
|
||||
private val replies: MutableList<Comment>
|
||||
) : RecyclerView.Adapter<RepliesViewHolder>() {
|
||||
|
||||
private val TAG = "RepliesAdapter"
|
||||
private var isLoading = false
|
||||
private var nextPage = ""
|
||||
|
||||
fun updateItems(newItems: List<Comment>) {
|
||||
var repliesSize = replies.size
|
||||
replies.addAll(newItems)
|
||||
notifyItemRangeInserted(repliesSize, newItems.size)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepliesViewHolder {
|
||||
var repliesView =
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.replies_row, parent, false)
|
||||
return RepliesViewHolder(repliesView)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RepliesViewHolder, position: Int) {
|
||||
holder.v.findViewById<TextView>(R.id.comment_infos).text =
|
||||
replies[position].author.toString() +
|
||||
" • " + replies[position].commentedTime.toString()
|
||||
holder.v.findViewById<TextView>(R.id.comment_text).text =
|
||||
replies[position].commentText.toString()
|
||||
val channelImage = holder.v.findViewById<ImageView>(R.id.commentor_image)
|
||||
Picasso.get().load(replies[position].thumbnail).fit().centerCrop().into(channelImage)
|
||||
holder.v.findViewById<TextView>(R.id.likes_textView).text =
|
||||
replies[position].likeCount?.toLong().formatShort()
|
||||
if (replies[position].verified == true) {
|
||||
holder.v.findViewById<ImageView>(R.id.verified_imageView).visibility = View.VISIBLE
|
||||
}
|
||||
if (replies[position].pinned == true) {
|
||||
holder.v.findViewById<ImageView>(R.id.pinned_imageView).visibility = View.VISIBLE
|
||||
}
|
||||
if (replies[position].hearted == true) {
|
||||
holder.v.findViewById<ImageView>(R.id.hearted_imageView).visibility = View.VISIBLE
|
||||
}
|
||||
channelImage.setOnClickListener {
|
||||
val activity = holder.v.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to replies[position].commentorUrl)
|
||||
activity.navController.navigate(R.id.channel, bundle)
|
||||
try {
|
||||
val mainMotionLayout = activity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
||||
if (mainMotionLayout.progress == 0.toFloat()) {
|
||||
mainMotionLayout.transitionToEnd()
|
||||
activity.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return replies.size
|
||||
}
|
||||
}
|
||||
|
||||
class RepliesViewHolder(val v: View) : RecyclerView.ViewHolder(v) {
|
||||
init {
|
||||
}
|
||||
}
|
@ -943,7 +943,7 @@ class PlayerFragment : Fragment() {
|
||||
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
|
||||
return@launchWhenCreated
|
||||
}
|
||||
commentsAdapter = CommentsAdapter(commentsResponse.comments)
|
||||
commentsAdapter = CommentsAdapter(videoId!!, commentsResponse.comments)
|
||||
commentsRecView.adapter = commentsAdapter
|
||||
nextPage = commentsResponse.nextpage
|
||||
commentsLoaded = true
|
||||
|
@ -5,6 +5,10 @@
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
@ -97,5 +101,14 @@
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/replies_recView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
101
app/src/main/res/layout/replies_row.xml
Normal file
101
app/src/main/res/layout/replies_row.xml
Normal file
@ -0,0 +1,101 @@
|
||||
<?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"
|
||||
android:layout_width="match_parent"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/commentor_image"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:srcCompat="@mipmap/ic_launcher" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/comment_infos"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text="Author and Time"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/verified_imageView"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
app:srcCompat="@drawable/ic_verified"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pinned_imageView"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
app:srcCompat="@drawable/ic_pinned"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/comment_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:autoLink="web"
|
||||
android:text="Comment Text" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/likes_imageView"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginRight="6dp"
|
||||
android:layout_marginTop="2dp"
|
||||
app:srcCompat="@drawable/ic_thumb_up" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/likes_textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="LikeCount" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/hearted_imageView"
|
||||
android:layout_width="14dp"
|
||||
android:layout_height="14dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginTop="3dp"
|
||||
app:srcCompat="@drawable/ic_hearted"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user