diff --git a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt index e2a0a0a..7f3911e 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -15,11 +15,14 @@ import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_reproductor.* import org.libre.agosto.p2play.adapters.CommentariesAdapter 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 class ReproductorActivity : AppCompatActivity() { lateinit var video:VideoModel private val _actions: Actions = Actions() + private val client: Comments = Comments() // Commentaries adapter values private lateinit var recyclerView: RecyclerView @@ -39,30 +42,6 @@ class ReproductorActivity : AppCompatActivity() { videoView.settings.allowUniversalAccessFromFileURLs = true videoView.settings.domStorageEnabled = true - try { - - viewManager = LinearLayoutManager(this) - - // Set data for RecyclerView - viewAdapter = CommentariesAdapter(arrayListOf()) - - recyclerView = findViewById(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 { this.video = this.intent.extras.getSerializable("video") as VideoModel tittleVideoTxt.text = this.video.name @@ -73,13 +52,19 @@ class ReproductorActivity : AppCompatActivity() { if(this.video.userImageUrl!="") Picasso.get().load("https://"+ManagerSingleton.url+this.video.userImageUrl).into(userImg) videoView.loadUrl("https://"+ManagerSingleton.url+this.video.embedUrl) - Log.d("url", videoView.url) + + } catch (err:Exception){ err.printStackTrace() Log.d("Error", err?.message) } + viewManager = LinearLayoutManager(this) + this.setDataComments(arrayListOf()) + + this.getComments() + subscribeBtn.setOnClickListener { subscribe() } likeLayout.setOnClickListener { rate("like") } dislikeLayout.setOnClickListener { rate("dislike") } @@ -183,6 +168,32 @@ class ReproductorActivity : AppCompatActivity() { } } + private fun setDataComments(data: ArrayList) { + // Set data for RecyclerView + viewAdapter = CommentariesAdapter(data) + + recyclerView = findViewById(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() { super.onResume() if(ManagerSingleton.user.status == 1) { diff --git a/app/src/main/java/org/libre/agosto/p2play/adapters/CommentariesAdapter.kt b/app/src/main/java/org/libre/agosto/p2play/adapters/CommentariesAdapter.kt index 0df1b35..7053460 100644 --- a/app/src/main/java/org/libre/agosto/p2play/adapters/CommentariesAdapter.kt +++ b/app/src/main/java/org/libre/agosto/p2play/adapters/CommentariesAdapter.kt @@ -48,7 +48,7 @@ class CommentariesAdapter(private val myDataset: ArrayList) : viewType: Int): CommentariesAdapter.ViewHolder { // create a new view 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 return ViewHolder(view) } diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index 29361e9..b32611d 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -231,6 +231,7 @@ android:id="@+id/listCommentaries" android:layout_width="match_parent" android:layout_height="wrap_content" + android:scrollbars="none" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/view_commentary.xml b/app/src/main/res/layout/view_commentary.xml index 7f42519..37c9051 100644 --- a/app/src/main/res/layout/view_commentary.xml +++ b/app/src/main/res/layout/view_commentary.xml @@ -1,16 +1,17 @@ - + android:layout_height="wrap_content"> + android:paddingRight="10dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toTopOf="parent">