2019-01-24 22:56:20 +01:00
|
|
|
package org.libre.agosto.p2play.adapters
|
|
|
|
|
2019-02-10 18:41:56 +01:00
|
|
|
import android.content.Context
|
2024-03-28 03:54:14 +01:00
|
|
|
import android.content.Intent
|
2024-03-23 00:23:16 +01:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2019-02-16 07:33:54 +01:00
|
|
|
import android.text.Html
|
2019-01-24 22:56:20 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.TextView
|
|
|
|
import com.squareup.picasso.Picasso
|
2024-03-28 03:54:14 +01:00
|
|
|
import kotlinx.android.synthetic.main.view_video.view.userImg
|
2019-02-24 17:34:12 +01:00
|
|
|
import org.libre.agosto.p2play.*
|
2019-01-24 22:56:20 +01:00
|
|
|
import org.libre.agosto.p2play.models.CommentaryModel
|
|
|
|
|
2019-12-13 16:53:10 +01:00
|
|
|
@Suppress("DEPRECATION")
|
2019-01-24 22:56:20 +01:00
|
|
|
class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
|
|
|
|
RecyclerView.Adapter<CommentariesAdapter.ViewHolder>() {
|
|
|
|
|
|
|
|
// Provide a reference to the views for each data item
|
|
|
|
// Complex data items may need more than one view per item, and
|
|
|
|
// you provide access to all the views for a data item in a view holder.
|
|
|
|
// Each data item is just a string in this case that is shown in a TextView.
|
|
|
|
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view){
|
|
|
|
val userImg: ImageView
|
|
|
|
val username: TextView
|
|
|
|
val commentary: TextView
|
2019-02-10 18:41:56 +01:00
|
|
|
val context: Context
|
2019-01-24 22:56:20 +01:00
|
|
|
|
|
|
|
init {
|
|
|
|
// Define click listener for the ViewHolder's View
|
|
|
|
username = view.findViewById(R.id.userTxt)
|
|
|
|
commentary = view.findViewById(R.id.userCommentary)
|
|
|
|
userImg = view.findViewById(R.id.userCommentImg)
|
2019-02-10 18:41:56 +01:00
|
|
|
context = view.context
|
2019-01-24 22:56:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create new views (invoked by the layout manager)
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup,
|
|
|
|
viewType: Int): CommentariesAdapter.ViewHolder {
|
|
|
|
// create a new view
|
|
|
|
val view = LayoutInflater.from(parent.context)
|
2019-01-25 18:38:59 +01:00
|
|
|
.inflate(R.layout.view_commentary, parent, false) as View
|
2024-03-28 03:54:14 +01:00
|
|
|
|
2019-01-24 22:56:20 +01:00
|
|
|
// set the view's size, margins, paddings and layout parameters
|
|
|
|
return ViewHolder(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace the contents of a view (invoked by the layout manager)
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
|
// - get element from your dataset at this position
|
|
|
|
// - replace the contents of the view with that element
|
|
|
|
holder.username.text = myDataset[position].username
|
|
|
|
|
2019-02-24 17:34:12 +01:00
|
|
|
// holder.userImg.setOnClickListener {
|
|
|
|
// val intent = Intent(holder.context, ChannelActivity::class.java)
|
|
|
|
// intent.putExtra("channel", myDataset[position])
|
|
|
|
// holder.context.startActivity(intent)
|
|
|
|
// }
|
|
|
|
|
2019-01-24 22:56:20 +01:00
|
|
|
if(myDataset[position].userImageUrl!="")
|
|
|
|
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg);
|
|
|
|
|
2019-02-16 07:33:54 +01:00
|
|
|
holder.commentary.text = Html.fromHtml(myDataset[position].commentary)
|
2019-01-24 22:56:20 +01:00
|
|
|
|
2024-03-28 03:54:14 +01:00
|
|
|
// TODO: Support for view and account (is different than a video channel)
|
|
|
|
// holder.userImg.setOnClickListener {
|
|
|
|
// val intent = Intent(holder.context, ChannelActivity::class.java)
|
|
|
|
// intent.putExtra("channel", myDataset[position].getAccount())
|
|
|
|
// holder.context.startActivity(intent)
|
|
|
|
// }
|
2019-01-24 22:56:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the size of your dataset (invoked by the layout manager)
|
|
|
|
override fun getItemCount() = myDataset.size
|
|
|
|
}
|