Channel view maked and working

This commit is contained in:
ivan agosto 2019-02-24 10:34:12 -06:00
parent 743c3147c1
commit 398265c6ed
10 changed files with 359 additions and 17 deletions

View File

@ -12,6 +12,8 @@
android:roundIcon="@mipmap/ic_p2play"
android:supportsRtl="true"
android:theme="@style/P2playTheme">
<activity android:name=".ChannelActivity"
android:theme="@style/P2playTheme.noBar"></activity>
<activity
android:name=".SplashActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
@ -27,9 +29,9 @@
android:theme="@style/P2playTheme.NoActionBar" />
<activity
android:name=".ReproductorActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true"
android:theme="@style/P2playTheme.noBar"
android:configChanges="orientation|screenSize"/>
android:theme="@style/P2playTheme.noBar" />
<activity android:name=".LoginActivity" />
<activity android:name=".RegisterActivity" />
<activity android:name=".AboutActivity" />

View File

@ -0,0 +1,149 @@
package org.libre.agosto.p2play
import android.os.AsyncTask
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.activity_channel.*
import org.libre.agosto.p2play.adapters.VideosAdapter
import org.libre.agosto.p2play.ajax.Actions
import org.libre.agosto.p2play.ajax.Channels
import org.libre.agosto.p2play.ajax.Videos
import org.libre.agosto.p2play.models.ChannelModel
import org.libre.agosto.p2play.models.VideoModel
class ChannelActivity : AppCompatActivity() {
private lateinit var channelId: String
private lateinit var channel: ChannelModel
private var isSubcribed: Boolean = false
private val _channel = Channels()
private val _videos = Videos()
private val _actions = Actions()
private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: RecyclerView.Adapter<VideosAdapter.ViewHolder>
private lateinit var viewManager: RecyclerView.LayoutManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_channel)
channelId = this.intent.extras.getString("channel")
viewManager = LinearLayoutManager(this)
subcriptionBtn.setOnClickListener {
subscribeAction()
}
}
override fun onResume() {
super.onResume()
getChannel()
getSubscription()
getVideos()
if(ManagerSingleton.user.status == 1) {
subcriptionBtn.visibility = View.VISIBLE
getSubscription()
}
}
private fun getChannel() {
AsyncTask.execute {
channel = _channel.getChannelInfo(channelId)
runOnUiThread {
usernameProfile.text = channel.name
hostTxt.text = channel.host
subcriptionsTxt.text = channel.followers.toString()
if(channel.channelImg != "")
Picasso.get().load("https://${ManagerSingleton.url}${channel.channelImg}").into(channelImg)
}
}
}
private fun subscribe() {
AsyncTask.execute {
val res = _actions.subscribe(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread {
if(res == 1){
subcriptionBtn.text = getString(R.string.unSubscribeBtn)
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this)
getSubscription()
}
else {
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
}
}
}
}
private fun unSubscribe() {
AsyncTask.execute {
val res = _actions.unSubscribe(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread {
if(res == 1){
subcriptionBtn.text = getString(R.string.subscribeBtn)
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this)
getSubscription()
}
else {
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
}
}
}
}
private fun subscribeAction() {
if(isSubcribed)
unSubscribe()
else
subscribe()
}
private fun getSubscription() {
AsyncTask.execute {
isSubcribed = _actions.getSubscription(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread {
if(isSubcribed){
subcriptionBtn.text = getText(R.string.unSubscribeBtn)
}
else {
subcriptionBtn.text = getText(R.string.subscribeBtn)
}
}
}
}
private fun getVideos() {
AsyncTask.execute {
val videos = _videos.channelVideos(channel.getAccount(), 0)
runOnUiThread {
initRecycler(videos)
}
}
}
// Generic function for set data to RecyclerView
private fun initRecycler(data: ArrayList<VideoModel>){
// val data = arrayListOf<VideoModel>()
viewAdapter = VideosAdapter(data)
recyclerView = findViewById<RecyclerView>(R.id.listVideosChannel).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
}
// swipeContainer.isRefreshing = false
}
}

View File

