From 395720a8821b27277da4bff19829a3ca2c990188 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 08:34:43 +0200 Subject: [PATCH] Lazy Load Subs and hide when not logged in --- .../java/com/github/libretube/Subscriptions.kt | 16 ++++++++++++---- .../main/res/layout/fragment_subscriptions.xml | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/Subscriptions.kt b/app/src/main/java/com/github/libretube/Subscriptions.kt index eb63d6147..6dba0f985 100644 --- a/app/src/main/java/com/github/libretube/Subscriptions.kt +++ b/app/src/main/java/com/github/libretube/Subscriptions.kt @@ -8,6 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.* +import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager @@ -52,8 +53,6 @@ class Subscriptions : Fragment() { progressBar.visibility=View.VISIBLE var channelRecView = view.findViewById(R.id.sub_channels) - channelRecView?.layoutManager = GridLayoutManager(context, 4) - fetchChannels(channelRecView) var feedRecView = view.findViewById(R.id.sub_feed) val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) @@ -67,9 +66,18 @@ class Subscriptions : Fragment() { } var toggleSubs = view.findViewById(R.id.toggle_subs) + toggleSubs.visibility = View.VISIBLE toggleSubs.setOnClickListener { - channelRecView.visibility = if (channelRecView.visibility == View.GONE) View.VISIBLE else View.GONE - feedRecView.visibility = if (feedRecView.visibility == View.GONE) View.VISIBLE else View.GONE + if (!channelRecView.isVisible) { + channelRecView?.layoutManager = GridLayoutManager(context, 4) + fetchChannels(channelRecView) + channelRecView.visibility = View.VISIBLE + feedRecView.visibility = View.GONE + } + else { + channelRecView.visibility = View.GONE + feedRecView.visibility = View.VISIBLE + } } val scrollView = view.findViewById(R.id.scrollview_sub) diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index dec57928a..ec0bd7bc6 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -58,7 +58,8 @@ android:id="@+id/toggle_subs" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="10dp"> + android:layout_margin="10dp" + android:visibility="gone">