From ea182f7f6db4427d556ef2f1db9cbbaa39f8e6a0 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 18 Mar 2023 17:28:04 +0100 Subject: [PATCH 1/2] Simplify playing queue logic --- $HOME/fish/config.fish | 3 ++ $HOME/fish/fish_variables | 31 +++++++++++++++++++ .../com/github/libretube/util/PlayingQueue.kt | 29 +++++------------ 3 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 $HOME/fish/config.fish create mode 100644 $HOME/fish/fish_variables diff --git a/$HOME/fish/config.fish b/$HOME/fish/config.fish new file mode 100644 index 0000000000..d714361fda --- /dev/null +++ b/$HOME/fish/config.fish @@ -0,0 +1,3 @@ +if status is-interactive + # Commands to run in interactive sessions can go here +end diff --git a/$HOME/fish/fish_variables b/$HOME/fish/fish_variables new file mode 100644 index 0000000000..1a82b8adb9 --- /dev/null +++ b/$HOME/fish/fish_variables @@ -0,0 +1,31 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR __fish_initialized:3400 +SETUVAR fish_color_autosuggestion:555\x1ebrblack +SETUVAR fish_color_cancel:\x2dr +SETUVAR fish_color_command:blue +SETUVAR fish_color_comment:red +SETUVAR fish_color_cwd:green +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:green +SETUVAR fish_color_error:brred +SETUVAR fish_color_escape:brcyan +SETUVAR fish_color_history_current:\x2d\x2dbold +SETUVAR fish_color_host:normal +SETUVAR fish_color_host_remote:yellow +SETUVAR fish_color_normal:normal +SETUVAR fish_color_operator:brcyan +SETUVAR fish_color_param:cyan +SETUVAR fish_color_quote:yellow +SETUVAR fish_color_redirection:cyan\x1e\x2d\x2dbold +SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_status:red +SETUVAR fish_color_user:brgreen +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_key_bindings:fish_default_key_bindings +SETUVAR fish_pager_color_completion:normal +SETUVAR fish_pager_color_description:B3A06D\x1eyellow\x1e\x2di +SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR fish_pager_color_selected_background:\x2dr diff --git a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt index 5201c2414e..457b90fb12 100644 --- a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt +++ b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt @@ -46,19 +46,10 @@ object PlayingQueue { ) } - fun getNext(): String? { - try { - return queue[currentIndex() + 1].url?.toID() - } catch (e: Exception) { - Log.e("queue ended", e.toString()) - } - if (repeatQueue) return queue.firstOrNull()?.url?.toID() - return null - } + fun getNext(): String? = queue.getOrNull(currentIndex() + 1)?.url?.toID() + ?: queue.firstOrNull()?.url?.toID()?.takeIf { repeatQueue } - fun getPrev(): String? { - return if (currentIndex() > 0) queue[currentIndex() - 1].url?.toID() else null - } + fun getPrev(): String? = queue.getOrNull(currentIndex() - 1)?.url?.toID() fun hasPrev(): Boolean { return currentIndex() > 0 @@ -84,15 +75,9 @@ object PlayingQueue { fun size() = queue.size - fun currentIndex(): Int { - return try { - queue.indexOf( - queue.first { it.url?.toID() == currentStream?.url?.toID() } - ) - } catch (e: Exception) { - 0 - } - } + fun currentIndex(): Int = queue.indexOfFirst { + it.url?.toID() == currentStream?.url?.toID() + }.takeIf { it >= 0 } ?: 0 fun getCurrent(): StreamItem? = currentStream @@ -131,7 +116,7 @@ object PlayingQueue { scope.launch { try { val playlist = PlaylistsHelper.getPlaylist(playlistId) - add(*playlist.relatedStreams.orEmpty().toTypedArray()) + add(*playlist.relatedStreams.toTypedArray()) updateCurrent(newCurrentStream) if (playlist.nextpage == null) return@launch fetchMoreFromPlaylist(playlistId, playlist.nextpage) From d5e8e3ae7ca2d02659b00d677b5c001a5f53f91b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 18 Mar 2023 17:28:18 +0100 Subject: [PATCH 2/2] Remove fish files --- $HOME/fish/config.fish | 3 --- $HOME/fish/fish_variables | 31 ------------------------------- 2 files changed, 34 deletions(-) delete mode 100644 $HOME/fish/config.fish delete mode 100644 $HOME/fish/fish_variables diff --git a/$HOME/fish/config.fish b/$HOME/fish/config.fish deleted file mode 100644 index d714361fda..0000000000 --- a/$HOME/fish/config.fish +++ /dev/null @@ -1,3 +0,0 @@ -if status is-interactive - # Commands to run in interactive sessions can go here -end diff --git a/$HOME/fish/fish_variables b/$HOME/fish/fish_variables deleted file mode 100644 index 1a82b8adb9..0000000000 --- a/$HOME/fish/fish_variables +++ /dev/null @@ -1,31 +0,0 @@ -# This file contains fish universal variable definitions. -# VERSION: 3.0 -SETUVAR __fish_initialized:3400 -SETUVAR fish_color_autosuggestion:555\x1ebrblack -SETUVAR fish_color_cancel:\x2dr -SETUVAR fish_color_command:blue -SETUVAR fish_color_comment:red -SETUVAR fish_color_cwd:green -SETUVAR fish_color_cwd_root:red -SETUVAR fish_color_end:green -SETUVAR fish_color_error:brred -SETUVAR fish_color_escape:brcyan -SETUVAR fish_color_history_current:\x2d\x2dbold -SETUVAR fish_color_host:normal -SETUVAR fish_color_host_remote:yellow -SETUVAR fish_color_normal:normal -SETUVAR fish_color_operator:brcyan -SETUVAR fish_color_param:cyan -SETUVAR fish_color_quote:yellow -SETUVAR fish_color_redirection:cyan\x1e\x2d\x2dbold -SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack -SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack -SETUVAR fish_color_status:red -SETUVAR fish_color_user:brgreen -SETUVAR fish_color_valid_path:\x2d\x2dunderline -SETUVAR fish_key_bindings:fish_default_key_bindings -SETUVAR fish_pager_color_completion:normal -SETUVAR fish_pager_color_description:B3A06D\x1eyellow\x1e\x2di -SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline -SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan -SETUVAR fish_pager_color_selected_background:\x2dr