mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
subscription
This commit is contained in:
parent
55272b615d
commit
9c7b0e6b1d
@ -129,10 +129,10 @@ class MainActivity : AppCompatActivity() {
|
||||
val orientation = newConfig.orientation
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
println("Portrait")
|
||||
unsetFullscreen()
|
||||
//unsetFullscreen()
|
||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
println("Landscape")
|
||||
setFullscreen()
|
||||
//setFullscreen()
|
||||
}
|
||||
}
|
||||
private fun setFullscreen() {
|
||||
|
@ -8,28 +8,26 @@ import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.*
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.adapters.SubscriptionAdapter
|
||||
import com.github.libretube.adapters.SubscriptionChannelAdapter
|
||||
import com.github.libretube.adapters.TrendingAdapter
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private const val ARG_PARAM1 = "param1"
|
||||
private const val ARG_PARAM2 = "param2"
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* Use the [Subscriptions.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class Subscriptions : Fragment() {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
|
||||
val TAG = "SubFragment"
|
||||
lateinit var token: String
|
||||
var isLoaded = false
|
||||
private var subscriptionAdapter: SubscriptionAdapter? =null
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
param1 = it.getString(ARG_PARAM1)
|
||||
param2 = it.getString(ARG_PARAM2)
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,27 +42,86 @@ class Subscriptions : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
Log.e("dafaq",sharedPref?.getString("token","")!!)
|
||||
token = sharedPref?.getString("token","")!!
|
||||
Log.e(TAG,token)
|
||||
if(token!=""){
|
||||
view.findViewById<RelativeLayout>(R.id.loginOrRegister).visibility=View.GONE
|
||||
var progressBar = view.findViewById<ProgressBar>(R.id.sub_progress)
|
||||
progressBar.visibility=View.VISIBLE
|
||||
|
||||
var channelRecView = view.findViewById<RecyclerView>(R.id.sub_channels)
|
||||
channelRecView?.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
fetchChannels(channelRecView)
|
||||
|
||||
var feedRecView = view.findViewById<RecyclerView>(R.id.sub_feed)
|
||||
feedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
|
||||
fetchFeed(feedRecView, progressBar)
|
||||
|
||||
val scrollView = view.findViewById<ScrollView>(R.id.scrollview_sub)
|
||||
scrollView.viewTreeObserver
|
||||
.addOnScrollChangedListener {
|
||||
if (scrollView.getChildAt(0).bottom
|
||||
== (scrollView.height + scrollView.scrollY)) {
|
||||
//scroll view is at bottom
|
||||
if(isLoaded){
|
||||
subscriptionAdapter?.updateItems()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment Subscriptions.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
@JvmStatic
|
||||
fun newInstance(param1: String, param2: String) =
|
||||
Subscriptions().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_PARAM1, param1)
|
||||
putString(ARG_PARAM2, param2)
|
||||
private fun fetchFeed(feedRecView: RecyclerView, progressBar: ProgressBar) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getFeed(token)
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
subscriptionAdapter = SubscriptionAdapter(response)
|
||||
feedRecView?.adapter= subscriptionAdapter
|
||||
progressBar.visibility=View.GONE
|
||||
isLoaded=true
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun fetchChannels(channelRecView: RecyclerView) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.subscriptions(token)
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
channelRecView?.adapter=SubscriptionChannelAdapter(response.toMutableList())
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.e(TAG,"Stopped")
|
||||
subscriptionAdapter = null
|
||||
view?.findViewById<RecyclerView>(R.id.sub_feed)?.adapter=null
|
||||
super.onStop()
|
||||
}
|
||||
override fun onDestroy() {
|
||||
Log.e(TAG,"Destroyed")
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.MainActivity
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.github.libretube.PlayerFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.obj.StreamItem
|
||||
import com.github.libretube.videoViews
|
||||
|
||||
class SubscriptionAdapter(private val videoFeed: List<StreamItem>): RecyclerView.Adapter<SubscriptionViewHolder>() {
|
||||
//private var limitedVideoFeed: MutableList<String> = [""].toMutableList()
|
||||
var i = 10
|
||||
override fun getItemCount(): Int {
|
||||
return i
|
||||
}
|
||||
|
||||
fun updateItems(){
|
||||
//limitedVideoFeed.add("")
|
||||
i += 10
|
||||
//println("suck another dick: "+newItems[0].title)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val cell = layoutInflater.inflate(R.layout.trending_row,parent,false)
|
||||
return SubscriptionViewHolder(cell)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
|
||||
val trending = videoFeed[position]
|
||||
holder.v.findViewById<TextView>(R.id.textView_title).text = trending.title
|
||||
holder.v.findViewById<TextView>(R.id.textView_channel).text = trending.uploaderName +" • "+ trending.views.videoViews()+" • "+trending.uploadedDate
|
||||
val thumbnailImage = holder.v.findViewById<ImageView>(R.id.thumbnail)
|
||||
val channelImage = holder.v.findViewById<ImageView>(R.id.channel_image)
|
||||
channelImage.setOnClickListener{
|
||||
val activity = holder.v.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to trending.uploaderUrl)
|
||||
activity.navController.navigate(R.id.channel, bundle)
|
||||
try {
|
||||
val mainMotionLayout = activity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
||||
if (mainMotionLayout.progress == 0.toFloat()) {
|
||||
mainMotionLayout.transitionToEnd()
|
||||
activity.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
|
||||
}
|
||||
}catch (e: Exception){
|
||||
|
||||
}
|
||||
}
|
||||
Picasso.get().load(trending.thumbnail).into(thumbnailImage)
|
||||
Picasso.get().load(trending.uploaderAvatar).into(channelImage)
|
||||
holder.v.setOnClickListener{
|
||||
var bundle = Bundle()
|
||||
bundle.putString("videoId",trending.url!!.replace("/watch?v=",""))
|
||||
var frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = holder.v.context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.commitNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
class SubscriptionViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
||||
init {
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.MainActivity
|
||||
import com.github.libretube.PlayerFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.obj.Subscription
|
||||
import com.squareup.picasso.Picasso
|
||||
import org.w3c.dom.Text
|
||||
|
||||
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>): RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||
override fun getItemCount(): Int {
|
||||
return subscriptions.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionChannelViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val cell = layoutInflater.inflate(R.layout.channel_subscription_row,parent,false)
|
||||
return SubscriptionChannelViewHolder(cell)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
|
||||
val subscription = subscriptions[position]
|
||||
holder.v.findViewById<TextView>(R.id.subscription_channel_name).text=subscription.name
|
||||
val avatar = holder.v.findViewById<ImageView>(R.id.subscription_channel_image)
|
||||
Picasso.get().load(subscription.avatar).into(avatar)
|
||||
holder.v.setOnClickListener{
|
||||
val activity = holder.v.context as MainActivity
|
||||
val bundle = bundleOf("channel_id" to subscription.url)
|
||||
activity.navController.navigate(R.id.channel,bundle)
|
||||
}
|
||||
}
|
||||
}
|
||||
class SubscriptionChannelViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
||||
init {
|
||||
}
|
||||
}
|
10
app/src/main/res/drawable/ic_login.xml
Normal file
10
app/src/main/res/drawable/ic_login.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11,7L9.6,8.4l2.6,2.6H2v2h10.2l-2.6,2.6L11,17l5,-5L11,7zM20,19h-8v2h8c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2h-8v2h8V19z"/>
|
||||
</vector>
|
24
app/src/main/res/layout/channel_subscription_row.xml
Normal file
24
app/src/main/res/layout/channel_subscription_row.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_margin="8dp"
|
||||
android:padding="8dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
>
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/subscription_channel_image"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="4dp"/>
|
||||
<TextView
|
||||
android:text="kirrrrrrrrrrrrrrrrrrrrrrrrrrfgdfg"
|
||||
android:id="@+id/subscription_channel_name"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1" />
|
||||
</LinearLayout>
|
@ -1,14 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Subscriptions">
|
||||
<ProgressBar
|
||||
android:id="@+id/sub_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/loginOrRegister"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
>
|
||||
@ -19,17 +27,49 @@
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:src="@drawable/ic_campaign" />
|
||||
android:src="@drawable/ic_login" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textLike"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Coming Soon!"
|
||||
android:id="@+id/textLike"
|
||||
android:layout_below="@id/boogh"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:text="@string/please_login"
|
||||
android:textSize="20sp"
|
||||
/>
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
<ScrollView
|
||||
android:id="@+id/scrollview_sub"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
</FrameLayout>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sub_channels"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false" />
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sub_feed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="false" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
@ -22,4 +22,5 @@
|
||||
<string name="customInstance">Add a custom instance</string>
|
||||
<string name="region">Choose a region</string>
|
||||
<string name="login_register">Login/Register</string>
|
||||
<string name="please_login">Please Login or Register from the settings to show your Subscriptions!</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user