Preference to edit the home tab content

This commit is contained in:
Bnyro 2023-05-31 21:43:50 +02:00
parent 52a2cfafa9
commit dca3eb4b5e
7 changed files with 53 additions and 4 deletions

View File

@ -39,6 +39,7 @@ object PreferenceKeys {
const val NEW_VIDEOS_BADGE = "new_videos_badge"
const val PLAYLISTS_ORDER = "playlists_order"
const val PLAYLIST_SORT_ORDER = "playlist_sort_order"
const val HOME_TAB_CONTENT = "home_tab_content"
/**
* Instance

View File

@ -77,6 +77,10 @@ object PreferenceHelper {
return settings.getFloat(key, defValue)
}
fun getStringSet(key: String?, defValue: Set<String>): Set<String> {
return settings.getStringSet(key, defValue).orEmpty()
}
fun clearPreferences() {
editor.clear().apply()
}

View File

@ -82,11 +82,14 @@ class HomeFragment : Fragment() {
private fun fetchHomeFeed() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) {
val defaultItems = resources.getStringArray(R.array.homeTabItemsValues)
val visibleItems = PreferenceHelper
.getStringSet(PreferenceKeys.HOME_TAB_CONTENT, defaultItems.toSet())
awaitAll(
async { loadTrending() },
async { loadBookmarks() },
async { loadFeed() },
async { loadPlaylists() },
async { if (visibleItems.contains(TRENDING)) loadTrending() },
async { if (visibleItems.contains(BOOKMARKS)) loadBookmarks() },
async { if (visibleItems.contains(FEATURED)) loadFeed() },
async { if (visibleItems.contains(PLAYLISTS)) loadPlaylists() },
)
}
}
@ -194,4 +197,12 @@ class HomeFragment : Fragment() {
binding.scroll.visibility = View.VISIBLE
binding.refresh.isRefreshing = false
}
companion object {
// The values of the preference entries for the home tab content
private const val FEATURED = "featured"
private const val TRENDING = "trending"
private const val BOOKMARKS = "bookmarks"
private const val PLAYLISTS = "playlists"
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19,9l1.25,-2.75L23,5l-2.75,-1.25L19,1l-1.25,2.75L15,5l2.75,1.25L19,9zM11.5,9.5L9,4 6.5,9.5 1,12l5.5,2.5L9,20l2.5,-5.5L17,12l-5.5,-2.5zM19,15l-1.25,2.75L15,19l2.75,1.25L19,23l1.25,-2.75L23,19l-2.75,-1.25L19,15z" />
</vector>

View File

@ -408,4 +408,18 @@
<item>never</item>
</string-array>
<string-array name="homeTabItems">
<item>@string/featured</item>
<item>@string/trending</item>
<item>@string/bookmarks</item>
<item>@string/playlists</item>
</string-array>
<string-array name="homeTabItemsValues">
<item>featured</item>
<item>trending</item>
<item>bookmarks</item>
<item>playlists</item>
</string-array>
</resources>

View File

@ -422,6 +422,7 @@
<string name="import_format_newpipe">NewPipe</string>
<string name="import_format_freetube">FreeTube</string>
<string name="import_format_youtube_csv">YouTube (CSV)</string>
<string name="home_tab_content">Home tab content</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>

View File

@ -56,6 +56,14 @@
<PreferenceCategory app:title="@string/layout">
<MultiSelectListPreference
android:icon="@drawable/ic_awesome"
app:defaultValue="@array/homeTabItemsValues"
android:title="@string/home_tab_content"
android:key="home_tab_content"
android:entryValues="@array/homeTabItemsValues"
android:entries="@array/homeTabItems" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:icon="@drawable/ic_list"