diff --git a/app/app.iml b/app/app.iml index 233e049..65d65c4 100644 --- a/app/app.iml +++ b/app/app.iml @@ -126,6 +126,7 @@ + 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 042e0ea..60ab82c 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -1,18 +1,21 @@ package org.libre.agosto.p2play +import android.opengl.Visibility import android.os.AsyncTask import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.os.Looper +import android.support.v4.content.ContextCompat import android.util.Log +import android.view.View import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.activity_reproductor.* -import org.libre.agosto.p2play.ajax.Subscriptions +import org.libre.agosto.p2play.ajax.Actions import org.libre.agosto.p2play.models.VideoModel class ReproductorActivity : AppCompatActivity() { lateinit var video:VideoModel - private val _subsciption: Subscriptions = Subscriptions() + private val _actions: Actions = Actions() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -46,6 +49,8 @@ class ReproductorActivity : AppCompatActivity() { // subscribeBtn.setOnClickListener { ManagerSingleton.Toast(getString(R.string.comming)) } subscribeBtn.setOnClickListener { subscribe() } + likeLayout.setOnClickListener { rate("like") } + dislikeLayout.setOnClickListener { rate("dislike") } } fun subscribe(){ @@ -53,7 +58,7 @@ class ReproductorActivity : AppCompatActivity() { AsyncTask.execute { if (Looper.myLooper() == null) Looper.prepare() - val res = this._subsciption.subscribe(ManagerSingleton.token.token, account) + val res = this._actions.subscribe(ManagerSingleton.token.token, account) if (res == 1) { runOnUiThread { ManagerSingleton.Toast(getString(R.string.subscribeMsg)) @@ -61,4 +66,33 @@ class ReproductorActivity : AppCompatActivity() { } } } + + fun rate(rate: String){ + AsyncTask.execute { + if (Looper.myLooper() == null) + Looper.prepare() + val res = this._actions.rate(ManagerSingleton.token.token, this.video.id, rate) + if (res == 1) { + runOnUiThread { + ManagerSingleton.Toast(getString(R.string.rateMsg)) + if(rate=="like"){ + likeLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.colorLike)) + dislikeLayout.background = null + } + else if(rate=="dislike"){ + dislikeLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.colorDislike)) + likeLayout.background = null + } + } + } + } + } + + override fun onResume() { + super.onResume() + if(ManagerSingleton.user.status == 1) { + actionsLayout.visibility = View.VISIBLE + subscribeBtn.visibility = View.VISIBLE + } + } } diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Subscriptions.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt similarity index 50% rename from app/src/main/java/org/libre/agosto/p2play/ajax/Subscriptions.kt rename to app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt index b0f0cc5..f2b1bb4 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ajax/Subscriptions.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt @@ -1,6 +1,6 @@ package org.libre.agosto.p2play.ajax -class Subscriptions: Client() { +class Actions: Client() { fun subscribe(token: String, account: String):Int{ var con=this._newCon("users/me/subscriptions","POST", token) @@ -20,4 +20,23 @@ class Subscriptions: Client() { return response } + + fun rate(token: String, id_video: Int, rate: String):Int{ + var con=this._newCon("videos/$id_video/rate","PUT", token) + val params:String= "rating=$rate" + con.outputStream.write(params.toByteArray()) + var response = 0 + + try { + if (con.responseCode == 204) { + response = 1 + } + } + catch (err: Exception){ + err.printStackTrace() + response = -1 + } + + return response + } } \ No newline at end of file diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt index 7f11381..1444323 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt @@ -21,6 +21,7 @@ class Videos: Client() { while (data.hasNext()){ val key = data.nextName() when (key.toString()) { + "id"-> video.id = data.nextInt() "name"->{ video.name= data.nextString() } diff --git a/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt b/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt index f7abe52..22f7333 100644 --- a/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt +++ b/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt @@ -3,6 +3,7 @@ package org.libre.agosto.p2play.models import java.io.Serializable class VideoModel( + var id: Int = 0, var name: String = "", var description: String = "", var thumbUrl: String = "", diff --git a/app/src/main/res/drawable/ic_dislike.xml b/app/src/main/res/drawable/ic_dislike.xml new file mode 100644 index 0000000..af897f3 --- /dev/null +++ b/app/src/main/res/drawable/ic_dislike.xml @@ -0,0 +1,21 @@ + + + + diff --git a/app/src/main/res/drawable/ic_like.xml b/app/src/main/res/drawable/ic_like.xml new file mode 100644 index 0000000..f1ad7c0 --- /dev/null +++ b/app/src/main/res/drawable/ic_like.xml @@ -0,0 +1,21 @@ + + + + diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index 427aa4f..3eeb428 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -45,38 +45,78 @@ android:textSize="12sp" /> -