From 210285b39a88cb6b8b204aa0f2c9f7c64030ff66 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 10 Feb 2025 13:37:00 -0700 Subject: [PATCH] home: remove adaptive tabs More hassle than they are worth. --- CHANGELOG.md | 1 + .../org/oxycblt/auxio/home/HomeFragment.kt | 4 +- .../auxio/home/tabs/AdaptiveTabStrategy.kt | 60 ------------------- .../auxio/home/tabs/NamedTabStrategy.kt | 10 ++++ 4 files changed, 13 insertions(+), 62 deletions(-) delete mode 100644 app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt create mode 100644 app/src/main/java/org/oxycblt/auxio/home/tabs/NamedTabStrategy.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 7263b8708..fc66300a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ - Date added is now local to when the app discovers the file and will not persist long-term - Songs with no album are now "Unknown album" rather than folder name +- Tab layout no longer changes on device configuration #### Dev/Meta - No longer using custom logging setup diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt index 8da7dc046..d069e6075 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt @@ -53,7 +53,7 @@ import org.oxycblt.auxio.home.list.ArtistListFragment import org.oxycblt.auxio.home.list.GenreListFragment import org.oxycblt.auxio.home.list.PlaylistListFragment import org.oxycblt.auxio.home.list.SongListFragment -import org.oxycblt.auxio.home.tabs.AdaptiveTabStrategy +import org.oxycblt.auxio.home.tabs.NamedTabStrategy import org.oxycblt.auxio.home.tabs.Tab import org.oxycblt.auxio.list.ListViewModel import org.oxycblt.auxio.list.SelectionFragment @@ -272,7 +272,7 @@ class HomeFragment : TabLayoutMediator( binding.homeTabs, binding.homePager, - AdaptiveTabStrategy(requireContext(), homeModel.currentTabTypes)) + NamedTabStrategy(homeModel.currentTabTypes)) .attach() } diff --git a/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt b/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt deleted file mode 100644 index 7cf0c2a53..000000000 --- a/app/src/main/java/org/oxycblt/auxio/home/tabs/AdaptiveTabStrategy.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 Auxio Project - * AdaptiveTabStrategy.kt is part of Auxio. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.oxycblt.auxio.home.tabs - -import android.content.Context -import com.google.android.material.tabs.TabLayout -import com.google.android.material.tabs.TabLayoutMediator -import org.oxycblt.auxio.R -import org.oxycblt.auxio.music.MusicType - -/** - * A [TabLayoutMediator.TabConfigurationStrategy] that uses larger/smaller tab configurations - * depending on the screen configuration. - * - * @param context [Context] required to obtain window information - * @param tabs Current tab configuration from settings - * @author Alexander Capehart (OxygenCobalt) - */ -class AdaptiveTabStrategy(context: Context, private val tabs: List) : - TabLayoutMediator.TabConfigurationStrategy { - private val width = context.resources.configuration.smallestScreenWidthDp - - override fun onConfigureTab(tab: TabLayout.Tab, position: Int) { - val homeTab = tabs[position] - val icon = - when (homeTab) { - MusicType.SONGS -> R.drawable.ic_song_24 - MusicType.ALBUMS -> R.drawable.ic_album_24 - MusicType.ARTISTS -> R.drawable.ic_artist_24 - MusicType.GENRES -> R.drawable.ic_genre_24 - MusicType.PLAYLISTS -> R.drawable.ic_playlist_24 - } - - // Use expected sw* size thresholds when choosing a configuration. - when { - // On small screens, only display an icon. - width < 370 -> tab.setIcon(icon).setContentDescription(homeTab.nameRes) - // On large screens, display an icon and text. - width < 600 -> tab.setText(homeTab.nameRes) - // On medium-size screens, display text. - else -> tab.setIcon(icon).setText(homeTab.nameRes) - } - } -} diff --git a/app/src/main/java/org/oxycblt/auxio/home/tabs/NamedTabStrategy.kt b/app/src/main/java/org/oxycblt/auxio/home/tabs/NamedTabStrategy.kt new file mode 100644 index 000000000..38950f691 --- /dev/null +++ b/app/src/main/java/org/oxycblt/auxio/home/tabs/NamedTabStrategy.kt @@ -0,0 +1,10 @@ +package org.oxycblt.auxio.home.tabs + +import com.google.android.material.tabs.TabLayout +import com.google.android.material.tabs.TabLayoutMediator.TabConfigurationStrategy + +class NamedTabStrategy(private val homeTabs: List) : TabConfigurationStrategy { + override fun onConfigureTab(tab: TabLayout.Tab, position: Int) { + tab.setText(homeTabs[position].type.nameRes) + } +} \ No newline at end of file