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 4370d7f..575ea1d 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -2,6 +2,7 @@ package org.libre.agosto.p2play import android.annotation.SuppressLint import android.app.Activity +import android.content.DialogInterface import android.content.Intent import android.content.pm.ActivityInfo import android.graphics.Bitmap @@ -11,12 +12,14 @@ import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.os.Looper import android.support.v4.content.ContextCompat +import android.support.v7.app.AlertDialog import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.util.Log import android.view.View import android.view.WindowManager import android.webkit.WebChromeClient +import android.widget.EditText import android.widget.FrameLayout import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.activity_reproductor.* @@ -57,7 +60,7 @@ class ReproductorActivity : AppCompatActivity() { videoView.settings.domStorageEnabled = true try { - this.video = this.intent.extras.getSerializable("video") as VideoModel + this.video = this.intent.extras.getSerializable("video") as VideoModel tittleVideoTxt.text = this.video.name viewsTxt.text = "${this.video.views} ${getString(R.string.view_text)}" userTxt.text = this.video.username @@ -69,13 +72,12 @@ class ReproductorActivity : AppCompatActivity() { hostTxt.text = this.video.userHost // Check if user had profile image - if(this.video.userImageUrl!="") - Picasso.get().load("https://"+ManagerSingleton.url+this.video.userImageUrl).into(userImg) + if (this.video.userImageUrl != "") + Picasso.get().load("https://" + ManagerSingleton.url + this.video.userImageUrl).into(userImg) // Load the video - videoView.loadUrl("https://"+ManagerSingleton.url+this.video.embedUrl) + videoView.loadUrl("https://" + ManagerSingleton.url + this.video.embedUrl) - } - catch (err:Exception){ + } catch (err: Exception) { err.printStackTrace() } @@ -89,6 +91,8 @@ class ReproductorActivity : AppCompatActivity() { dislikeLayout.setOnClickListener { rate("dislike") } commentaryBtn.setOnClickListener { makeComment() } showMoreBtn.setOnClickListener { getDescription() } + shareLayout.setOnClickListener { shareIntent() } + reportLayout.setOnClickListener { reportIntent() } userImg.setOnClickListener { val intent = Intent(this, ChannelActivity::class.java) @@ -97,7 +101,7 @@ class ReproductorActivity : AppCompatActivity() { } } - private fun subscribe(){ + private fun subscribe() { AsyncTask.execute { if (Looper.myLooper() == null) Looper.prepare() @@ -111,7 +115,7 @@ class ReproductorActivity : AppCompatActivity() { } } - private fun unSubscribe(){ + private fun unSubscribe() { AsyncTask.execute { if (Looper.myLooper() == null) Looper.prepare() @@ -125,7 +129,7 @@ class ReproductorActivity : AppCompatActivity() { } } - private fun rate(rate: String){ + private fun rate(rate: String) { AsyncTask.execute { if (Looper.myLooper() == null) Looper.prepare() @@ -133,11 +137,10 @@ class ReproductorActivity : AppCompatActivity() { if (res == 1) { runOnUiThread { ManagerSingleton.Toast(getString(R.string.rateMsg), this) - if(rate=="like"){ + if (rate == "like") { textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) - } - else if(rate=="dislike"){ + } else if (rate == "dislike") { textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.colorDislike)) textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) } @@ -146,13 +149,13 @@ class ReproductorActivity : AppCompatActivity() { } } - private fun getRate(){ + private fun getRate() { AsyncTask.execute { if (Looper.myLooper() == null) Looper.prepare() val rate = this._actions.getRate(ManagerSingleton.token.token, this.video.id) runOnUiThread { - when (rate){ + when (rate) { "like" -> { textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) @@ -170,8 +173,8 @@ class ReproductorActivity : AppCompatActivity() { } } - private fun getSubscription(){ - val account = this.video.nameChannel+"@"+this.video.userHost + private fun getSubscription() { + val account = this.video.nameChannel + "@" + this.video.userHost AsyncTask.execute { if (Looper.myLooper() == null) Looper.prepare() @@ -182,12 +185,11 @@ class ReproductorActivity : AppCompatActivity() { } } - private fun changeSubscribeBtn(subscribed: Boolean){ - if(subscribed){ + private fun changeSubscribeBtn(subscribed: Boolean) { + if (subscribed) { subscribeBtn.text = getText(R.string.unSubscribeBtn) subscribeBtn.setOnClickListener { this.unSubscribe() } - } - else{ + } else { subscribeBtn.text = getText(R.string.subscribeBtn) subscribeBtn.setOnClickListener { this.subscribe() } } @@ -220,7 +222,7 @@ class ReproductorActivity : AppCompatActivity() { } private fun makeComment() { - if(commentaryText.text.toString() == ""){ + if (commentaryText.text.toString() == "") { ManagerSingleton.Toast(getString(R.string.emptyCommentaryMsg), this) return } @@ -232,8 +234,7 @@ class ReproductorActivity : AppCompatActivity() { ManagerSingleton.Toast(getString(R.string.makedCommentaryMsg), this) commentaryText.text.clear() this.getComments() - } - else { + } else { ManagerSingleton.Toast(getString(R.string.errorCommentaryMsg), this) } } @@ -242,19 +243,19 @@ class ReproductorActivity : AppCompatActivity() { override fun onResume() { super.onResume() - if(ManagerSingleton.user.status == 1) { + if (ManagerSingleton.user.status == 1) { this.getRate() 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) + if (ManagerSingleton.user.avatar != "") { + Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(userImgCom) } } } - fun getDescription(){ + fun getDescription() { AsyncTask.execute { val fullDescription = this.videos.fullDescription(this.video.id) runOnUiThread { @@ -264,6 +265,52 @@ class ReproductorActivity : AppCompatActivity() { } } + private fun shareIntent() { + val sendIntent: Intent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_TEXT, "${video.name} ${video.getVideoUrl()}") + type = "text/plain" + } + startActivity(Intent.createChooser(sendIntent, resources.getText(R.string.shareBtn))) + } + + private fun reportIntent() { + val builder = AlertDialog.Builder(this) + // Get the layout inflater + val dialog = layoutInflater.inflate(R.layout.report_dialog, null) + + val inputReason = dialog.findViewById(R.id.reportText) + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + builder.setView(dialog) + // Add action buttons + .setPositiveButton(R.string.reportBtn) { dialog, id -> + val reason = inputReason.text.toString() + reportVideo(reason) + } + .setNegativeButton("Cancel") { dialog, id -> + dialog.cancel() + } + val alertDialog = builder.create() + alertDialog.show() + } + + private fun reportVideo(reason: String){ + AsyncTask.execute { + val res = _actions.reportVideo(video.id, reason, ManagerSingleton.token.token) + + runOnUiThread { + if(res) { + ManagerSingleton.Toast(getText(R.string.reportDialogMsg).toString(), this) + } + else { + ManagerSingleton.Toast(getText(R.string.errorMsg).toString(), this) + } + } + } + } + internal inner class WebClient: WebChromeClient() { private var mCustomView: View? = null private var mCustomViewCallback: WebChromeClient.CustomViewCallback? = null 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 7fb0929..47a0b47 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 @@ -127,4 +127,21 @@ class Actions: Client() { return rating } + fun reportVideo(videoId: Int, reason: String, token: String): Boolean { + val con = this._newCon("videos/$videoId/abuse", "POST", token) + val params = "reason=$reason" + con.outputStream.write(params.toByteArray()) + + var response = false + try { + if(con.responseCode == 200){ + response = true + } + } catch (err: Exception) { + err.printStackTrace() + response = false + } + + return response + } } \ No newline at end of file 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 963d2f2..6059a94 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 @@ -6,6 +6,7 @@ import java.io.Serializable class VideoModel( var id: Int = 0, + var uuid: String = "", var name: String = "", var description: String = "", var thumbUrl: String = "", @@ -22,12 +23,17 @@ class VideoModel( return "$nameChannel@$userHost" } + fun getVideoUrl(): String { + return "https://$userHost/videos/watch/$uuid" + } + fun parseVideo(data: JsonReader){ data.beginObject() while (data.hasNext()){ val key = data.nextName() when (key.toString()) { "id"-> this.id = data.nextInt() + "uuid" -> this.uuid = data.nextString() "name"->{ this.name= data.nextString() } diff --git a/app/src/main/res/drawable/ic_alert.xml b/app/src/main/res/drawable/ic_alert.xml new file mode 100644 index 0000000..8ef6143 --- /dev/null +++ b/app/src/main/res/drawable/ic_alert.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_share.xml b/app/src/main/res/drawable/ic_share.xml new file mode 100644 index 0000000..e8ba475 --- /dev/null +++ b/app/src/main/res/drawable/ic_share.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index b1195f6..55a9d13 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -124,21 +124,61 @@ android:textAlignment="center" /> -