mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Playlists
This commit is contained in:
parent
501f64d7dd
commit
362bcfe1e5
@ -230,19 +230,19 @@ class ChannelFragment : Fragment() {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getChannelNextPage(channel_id!!,nextPage!!)
|
||||
} catch (e: IOException) {
|
||||
refreshLayout?.isRefreshing = false;
|
||||
refreshLayout?.isRefreshing = false
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
refreshLayout?.isRefreshing = false;
|
||||
refreshLayout?.isRefreshing = false
|
||||
Log.e(TAG, "HttpException, unexpected response,"+e.response())
|
||||
return@launchWhenCreated
|
||||
}
|
||||
nextPage = response.nextpage
|
||||
channelAdapter?.updateItems(response.relatedStreams!!)
|
||||
isLoading=false
|
||||
refreshLayout?.isRefreshing = false;
|
||||
refreshLayout?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
run()
|
||||
|
@ -1,15 +1,28 @@
|
||||
package com.github.libretube
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
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() {
|
||||
|
||||
|
||||
private val TAG = "LibraryFragment"
|
||||
lateinit var token: String
|
||||
lateinit var playlistRecyclerView: RecyclerView
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
@ -25,5 +38,39 @@ class Library : Fragment() {
|
||||
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")
|
||||
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
|
||||
@GET
|
||||
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">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/loginOrRegister2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
>
|
||||
android:layout_centerVertical="true">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/player_like"
|
||||
android:id="@+id/boogh2"
|
||||
android:layout_width="100dp"
|
||||
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/textLike2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Coming Soon!"
|
||||
android:id="@+id/textLike"
|
||||
android:layout_below="@id/player_like"
|
||||
android:layout_below="@id/boogh2"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:text="@string/please_login"
|
||||
android:textSize="20sp"
|
||||
/>
|
||||
android:textStyle="bold" />
|
||||
</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>
|
@ -17,8 +17,7 @@
|
||||
android:id="@+id/loginOrRegister"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true">
|
||||
android:layout_centerInParent="true">
|
||||
|
||||
<ImageView
|
||||
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…
Reference in New Issue
Block a user