From 176e580f1f47c19ac79e3b4b905a012f5d69224f Mon Sep 17 00:00:00 2001 From: ivan agosto Date: Fri, 25 Jan 2019 12:30:48 -0600 Subject: [PATCH] Make commentaries on videos --- .../agosto/p2play/ReproductorActivity.kt | 28 +++++++++++++++++-- .../org/libre/agosto/p2play/ajax/Comments.kt | 20 +++++++++++++ .../main/res/layout/activity_reproductor.xml | 15 ++++++---- app/src/main/res/values-es/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 9 ++++-- 5 files changed, 64 insertions(+), 11 deletions(-) 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 7f3911e..6828307 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -1,6 +1,5 @@ package org.libre.agosto.p2play -import android.opengl.Visibility import android.os.AsyncTask import android.support.v7.app.AppCompatActivity import android.os.Bundle @@ -11,7 +10,6 @@ import android.support.v7.widget.RecyclerView import android.util.Log import android.view.View import com.squareup.picasso.Picasso -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 @@ -68,6 +66,7 @@ class ReproductorActivity : AppCompatActivity() { subscribeBtn.setOnClickListener { subscribe() } likeLayout.setOnClickListener { rate("like") } dislikeLayout.setOnClickListener { rate("dislike") } + commentaryBtn.setOnClickListener { makeComment() } } private fun subscribe(){ @@ -194,6 +193,27 @@ class ReproductorActivity : AppCompatActivity() { } } + private fun makeComment() { + if(commentaryText.text.toString() == ""){ + ManagerSingleton.Toast(getString(R.string.emptyCommentaryMsg)) + return + } + val text = commentaryText.text.toString() + AsyncTask.execute { + val res = this.client.makeCommentary(ManagerSingleton.token.token, this.video.id, text) + runOnUiThread { + if (res) { + ManagerSingleton.Toast(getString(R.string.makedCommentaryMsg)) + commentaryText.text.clear() + this.getComments() + } + else { + ManagerSingleton.Toast(getString(R.string.errorCommentaryMsg)) + } + } + } + } + override fun onResume() { super.onResume() if(ManagerSingleton.user.status == 1) { @@ -201,6 +221,10 @@ class ReproductorActivity : AppCompatActivity() { this.getSubscription() actionsLayout.visibility = View.VISIBLE subscribeBtn.visibility = View.VISIBLE + commentaryLayout.visibility = View.VISIBLE + if(ManagerSingleton.user.avatar != ""){ + Picasso.get().load("https://"+ManagerSingleton.url+ManagerSingleton.user.avatar).into(userImgCom) + } } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Comments.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Comments.kt index 043357e..a909a60 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ajax/Comments.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Comments.kt @@ -89,4 +89,24 @@ class Comments: Client() { return commentaries } + fun makeCommentary(token: String, videoId: Int, text: String): Boolean { + val con = this._newCon("videos/$videoId/comment-threads", "POST", token) + val params:String= "text=$text" + con.outputStream.write(params.toByteArray()) + + try { + if (con.responseCode == 200) { + return true + } + else{ + Log.d("Status", con.responseMessage) + } + } + catch (err: Exception){ + err.printStackTrace() + } + + return false + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index b32611d..18af040 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -192,9 +192,11 @@ android:text="@string/commentariesTxt" /> + android:orientation="vertical" + android:visibility="visible"> @@ -212,14 +214,15 @@ android:id="@+id/commentaryText" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_weight="2" android:ems="10" android:inputType="textMultiLine" />