diff --git a/app/src/main/java/com/github/libretube/Subscriptions.kt b/app/src/main/java/com/github/libretube/Subscriptions.kt
index 9262fc45e..c01b5b85f 100644
--- a/app/src/main/java/com/github/libretube/Subscriptions.kt
+++ b/app/src/main/java/com/github/libretube/Subscriptions.kt
@@ -14,6 +14,7 @@ import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.libretube.adapters.SubscriptionAdapter
import com.github.libretube.adapters.SubscriptionChannelAdapter
import com.github.libretube.adapters.TrendingAdapter
@@ -25,6 +26,7 @@ class Subscriptions : Fragment() {
lateinit var token: String
var isLoaded = false
private var subscriptionAdapter: SubscriptionAdapter? =null
+ private var refreshLayout: SwipeRefreshLayout? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
@@ -44,8 +46,11 @@ class Subscriptions : Fragment() {
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
token = sharedPref?.getString("token","")!!
Log.e(TAG,token)
+ refreshLayout = view.findViewById(R.id.sub_refresh)
if(token!=""){
view.findViewById(R.id.loginOrRegister).visibility=View.GONE
+ refreshLayout?.isEnabled = true
+
var progressBar = view.findViewById(R.id.sub_progress)
progressBar.visibility=View.VISIBLE
@@ -57,6 +62,11 @@ class Subscriptions : Fragment() {
feedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
fetchFeed(feedRecView, progressBar)
+ refreshLayout?.setOnRefreshListener {
+ fetchChannels(channelRecView)
+ fetchFeed(feedRecView, progressBar)
+ }
+
val scrollView = view.findViewById(R.id.scrollview_sub)
scrollView.viewTreeObserver
.addOnScrollChangedListener {
@@ -64,11 +74,15 @@ class Subscriptions : Fragment() {
== (scrollView.height + scrollView.scrollY)) {
//scroll view is at bottom
if(isLoaded){
+ refreshLayout?.isRefreshing = true
subscriptionAdapter?.updateItems()
+ refreshLayout?.isRefreshing = false
}
}
}
+ } else {
+ refreshLayout?.isEnabled = false
}
}
@@ -84,6 +98,8 @@ class Subscriptions : Fragment() {
} catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response")
return@launchWhenCreated
+ } finally {
+ refreshLayout?.isRefreshing = false
}
if (response.isNotEmpty()){
subscriptionAdapter = SubscriptionAdapter(response)
@@ -109,6 +125,8 @@ class Subscriptions : Fragment() {
} catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response")
return@launchWhenCreated
+ } finally {
+ refreshLayout?.isRefreshing = false
}
if (response.isNotEmpty()){
channelRecView?.adapter=SubscriptionChannelAdapter(response.toMutableList())
@@ -131,4 +149,4 @@ class Subscriptions : Fragment() {
super.onDestroy()
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml
index 401303438..a27f4ddb0 100644
--- a/app/src/main/res/layout/fragment_subscriptions.xml
+++ b/app/src/main/res/layout/fragment_subscriptions.xml
@@ -4,22 +4,21 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Subscriptions">
+
+ android:layout_centerVertical="true"
+ android:visibility="gone" />
+ android:layout_centerVertical="true">
-
-
-
+
+
+ android:orientation="vertical">
-
-
-
+ android:descendantFocusability="blocksDescendants">
-
+
+
+
-
-
-
-
\ No newline at end of file
+ android:layout_height="wrap_content"
+ android:descendantFocusability="blocksDescendants">
+
+
+
+
+
+
+