mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Playlists
This commit is contained in:
parent
501f64d7dd
commit
362bcfe1e5
@ -230,19 +230,19 @@ class ChannelFragment : Fragment() {
|
|||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.api.getChannelNextPage(channel_id!!,nextPage!!)
|
RetrofitInstance.api.getChannelNextPage(channel_id!!,nextPage!!)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
refreshLayout?.isRefreshing = false;
|
refreshLayout?.isRefreshing = false
|
||||||
println(e)
|
println(e)
|
||||||
Log.e(TAG, "IOException, you might not have internet connection")
|
Log.e(TAG, "IOException, you might not have internet connection")
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
} catch (e: HttpException) {
|
} catch (e: HttpException) {
|
||||||
refreshLayout?.isRefreshing = false;
|
refreshLayout?.isRefreshing = false
|
||||||
Log.e(TAG, "HttpException, unexpected response,"+e.response())
|
Log.e(TAG, "HttpException, unexpected response,"+e.response())
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
nextPage = response.nextpage
|
nextPage = response.nextpage
|
||||||
channelAdapter?.updateItems(response.relatedStreams!!)
|
channelAdapter?.updateItems(response.relatedStreams!!)
|
||||||
isLoading=false
|
isLoading=false
|
||||||
refreshLayout?.isRefreshing = false;
|
refreshLayout?.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
run()
|
run()
|
||||||
|
@ -1,15 +1,28 @@
|
|||||||
package com.github.libretube
|
package com.github.libretube
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.ScrollView
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.github.libretube.adapters.ChannelAdapter
|
||||||
|
import com.squareup.picasso.Picasso
|
||||||
|
import retrofit2.HttpException
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
|
||||||
class Library : Fragment() {
|
class Library : Fragment() {
|
||||||
|
|
||||||
|
private val TAG = "LibraryFragment"
|
||||||
|
lateinit var token: String
|
||||||
|
lateinit var playlistRecyclerView: RecyclerView
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
@ -25,5 +38,39 @@ class Library : Fragment() {
|
|||||||
return inflater.inflate(R.layout.fragment_library, container, false)
|
return inflater.inflate(R.layout.fragment_library, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
playlistRecyclerView = view.findViewById(R.id.playlist_recView)
|
||||||
|
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||||
|
token = sharedPref?.getString("token","")!!
|
||||||
|
if(token!="") {
|
||||||
|
fetchPlaylists(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchPlaylists(view: View){
|
||||||
|
fun run() {
|
||||||
|
lifecycleScope.launchWhenCreated {
|
||||||
|
val response = try {
|
||||||
|
RetrofitInstance.api.playlists(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
|
||||||
|
}
|
||||||
|
runOnUiThread {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run()
|
||||||
|
}
|
||||||
|
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||||
|
this ?: return
|
||||||
|
if (!isAdded) return // Fragment not attached to an Activity
|
||||||
|
activity?.runOnUiThread(action)
|
||||||
|
}
|
||||||
}
|
}
|
@ -55,6 +55,9 @@ interface PipedApi {
|
|||||||
@POST("import")
|
@POST("import")
|
||||||
suspend fun importSubscriptions(@Header("Authorization") token: String, @Body channels: List<String>): Message
|
suspend fun importSubscriptions(@Header("Authorization") token: String, @Body channels: List<String>): Message
|
||||||
|
|
||||||
|
@GET("user/playlists")
|
||||||
|
suspend fun playlists(@Header("Authorization") token: String): List<Playlists>
|
||||||
|
|
||||||
//only for fetching servers list
|
//only for fetching servers list
|
||||||
@GET
|
@GET
|
||||||
suspend fun getInstances(@Url url: String): List<Instances>
|
suspend fun getInstances(@Url url: String): List<Instances>
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.github.libretube.adapters
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.format.DateUtils
|
||||||
|
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.recyclerview.widget.RecyclerView
|
||||||
|
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.formatShort
|
||||||
|
import com.github.libretube.obj.Playlists
|
||||||
|
|
||||||
|
class PlaylistsAdapter(private val playlists: MutableList<Playlists>): RecyclerView.Adapter<PlaylistsViewHolder>() {
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return playlists.size
|
||||||
|
}
|
||||||
|
fun updateItems(newItems: List<Playlists>){
|
||||||
|
playlists.addAll(newItems)
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistsViewHolder {
|
||||||
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
|
val cell = layoutInflater.inflate(R.layout.playlists_row,parent,false)
|
||||||
|
return PlaylistsViewHolder(cell)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) {
|
||||||
|
val playlist = playlists[position]
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class PlaylistsViewHolder(val v: View): RecyclerView.ViewHolder(v){
|
||||||
|
init {
|
||||||
|
}
|
||||||
|
}
|
11
app/src/main/java/com/github/libretube/obj/Playlists.kt
Normal file
11
app/src/main/java/com/github/libretube/obj/Playlists.kt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.github.libretube.obj
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
data class Playlists(
|
||||||
|
var id: String? = null,
|
||||||
|
var name: String? = null,
|
||||||
|
var shortDescription: String? = null,
|
||||||
|
var thumbnail: String? = null,
|
||||||
|
)
|
@ -6,30 +6,60 @@
|
|||||||
tools:context=".Library">
|
tools:context=".Library">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
android:id="@+id/loginOrRegister2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
>
|
android:layout_centerVertical="true">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/player_like"
|
android:id="@+id/boogh2"
|
||||||
android:layout_width="100dp"
|
android:layout_width="100dp"
|
||||||
android:layout_height="100dp"
|
android:layout_height="100dp"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:src="@drawable/ic_campaign" />
|
android:src="@drawable/ic_login" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/textLike2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Coming Soon!"
|
android:layout_below="@id/boogh2"
|
||||||
android:id="@+id/textLike"
|
|
||||||
android:layout_below="@id/player_like"
|
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:textStyle="bold"
|
android:gravity="center"
|
||||||
|
android:text="@string/please_login"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
/>
|
android:textStyle="bold" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<com.github.libretube.CustomSwipeToRefresh
|
||||||
|
android:id="@+id/playlist_refresh"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollview_playlist"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:descendantFocusability="blocksDescendants">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/playlist_recView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:nestedScrollingEnabled="false" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</com.github.libretube.CustomSwipeToRefresh>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
@ -17,8 +17,7 @@
|
|||||||
android:id="@+id/loginOrRegister"
|
android:id="@+id/loginOrRegister"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerInParent="true">
|
||||||
android:layout_centerVertical="true">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/boogh"
|
android:id="@+id/boogh"
|
||||||
|
59
app/src/main/res/layout/playlists_row.xml
Normal file
59
app/src/main/res/layout/playlists_row.xml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.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"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:id="@+id/playlist"
|
||||||
|
>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Guideline
|
||||||
|
android:id="@+id/guideline"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintGuide_percent=".5"/>
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/card_playlist_thumbnail"
|
||||||
|
app:cardCornerRadius="8dp"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintDimensionRatio="16:9"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.0"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/guideline">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/playlist_thumbnail"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:srcCompat="@tools:sample/backgrounds/scenic" />
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/playlist_title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="TextView"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/card_playlist_thumbnail"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/playlist_description"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="TextView"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/card_playlist_thumbnail"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/playlist_title" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user