Showing commentaries on videos

This commit is contained in:
ivan agosto 2019-01-25 11:38:59 -06:00
parent 5cf806577a
commit ab69d59f9a
4 changed files with 44 additions and 31 deletions

View File

@ -15,11 +15,14 @@ import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_reproductor.* import kotlinx.android.synthetic.main.activity_reproductor.*
import org.libre.agosto.p2play.adapters.CommentariesAdapter import org.libre.agosto.p2play.adapters.CommentariesAdapter
import org.libre.agosto.p2play.ajax.Actions import org.libre.agosto.p2play.ajax.Actions
import org.libre.agosto.p2play.ajax.Comments
import org.libre.agosto.p2play.models.CommentaryModel
import org.libre.agosto.p2play.models.VideoModel import org.libre.agosto.p2play.models.VideoModel
class ReproductorActivity : AppCompatActivity() { class ReproductorActivity : AppCompatActivity() {
lateinit var video:VideoModel lateinit var video:VideoModel
private val _actions: Actions = Actions() private val _actions: Actions = Actions()
private val client: Comments = Comments()
// Commentaries adapter values // Commentaries adapter values
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
@ -39,30 +42,6 @@ class ReproductorActivity : AppCompatActivity() {
videoView.settings.allowUniversalAccessFromFileURLs = true videoView.settings.allowUniversalAccessFromFileURLs = true
videoView.settings.domStorageEnabled = true videoView.settings.domStorageEnabled = true
try {
viewManager = LinearLayoutManager(this)
// Set data for RecyclerView
viewAdapter = CommentariesAdapter(arrayListOf())
recyclerView = findViewById<RecyclerView>(R.id.listCommentaries).apply {
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
setHasFixedSize(true)
// use a linear layout manager
layoutManager = viewManager
// specify an viewAdapter (see also next example)
adapter = viewAdapter
}
}catch (err: Exception){
err.printStackTrace()
Log.d("Error", err?.message)
}
try { try {
this.video = this.intent.extras.getSerializable("video") as VideoModel this.video = this.intent.extras.getSerializable("video") as VideoModel
tittleVideoTxt.text = this.video.name tittleVideoTxt.text = this.video.name
@ -73,13 +52,19 @@ class ReproductorActivity : AppCompatActivity() {
if(this.video.userImageUrl!="") if(this.video.userImageUrl!="")
Picasso.get().load("https://"+ManagerSingleton.url+this.video.userImageUrl).into(userImg) Picasso.get().load("https://"+ManagerSingleton.url+this.video.userImageUrl).into(userImg)
videoView.loadUrl("https://"+ManagerSingleton.url+this.video.embedUrl) videoView.loadUrl("https://"+ManagerSingleton.url+this.video.embedUrl)
Log.d("url", videoView.url)
} }
catch (err:Exception){ catch (err:Exception){
err.printStackTrace() err.printStackTrace()
Log.d("Error", err?.message) Log.d("Error", err?.message)
} }
viewManager = LinearLayoutManager(this)
this.setDataComments(arrayListOf())
this.getComments()
subscribeBtn.setOnClickListener { subscribe() } subscribeBtn.setOnClickListener { subscribe() }
likeLayout.setOnClickListener { rate("like") } likeLayout.setOnClickListener { rate("like") }
dislikeLayout.setOnClickListener { rate("dislike") } dislikeLayout.setOnClickListener { rate("dislike") }
@ -183,6 +168,32 @@ class ReproductorActivity : AppCompatActivity() {
} }
} }
private fun setDataComments(data: ArrayList<CommentaryModel>) {
// Set data for RecyclerView
viewAdapter = CommentariesAdapter(data)
recyclerView = findViewById<RecyclerView>(R.id.listCommentaries).apply {
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
setHasFixedSize(true)
// use a linear layout manager
layoutManager = viewManager
// specify an viewAdapter (see also next example)
adapter = viewAdapter
}
}
private fun getComments() {
AsyncTask.execute {
val data = this.client.getCommentaries(this.video.id)
runOnUiThread {
this.setDataComments(data)
}
}
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if(ManagerSingleton.user.status == 1) { if(ManagerSingleton.user.status == 1) {

View File

@ -48,7 +48,7 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
viewType: Int): CommentariesAdapter.ViewHolder { viewType: Int): CommentariesAdapter.ViewHolder {
// create a new view // create a new view
val view = LayoutInflater.from(parent.context) val view = LayoutInflater.from(parent.context)
.inflate(R.layout.view_video, parent, false) as View .inflate(R.layout.view_commentary, parent, false) as View
// set the view's size, margins, paddings and layout parameters // set the view's size, margins, paddings and layout parameters
return ViewHolder(view) return ViewHolder(view)
} }

View File

@ -231,6 +231,7 @@
android:id="@+id/listCommentaries" android:id="@+id/listCommentaries"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

View File

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp"> android:paddingRight="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView <ImageView
android:id="@+id/userCommentImg" android:id="@+id/userCommentImg"