@ -2,6 +2,7 @@ package org.libre.agosto.p2play
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.graphics.BitmapFactory
@ -73,7 +74,6 @@ class ReproductorActivity : AppCompatActivity() {
// Load the video
videoView.loadUrl("https://"+ManagerSingleton.url+this.video.embedUrl)
}
catch (err:Exception){
err.printStackTrace()
@ -89,14 +89,19 @@ class ReproductorActivity : AppCompatActivity() {
dislikeLayout.setOnClickListener { rate("dislike") }
commentaryBtn.setOnClickListener { makeComment() }
showMoreBtn.setOnClickListener { getDescription() }
userImg.setOnClickListener {
val intent = Intent(this, ChannelActivity::class.java)
intent.putExtra("channel", video.getAccount())
startActivity(intent)
}
}
private fun subscribe(){
val account = this.video.nameChannel+"@"+this.video.userHost
AsyncTask.execute {
if (Looper.myLooper() == null)
Looper.prepare()
val res = this._actions.subscribe(ManagerSingleton.token.token, account)
val res = this._actions.subscribe(ManagerSingleton.token.token, video.getAccount())
if (res == 1) {
runOnUiThread {
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this)
@ -107,11 +112,10 @@ class ReproductorActivity : AppCompatActivity() {
}
private fun unSubscribe(){
val account = this.video.nameChannel+"@"+this.video.userHost
AsyncTask.execute {
if (Looper.myLooper() == null)
Looper.prepare()
val res = this._actions.unSubscribe(ManagerSingleton.token.token, account)
val res = this._actions.unSubscribe(ManagerSingleton.token.token, video.getAccount())
if (res == 1) {
runOnUiThread {
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this)

View File

@ -14,10 +14,7 @@ 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.*
import org.libre.agosto.p2play.models.CommentaryModel
import org.libre.agosto.p2play.models.VideoModel
import java.io.InputStream
@ -63,6 +60,12 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
// - replace the contents of the view with that element
holder.username.text = myDataset[position].username
// holder.userImg.setOnClickListener {
// val intent = Intent(holder.context, ChannelActivity::class.java)
// intent.putExtra("channel", myDataset[position])
// holder.context.startActivity(intent)
// }
if(myDataset[position].userImageUrl!="")
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg);

View File

@ -13,10 +13,7 @@ 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.*
import org.libre.agosto.p2play.models.VideoModel
import java.io.InputStream
import java.io.Serializable
@ -69,6 +66,13 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
intent.putExtra("video", myDataset[position] as Serializable)
holder.context.startActivity(intent)
}
holder.userImg.setOnClickListener {
val intent = Intent(holder.context, ChannelActivity::class.java)
intent.putExtra("channel", myDataset[position].getAccount())
holder.context.startActivity(intent)
}
if(myDataset[position].userImageUrl!="")
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg)
else

View File

@ -16,8 +16,8 @@ class Channels: Client() {
return channel
}
fun getChannelInfo(channelId: String): ChannelModel {
val con = this._newCon("video-channels/$channelId", "GET")
fun getChannelInfo(account: String): ChannelModel {
val con = this._newCon("video-channels/$account", "GET")
var channel = ChannelModel()
try {
if(con.responseCode == 200){

View File

@ -5,6 +5,7 @@ import android.util.Log
import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.models.HostModel
import java.io.InputStreamReader
import java.io.Reader
import java.net.HttpURLConnection
import java.net.URL

View File

@ -154,4 +154,24 @@ class Videos: Client() {
con.disconnect()
return description
}
fun channelVideos(account: String, start: Int): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_count
val params = "start=$start&count=$count"
val con = this._newCon("video-channels/$account/videos","GET")
var videos = arrayListOf<VideoModel>()
try {
if (con.responseCode == 200) {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
videos = parseVideos(data)
data.close()
}
} catch(err:Exception){
err.printStackTrace()
}
con.disconnect()
return videos
}
}

View File

@ -0,0 +1,154 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".ChannelActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorProfile"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@+id/channelImg"
android:layout_width="match_parent"
android:layout_height="70dp"
android:adjustViewBounds="false"
android:background="@android:color/transparent"
android:contentDescription="@string/app_name"
android:cropToPadding="false"
android:scaleType="fitCenter"
app:srcCompat="@drawable/default_avatar" />
<TextView
android:id="@+id/usernameProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/followersIndicator"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/subcriptionsTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textStart"
android:textColor="@android:color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/hostIndicator"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/hostTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textStart"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/subcriptionBtn"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subscribeBtn"
android:textAlignment="center"
android:visibility="invisible" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
app:layout_constraintTop_toBottomOf="@+id/linearLayout2"
tools:layout_editor_absoluteX="0dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Videos:"
android:textStyle="bold"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="214dp" />
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listVideosChannel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>

View File

@ -107,5 +107,10 @@
<string name="pref_message_exit">Restart app to apply changes</string>
<string name="pref_videos_count_title">Videos per page</string>
<!-- End Settings strings -->
<!-- Start Channel strings -->
<string name="followersIndicator">Followers:</string>
<string name="hostIndicator">Host:</string>
<!-- End Channel strings -->
</resources>