Rate video actions

This commit is contained in:
ivan agosto
2018-10-10 12:24:35 -05:00
parent df04a0b9d9
commit a92064552e
10 changed files with 165 additions and 20 deletions

View File

@@ -126,6 +126,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_main_apk_resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_merged_manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_merged_manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" />

View File

@@ -1,18 +1,21 @@
package org.libre.agosto.p2play package org.libre.agosto.p2play
import android.opengl.Visibility
import android.os.AsyncTask import android.os.AsyncTask
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.Looper import android.os.Looper
import android.support.v4.content.ContextCompat
import android.util.Log import android.util.Log
import android.view.View
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.activity_reproductor.* 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 import org.libre.agosto.p2play.models.VideoModel
class ReproductorActivity : AppCompatActivity() { class ReproductorActivity : AppCompatActivity() {
lateinit var video:VideoModel lateinit var video:VideoModel
private val _subsciption: Subscriptions = Subscriptions() private val _actions: Actions = Actions()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -46,6 +49,8 @@ class ReproductorActivity : AppCompatActivity() {
// subscribeBtn.setOnClickListener { ManagerSingleton.Toast(getString(R.string.comming)) } // subscribeBtn.setOnClickListener { ManagerSingleton.Toast(getString(R.string.comming)) }
subscribeBtn.setOnClickListener { subscribe() } subscribeBtn.setOnClickListener { subscribe() }
likeLayout.setOnClickListener { rate("like") }
dislikeLayout.setOnClickListener { rate("dislike") }
} }
fun subscribe(){ fun subscribe(){
@@ -53,7 +58,7 @@ class ReproductorActivity : AppCompatActivity() {
AsyncTask.execute { AsyncTask.execute {
if (Looper.myLooper() == null) if (Looper.myLooper() == null)
Looper.prepare() Looper.prepare()
val res = this._subsciption.subscribe(ManagerSingleton.token.token, account) val res = this._actions.subscribe(ManagerSingleton.token.token, account)
if (res == 1) { if (res == 1) {
runOnUiThread { runOnUiThread {
ManagerSingleton.Toast(getString(R.string.subscribeMsg)) 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
}
}
} }

View File

@@ -1,6 +1,6 @@
package org.libre.agosto.p2play.ajax package org.libre.agosto.p2play.ajax
class Subscriptions: Client() { class Actions: Client() {
fun subscribe(token: String, account: String):Int{ fun subscribe(token: String, account: String):Int{
var con=this._newCon("users/me/subscriptions","POST", token) var con=this._newCon("users/me/subscriptions","POST", token)
@@ -20,4 +20,23 @@ class Subscriptions: Client() {
return response 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
}
} }

View File

@@ -21,6 +21,7 @@ class Videos: Client() {
while (data.hasNext()){ while (data.hasNext()){
val key = data.nextName() val key = data.nextName()
when (key.toString()) { when (key.toString()) {
"id"-> video.id = data.nextInt()
"name"->{ "name"->{
video.name= data.nextString() video.name= data.nextString()
} }

View File

@@ -3,6 +3,7 @@ package org.libre.agosto.p2play.models
import java.io.Serializable import java.io.Serializable
class VideoModel( class VideoModel(
var id: Int = 0,
var name: String = "", var name: String = "",
var description: String = "", var description: String = "",
var thumbUrl: String = "", var thumbUrl: String = "",

View File

@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M6,10C6,7.5 6.5,5 8,5L16.9938,5C17.5495,5 18.182,5.4044 18.4073,5.9051L20.8563,11.3473C21.7641,13.3646 20.7155,15 18.5093,15L15.5,15C15.5,15 18.5,21 15,21C12.5,21 11.5,15 8,15C6.5,15 6,12.5 6,10Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#585858"
android:fillType="evenOdd"
android:strokeLineCap="round"/>
<path
android:pathData="M4,15.5C4,15.5 3,13 3,10C3,7 4,4.5 4,4.5"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#585858"
android:fillType="evenOdd"
android:strokeLineCap="round"/>
</vector>

View File

@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M6,14C6,16.5 6.5,19 8,19L16.9938,19C17.5495,19 18.182,18.5956 18.4073,18.0949L20.8563,12.6527C21.7641,10.6354 20.7155,9 18.5093,9L15.5,9C15.5,9 18.5,3 15,3C12.5,3 11.5,9 8,9C6.5,9 6,11.5 6,14Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#585858"
android:fillType="evenOdd"
android:strokeLineCap="round"/>
<path
android:pathData="M4,8.5C4,8.5 3,11 3,14C3,17 4,19.5 4,19.5"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#585858"
android:fillType="evenOdd"
android:strokeLineCap="round"/>
</vector>

View File

@@ -45,38 +45,78 @@
android:textSize="12sp" /> android:textSize="12sp" />
<LinearLayout <LinearLayout
android:id="@+id/actionsLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="40dp"
android:gravity="top"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone"> android:visibility="gone">
<Button <LinearLayout
android:id="@+id/button2" android:id="@+id/likeLayout"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/likeBtn" /> android:orientation="vertical">
<Button <ImageView
android:id="@+id/button5" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/dislikeBtn" /> android:adjustViewBounds="false"
android:cropToPadding="false"
app:srcCompat="@drawable/ic_like" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/likeBtn"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:id="@+id/dislikeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:adjustViewBounds="false"
android:cropToPadding="false"
app:srcCompat="@drawable/ic_dislike" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dislikeBtn"
android:textAlignment="center" />
</LinearLayout>
<Button <Button
android:id="@+id/button4" android:id="@+id/button4"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/shareBtn" /> android:text="@string/shareBtn"
android:visibility="gone" />
<Button <Button
android:id="@+id/button3" android:id="@+id/button3"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/reportBtn" /> android:text="@string/reportBtn"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@@ -111,7 +151,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/subscribeBtn" /> android:text="@string/subscribeBtn"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
<TextView <TextView

View File

@@ -7,4 +7,6 @@
<color name="colorBody">#fff</color> <color name="colorBody">#fff</color>
<color name="colorMenu">#000</color> <color name="colorMenu">#000</color>
<color name="colorBlack">#000</color> <color name="colorBlack">#000</color>
<color name="colorLike">#FF3C9100</color>
<color name="colorDislike">#ec020e</color>
</resources> </resources>

View File

@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="descriptionTxt">Description:</string> <string name="descriptionTxt">Description:</string>
<!-- Actions -->
<string name="subscribeBtn">Subscribe</string>
<string name="likeBtn">Like</string> <string name="likeBtn">Like</string>
<string name="dislikeBtn">Dislike</string> <string name="dislikeBtn">Dislike</string>
<string name="shareBtn">Share</string> <string name="shareBtn">Share</string>
<string name="reportBtn">Report</string> <string name="reportBtn">Report</string>
<!-- Subscriptions --> <!-- Messages -->
<string name="subscribeBtn">Subscribe</string>
<string name="subscribeMsg">You are subscribed to this channel</string> <string name="subscribeMsg">You are subscribed to this channel</string>
<string name="rateMsg">You are rated the video</string>
</resources> </resources>