mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #122 from suraj0208/feature/channel-swipe-to-refresh
Add swipe to refresh on channel fragment
This commit is contained in:
commit
041005f40b
@ -4,6 +4,7 @@ package com.github.libretube
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.opengl.Visibility
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
@ -17,6 +18,7 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
import com.github.libretube.adapters.ChannelAdapter
|
import com.github.libretube.adapters.ChannelAdapter
|
||||||
import com.github.libretube.obj.Subscribe
|
import com.github.libretube.obj.Subscribe
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
@ -33,6 +35,7 @@ class ChannelFragment : Fragment() {
|
|||||||
var channelAdapter: ChannelAdapter? = null
|
var channelAdapter: ChannelAdapter? = null
|
||||||
var isLoading = true
|
var isLoading = true
|
||||||
var isSubscribed: Boolean =false
|
var isSubscribed: Boolean =false
|
||||||
|
private var refreshLayout: SwipeRefreshLayout? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -58,12 +61,22 @@ class ChannelFragment : Fragment() {
|
|||||||
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView)
|
||||||
recyclerView.layoutManager = LinearLayoutManager(context)
|
recyclerView.layoutManager = LinearLayoutManager(context)
|
||||||
|
refreshLayout = view.findViewById(R.id.channel_refresh)
|
||||||
|
|
||||||
|
val refreshChannel = {
|
||||||
|
refreshLayout?.isRefreshing = true
|
||||||
fetchChannel(view)
|
fetchChannel(view)
|
||||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||||
if(sharedPref?.getString("token","")!=""){
|
|
||||||
val subButton = view.findViewById<MaterialButton>(R.id.channel_subscribe)
|
val subButton = view.findViewById<MaterialButton>(R.id.channel_subscribe)
|
||||||
|
if (sharedPref?.getString("token","") != "") {
|
||||||
isSubscribed(subButton)
|
isSubscribed(subButton)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
refreshChannel()
|
||||||
|
refreshLayout?.setOnRefreshListener {
|
||||||
|
refreshChannel()
|
||||||
|
}
|
||||||
|
|
||||||
val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
|
val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
|
||||||
scrollView.viewTreeObserver
|
scrollView.viewTreeObserver
|
||||||
.addOnScrollChangedListener {
|
.addOnScrollChangedListener {
|
||||||
@ -72,6 +85,7 @@ class ChannelFragment : Fragment() {
|
|||||||
//scroll view is at bottom
|
//scroll view is at bottom
|
||||||
if(nextPage!=null && !isLoading){
|
if(nextPage!=null && !isLoading){
|
||||||
isLoading=true
|
isLoading=true
|
||||||
|
refreshLayout?.isRefreshing = true;
|
||||||
fetchNextPage()
|
fetchNextPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,16 +194,20 @@ class ChannelFragment : Fragment() {
|
|||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.api.getChannel(channel_id!!)
|
RetrofitInstance.api.getChannel(channel_id!!)
|
||||||
}catch(e: IOException) {
|
}catch(e: IOException) {
|
||||||
|
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;
|
||||||
Log.e(TAG, "HttpException, unexpected response")
|
Log.e(TAG, "HttpException, unexpected response")
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
nextPage = response.nextpage
|
nextPage = response.nextpage
|
||||||
isLoading=false
|
isLoading=false
|
||||||
|
refreshLayout?.isRefreshing = false;
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
view.findViewById<ScrollView>(R.id.channel_scrollView).visibility = View.VISIBLE
|
||||||
view.findViewById<TextView>(R.id.channel_name).text=response.name
|
view.findViewById<TextView>(R.id.channel_name).text=response.name
|
||||||
view.findViewById<TextView>(R.id.channel_subs).text=response.subscriberCount.formatShort() + " subscribers"
|
view.findViewById<TextView>(R.id.channel_subs).text=response.subscriberCount.formatShort() + " subscribers"
|
||||||
view.findViewById<TextView>(R.id.channel_description).text=response.description
|
view.findViewById<TextView>(R.id.channel_description).text=response.description
|
||||||
@ -212,17 +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;
|
||||||
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;
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
run()
|
run()
|
||||||
|
@ -1,61 +1,72 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.github.libretube.CustomSwipeToRefresh xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/channel_refresh"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/channel_scrollView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".ChannelFragment"
|
tools:context=".ChannelFragment"
|
||||||
android:id="@+id/channel_scrollView">
|
android:visibility="invisible">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/channel_banner"
|
android:id="@+id/channel_banner"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="80dp"
|
android:layout_height="80dp" />
|
||||||
/>
|
|
||||||
<de.hdodenhof.circleimageview.CircleImageView
|
<de.hdodenhof.circleimageview.CircleImageView
|
||||||
android:id="@+id/channel_image"
|
android:id="@+id/channel_image"
|
||||||
android:layout_width="55dp"
|
android:layout_width="55dp"
|
||||||
android:layout_height="55dp"
|
android:layout_height="55dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp" />
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/channel_name"
|
android:id="@+id/channel_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="7dp"
|
||||||
android:text="Mia Plays"
|
android:text="Mia Plays"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:layout_marginTop="7dp"
|
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/channel_subscribe"
|
android:id="@+id/channel_subscribe"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:text="@string/subscribe"
|
android:text="@string/subscribe"
|
||||||
android:textColor="?attr/colorPrimary"
|
android:textColor="?attr/colorPrimary"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/channel_subs"
|
android:id="@+id/channel_subs"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:text="@string/app_name"/>
|
android:text="@string/app_name" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="Description"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:textSize="17sp" />
|
android:text="Description"
|
||||||
|
android:textSize="17sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/channel_description"
|
android:id="@+id/channel_description"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -68,12 +79,12 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="Videos"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginBottom="5dp"
|
android:layout_marginBottom="5dp"
|
||||||
android:textSize="17sp" />
|
android:text="Videos"
|
||||||
|
android:textSize="17sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -82,11 +93,13 @@
|
|||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/channel_recView"
|
android:id="@+id/channel_recView"
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:layout_marginEnd="10dp"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
android:nestedScrollingEnabled="false" />
|
android:nestedScrollingEnabled="false" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
</com.github.libretube.CustomSwipeToRefresh>
|
Loading…
x
Reference in New Issue
Block a user