diff --git a/app/app.iml b/app/app.iml
index 65d65c4..dbaee1e 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -131,7 +131,6 @@
-
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a81cc54..0fd316f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,7 +11,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_p2play"
android:supportsRtl="true"
- android:theme="@style/P2playTheme">
+ android:theme="@style/P2playTheme"
+ android:hardwareAccelerated="true">
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 60ab82c..1877e22 100644
--- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt
+++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt
@@ -62,6 +62,22 @@ class ReproductorActivity : AppCompatActivity() {
if (res == 1) {
runOnUiThread {
ManagerSingleton.Toast(getString(R.string.subscribeMsg))
+ this.changeSubscribeBtn(true)
+ }
+ }
+ }
+ }
+
+ fun unSubscribe(){
+ val account = this.video.userUuid+"@"+this.video.userHost
+ AsyncTask.execute {
+ if (Looper.myLooper() == null)
+ Looper.prepare()
+ val res = this._actions.unSubscribe(ManagerSingleton.token.token, account)
+ if (res == 1) {
+ runOnUiThread {
+ ManagerSingleton.Toast(getString(R.string.unSubscribeMsg))
+ this.changeSubscribeBtn(false)
}
}
}
@@ -88,9 +104,58 @@ class ReproductorActivity : AppCompatActivity() {
}
}
+ fun getRate(){
+ AsyncTask.execute {
+ if (Looper.myLooper() == null)
+ Looper.prepare()
+ val rate = this._actions.getRate(ManagerSingleton.token.token, this.video.id)
+ runOnUiThread {
+ when (rate){
+ "like" -> {
+ likeLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.colorLike))
+ dislikeLayout.background = null
+ }
+ "dislike" -> {
+ dislikeLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.colorDislike))
+ likeLayout.background = null
+ }
+ else -> {
+ likeLayout.background = null
+ dislikeLayout.background = null
+ }
+ }
+ }
+ }
+ }
+
+ fun getSubscription(){
+ val account = this.video.userUuid+"@"+this.video.userHost
+ AsyncTask.execute {
+ if (Looper.myLooper() == null)
+ Looper.prepare()
+ val isSubscribed = this._actions.getSubscription(ManagerSingleton.token.token, account)
+ runOnUiThread {
+ this.changeSubscribeBtn(isSubscribed)
+ }
+ }
+ }
+
+ fun changeSubscribeBtn(subscribed: Boolean){
+ if(subscribed){
+ subscribeBtn.text = getText(R.string.unSubscribeBtn)
+ subscribeBtn.setOnClickListener { this.unSubscribe() }
+ }
+ else{
+ subscribeBtn.text = getText(R.string.subscribeBtn)
+ subscribeBtn.setOnClickListener { this.subscribe() }
+ }
+ }
+
override fun onResume() {
super.onResume()
if(ManagerSingleton.user.status == 1) {
+ this.getRate()
+ this.getSubscription()
actionsLayout.visibility = View.VISIBLE
subscribeBtn.visibility = View.VISIBLE
}
diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt
index f2b1bb4..93b81da 100644
--- a/app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt
+++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Actions.kt
@@ -1,5 +1,8 @@
package org.libre.agosto.p2play.ajax
+import android.util.JsonReader
+import java.io.InputStreamReader
+
class Actions: Client() {
fun subscribe(token: String, account: String):Int{
@@ -21,6 +24,53 @@ class Actions: Client() {
return response
}
+ fun unSubscribe(token: String, account: String):Int{
+ var con=this._newCon("users/me/subscriptions/$account","DELETE", token)
+ var response = 0
+
+ try {
+ if (con.responseCode == 204) {
+ response = 1
+ }
+ }
+ catch (err: Exception){
+ err.printStackTrace()
+ response = -1
+ }
+
+ return response
+ }
+
+ fun getSubscription(token: String, account: String): Boolean{
+ var con=this._newCon("users/me/subscriptions/exist?uris=$account","GET", token)
+ var isSubscribed = false
+
+ try {
+ if (con.responseCode == 200) {
+ var response = InputStreamReader(con.inputStream)
+ var data = JsonReader(response)
+ data.beginObject()
+ while (data.hasNext()){
+ val key = data.nextName()
+ when (key.toString()) {
+ account->{
+ isSubscribed = data.nextBoolean()
+ }
+ else->{
+ data.skipValue()
+ }
+ }
+ }
+ }
+ }
+ catch (err: Exception){
+ err.printStackTrace()
+ isSubscribed = false
+ }
+
+ return isSubscribed
+ }
+
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"
@@ -39,4 +89,35 @@ class Actions: Client() {
return response
}
+
+ fun getRate(token: String, id_video: Int):String{
+ var con=this._newCon("users/me/videos/$id_video/rating","GET", token)
+ var rating = "none"
+
+ try {
+ if (con.responseCode == 200) {
+ var response = InputStreamReader(con.inputStream)
+ var data = JsonReader(response)
+ data.beginObject()
+ while (data.hasNext()){
+ val key = data.nextName()
+ when (key.toString()) {
+ "rating"->{
+ rating = data.nextString()
+ }
+ else->{
+ data.skipValue()
+ }
+ }
+ }
+ }
+ }
+ catch (err: Exception){
+ err.printStackTrace()
+ rating = "none"
+ }
+
+ return rating
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/res/values/reproductorActivity.xml b/app/src/main/res/values/reproductorActivity.xml
index 357404c..bf2b5be 100644
--- a/app/src/main/res/values/reproductorActivity.xml
+++ b/app/src/main/res/values/reproductorActivity.xml
@@ -9,8 +9,11 @@
Share
Report
+ Unsubscribe
+
You are subscribed to this channel
You are rated the video
+ You are unsubscribed to this channel
\ No newline at end of file