From c75ec150fe8c41af255399d4725e60fc192a723f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 6 Oct 2022 15:14:06 +0200 Subject: [PATCH] playlist sorting option --- .../libretube/constants/PreferenceKeys.kt | 2 +- .../libretube/ui/fragments/HomeFragment.kt | 1 - .../libretube/ui/fragments/LibraryFragment.kt | 19 ++++++++++++++++--- .../ui/preferences/PlayerSettings.kt | 1 - app/src/main/res/drawable/ic_filter.xml | 10 ++++++++++ .../main/res/layout/dialog_delete_account.xml | 6 +++--- app/src/main/res/layout/dialog_download.xml | 2 +- app/src/main/res/layout/dialog_login.xml | 6 +++--- app/src/main/res/menu/bottom_menu.xml | 8 ++++---- app/src/main/res/values-night/themes.xml | 9 ++++++--- app/src/main/res/values/array.xml | 14 ++++++++++++++ app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/values/themes.xml | 18 ++++++++++++------ app/src/main/res/xml/instance_settings.xml | 12 ++++++++++++ 14 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 app/src/main/res/drawable/ic_filter.xml diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index 0b34e4177..1fdd5e0ce 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -29,13 +29,13 @@ object PreferenceKeys { const val PURE_THEME = "pure_theme" const val ACCENT_COLOR = "accent_color" const val GRID_COLUMNS = "grid" - const val DEFAULT_TAB = "default_tab" const val LABEL_VISIBILITY = "label_visibility" const val APP_ICON = "icon_change" const val LEGACY_SUBSCRIPTIONS = "legacy_subscriptions" const val LEGACY_SUBSCRIPTIONS_COLUMNS = "legacy_subscriptions_columns" const val ALTERNATIVE_TRENDING_LAYOUT = "trending_layout" const val NEW_VIDEOS_BADGE = "new_videos_badge" + const val PLAYLISTS_ORDER = "playlists_order" /** * Instance diff --git a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt index 1f00e2388..c5a7566cf 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import android.widget.Toast.makeText import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager diff --git a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt index f0cc9b98a..42e689cb0 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt @@ -97,7 +97,7 @@ class LibraryFragment : BaseFragment() { fun fetchPlaylists() { binding.playlistRefresh.isRefreshing = true lifecycleScope.launchWhenCreated { - val response = try { + var playlists = try { RetrofitInstance.authApi.playlists(token) } catch (e: IOException) { println(e) @@ -111,11 +111,24 @@ class LibraryFragment : BaseFragment() { } finally { binding.playlistRefresh.isRefreshing = false } - if (response.isNotEmpty()) { + if (playlists.isNotEmpty()) { binding.loginOrRegister.visibility = View.GONE + playlists = when ( + PreferenceHelper.getString( + PreferenceKeys.PLAYLISTS_ORDER, + "recent" + ) + ) { + "recent" -> playlists + "recent_reversed" -> playlists.reversed() + "name" -> playlists.sortedBy { it.name } + "name_reversed" -> playlists.sortedBy { it.name }.reversed() + else -> playlists + } + val playlistsAdapter = PlaylistsAdapter( - response.toMutableList(), + playlists.toMutableList(), childFragmentManager, requireActivity() ) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt index 24f5e31de..edf80a2de 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/PlayerSettings.kt @@ -10,7 +10,6 @@ import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.util.LocaleHelper import com.github.libretube.util.PreferenceHelper -import java.util.* class PlayerSettings : BasePreferenceFragment() { diff --git a/app/src/main/res/drawable/ic_filter.xml b/app/src/main/res/drawable/ic_filter.xml new file mode 100644 index 000000000..52d959093 --- /dev/null +++ b/app/src/main/res/drawable/ic_filter.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/dialog_delete_account.xml b/app/src/main/res/layout/dialog_delete_account.xml index 21d350617..e9d0257ca 100644 --- a/app/src/main/res/layout/dialog_delete_account.xml +++ b/app/src/main/res/layout/dialog_delete_account.xml @@ -1,8 +1,8 @@ + android:hint="@string/password" + app:passwordToggleEnabled="true"> diff --git a/app/src/main/res/layout/dialog_login.xml b/app/src/main/res/layout/dialog_login.xml index 4f1157680..9e2192217 100644 --- a/app/src/main/res/layout/dialog_login.xml +++ b/app/src/main/res/layout/dialog_login.xml @@ -1,8 +1,8 @@ + android:hint="@string/password" + app:passwordToggleEnabled="true"> + android:title="@string/downloads" /> + android:title="@string/history" /> \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 042a7473a..708d3362a 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -93,7 +93,8 @@ @color/yellow_md_theme_dark_secondary @color/yellow_md_theme_dark_onSecondary @color/yellow_md_theme_dark_secondaryContainer - @color/yellow_md_theme_dark_onSecondaryContainer + @color/yellow_md_theme_dark_onSecondaryContainer + @color/yellow_md_theme_dark_tertiary @color/yellow_md_theme_dark_onTertiary @color/yellow_md_theme_dark_tertiaryContainer @@ -124,7 +125,8 @@ @color/green_md_theme_dark_secondary @color/green_md_theme_dark_onSecondary @color/green_md_theme_dark_secondaryContainer - @color/green_md_theme_dark_onSecondaryContainer + @color/green_md_theme_dark_onSecondaryContainer + @color/green_md_theme_dark_tertiary @color/green_md_theme_dark_onTertiary @color/green_md_theme_dark_tertiaryContainer @@ -155,7 +157,8 @@ @color/purple_md_theme_dark_secondary @color/purple_md_theme_dark_onSecondary @color/purple_md_theme_dark_secondaryContainer - @color/purple_md_theme_dark_onSecondaryContainer + @color/purple_md_theme_dark_onSecondaryContainer + @color/purple_md_theme_dark_tertiary @color/purple_md_theme_dark_onTertiary @color/purple_md_theme_dark_tertiaryContainer diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 1bc51202b..eea117749 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -421,4 +421,18 @@ default + + @string/recentlyUpdated + @string/recentlyUpdatedReversed + @string/playlistName + @string/playlistNameReversed + + + + recent + recent_reversed + name + name_reversed + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00e7a3bc0..5735b79af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -340,6 +340,10 @@ Pitch Filename Invalid filename! + Playlists order + Playlist name (reversed) + Recently updated + Recently updated (reversed) Download Service diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 8db722ec0..a02bbf482 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -62,7 +62,8 @@ @color/blue_md_theme_light_secondary @color/blue_md_theme_light_onSecondary @color/blue_md_theme_light_secondaryContainer - @color/blue_md_theme_light_onSecondaryContainer + @color/blue_md_theme_light_onSecondaryContainer + @color/blue_md_theme_light_tertiary @color/blue_md_theme_light_onTertiary @color/blue_md_theme_light_tertiaryContainer @@ -93,11 +94,13 @@ @color/yellow_md_theme_light_secondary @color/yellow_md_theme_light_onSecondary @color/yellow_md_theme_light_secondaryContainer - @color/yellow_md_theme_light_onSecondaryContainer + @color/yellow_md_theme_light_onSecondaryContainer + @color/yellow_md_theme_light_tertiary @color/yellow_md_theme_light_onTertiary @color/yellow_md_theme_light_tertiaryContainer - @color/yellow_md_theme_light_onTertiaryContainer + @color/yellow_md_theme_light_onTertiaryContainer + @color/yellow_md_theme_light_error @color/yellow_md_theme_light_errorContainer @color/yellow_md_theme_light_onError @@ -124,7 +127,8 @@ @color/green_md_theme_light_secondary @color/green_md_theme_light_onSecondary @color/green_md_theme_light_secondaryContainer - @color/green_md_theme_light_onSecondaryContainer + @color/green_md_theme_light_onSecondaryContainer + @color/green_md_theme_light_tertiary @color/green_md_theme_light_onTertiary @color/green_md_theme_light_tertiaryContainer @@ -155,11 +159,13 @@ @color/purple_md_theme_light_secondary @color/purple_md_theme_light_onSecondary @color/purple_md_theme_light_secondaryContainer - @color/purple_md_theme_light_onSecondaryContainer + @color/purple_md_theme_light_onSecondaryContainer + @color/purple_md_theme_light_tertiary @color/purple_md_theme_light_onTertiary @color/purple_md_theme_light_tertiaryContainer - @color/purple_md_theme_light_onTertiaryContainer + @color/purple_md_theme_light_onTertiaryContainer + @color/purple_md_theme_light_error @color/purple_md_theme_light_errorContainer @color/purple_md_theme_light_onError diff --git a/app/src/main/res/xml/instance_settings.xml b/app/src/main/res/xml/instance_settings.xml index 40fc7824e..29ab5da02 100644 --- a/app/src/main/res/xml/instance_settings.xml +++ b/app/src/main/res/xml/instance_settings.xml @@ -71,4 +71,16 @@ + + + + + + \ No newline at end of file