Adapter and model of commentaries maked

This commit is contained in:
ivan agosto 2019-01-24 15:56:20 -06:00
parent 6413bb078d
commit 9bf8ea0483
6 changed files with 188 additions and 18 deletions

View File

@ -27,11 +27,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: RecyclerView.Adapter<*>
private lateinit var viewManager: RecyclerView.LayoutManager
val client: Videos = Videos()
private val client: Videos = Videos()
private lateinit var lastItem: MenuItem
private lateinit var subItem: MenuItem
lateinit var myMenu: Menu
val _db = Database(this)
private val _db = Database(this)
var section: String = ""
@ -67,7 +67,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Generic function for set data to RecyclerView
fun setData(data:ArrayList<VideoModel>){
private fun setData(data:ArrayList<VideoModel>){
viewAdapter = VideosAdapter(data)
recyclerView = findViewById<RecyclerView>(R.id.list).apply {
@ -84,7 +84,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
swipeContainer.isRefreshing = false
}
fun refresh(){
private fun refresh(){
swipeContainer.isRefreshing = true
when(section){
"local" -> this.getLocalVideos()
@ -100,7 +100,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
fun getSubscriptionVideos(){
private fun getSubscriptionVideos(){
if(ManagerSingleton.user.status != 1){
ManagerSingleton.Toast("Inicia session primero")
startActivity(Intent(this, LoginActivity::class.java))
@ -118,7 +118,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Last videos
fun getLastVideos(){
private fun getLastVideos(){
swipeContainer.isRefreshing = true
section = "last"
setTitle(R.string.title_recent)
@ -130,8 +130,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
//
fun getPopularVideos(){
// Popular videos
private fun getPopularVideos(){
swipeContainer.isRefreshing = true
section = "popular"
setTitle(R.string.title_popular)
@ -143,7 +143,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
fun getLocalVideos(){
// Local videos
private fun getLocalVideos(){
swipeContainer.isRefreshing = true
section = "local"
setTitle(R.string.title_local)
@ -155,7 +156,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
fun getMyVideos(){
// Videos of user
private fun getMyVideos(){
swipeContainer.isRefreshing = true
section = "my_videos"
setTitle(R.string.title_myVideos)
@ -266,7 +268,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
fun logout(){
private fun logout(){
if(::myMenu.isInitialized){
myMenu.findItem(R.id.action_login).isVisible = true
myMenu.findItem(R.id.action_logout).isVisible = false

View File

@ -6,10 +6,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.widget.LinearLayoutManager
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
import org.libre.agosto.p2play.models.VideoModel
@ -17,6 +21,11 @@ class ReproductorActivity : AppCompatActivity() {
lateinit var video:VideoModel
private val _actions: Actions = Actions()
// Commentaries adapter values
private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: RecyclerView.Adapter<*>
private lateinit var viewManager: RecyclerView.LayoutManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_reproductor)
@ -30,6 +39,30 @@ class ReproductorActivity : AppCompatActivity() {
videoView.settings.allowUniversalAccessFromFileURLs = true
videoView.settings.domStorageEnabled = true
try {
viewManager = LinearLayoutManager(this)
// Set data for RecyclerView
viewAdapter = CommentariesAdapter(arrayListOf())
recyclerView = findViewById<RecyclerView>(R.id.listCommentaries).apply {
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
setHasFixedSize(true)
// use a linear layout manager
layoutManager = viewManager
// specify an viewAdapter (see also next example)
adapter = viewAdapter
}
}catch (err: Exception){
err.printStackTrace()
Log.d("Error", err?.message)
}
try {
this.video = this.intent.extras.getSerializable("video") as VideoModel
tittleVideoTxt.text = this.video.name
@ -47,13 +80,12 @@ class ReproductorActivity : AppCompatActivity() {
Log.d("Error", err?.message)
}
// subscribeBtn.setOnClickListener { ManagerSingleton.Toast(getString(R.string.comming)) }
subscribeBtn.setOnClickListener { subscribe() }
likeLayout.setOnClickListener { rate("like") }
dislikeLayout.setOnClickListener { rate("dislike") }
}
fun subscribe(){
private fun subscribe(){
val account = this.video.userUuid+"@"+this.video.userHost
AsyncTask.execute {
if (Looper.myLooper() == null)
@ -68,7 +100,7 @@ class ReproductorActivity : AppCompatActivity() {
}
}
fun unSubscribe(){
private fun unSubscribe(){
val account = this.video.userUuid+"@"+this.video.userHost
AsyncTask.execute {
if (Looper.myLooper() == null)
@ -83,7 +115,7 @@ class ReproductorActivity : AppCompatActivity() {
}
}
fun rate(rate: String){
private fun rate(rate: String){
AsyncTask.execute {
if (Looper.myLooper() == null)
Looper.prepare()
@ -104,7 +136,7 @@ class ReproductorActivity : AppCompatActivity() {
}
}
fun getRate(){
private fun getRate(){
AsyncTask.execute {
if (Looper.myLooper() == null)
Looper.prepare()
@ -128,7 +160,7 @@ class ReproductorActivity : AppCompatActivity() {
}
}
fun getSubscription(){
private fun getSubscription(){
val account = this.video.userUuid+"@"+this.video.userHost
AsyncTask.execute {
if (Looper.myLooper() == null)
@ -140,7 +172,7 @@ class ReproductorActivity : AppCompatActivity() {
}
}
fun changeSubscribeBtn(subscribed: Boolean){
private fun changeSubscribeBtn(subscribed: Boolean){
if(subscribed){
subscribeBtn.text = getText(R.string.unSubscribeBtn)
subscribeBtn.setOnClickListener { this.unSubscribe() }

View File

@ -0,0 +1,71 @@
package org.libre.agosto.p2play.adapters
import android.app.Activity
import android.content.Intent
import android.graphics.drawable.Drawable
import android.os.AsyncTask
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.squareup.picasso.Picasso
import org.libre.agosto.p2play.MainActivity
import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.R
import org.libre.agosto.p2play.ReproductorActivity
import org.libre.agosto.p2play.models.CommentaryModel
import org.libre.agosto.p2play.models.VideoModel
import java.io.InputStream
import java.io.Serializable
import java.net.URL
class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
RecyclerView.Adapter<CommentariesAdapter.ViewHolder>() {
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder.
// Each data item is just a string in this case that is shown in a TextView.
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view){
val userImg: ImageView
val username: TextView
val commentary: TextView
init {
// Define click listener for the ViewHolder's View
username = view.findViewById(R.id.userTxt)
commentary = view.findViewById(R.id.userCommentary)
userImg = view.findViewById(R.id.userCommentImg)
}
}
// Create new views (invoked by the layout manager)
override fun onCreateViewHolder(parent: ViewGroup,
viewType: Int): CommentariesAdapter.ViewHolder {
// create a new view
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.view_video, parent, false) as View
// set the view's size, margins, paddings and layout parameters
return ViewHolder(view)
}
// Replace the contents of a view (invoked by the layout manager)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
holder.username.text = myDataset[position].username
if(myDataset[position].userImageUrl!="")
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg);
holder.commentary.text = myDataset[position].commentary
}
// Return the size of your dataset (invoked by the layout manager)
override fun getItemCount() = myDataset.size
}

View File

@ -0,0 +1,9 @@
package org.libre.agosto.p2play.models
class CommentaryModel (
var id: Int = 0,
var uuid: Int = 0,
var username: String = "",
var userImageUrl: String = "",
var commentary: String = ""
)

View File

@ -227,6 +227,14 @@
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listCommentaries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:id="@+id/userCommentImg"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_weight="1"
android:contentDescription="@string/app_name"
app:srcCompat="@drawable/default_avatar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="@+id/userTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/darker_gray"
android:textStyle="italic" />
<TextView
android:id="@+id/userCommentary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:maxLength="1000"
android:maxLines="10" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>