From ee5e0e13b7a2c484e95da2dccaae9db505dc8a0e Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Wed, 16 Mar 2022 15:44:34 +0100 Subject: [PATCH] Made ``onClick`` less (cognitive) complex --- .../org/schabi/newpipe/player/Player.java | 31 +++------ app/src/main/res/layout/player.xml | 63 ++++++++++--------- 2 files changed, 41 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index c06e2f2d4..e8d6cff18 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -545,11 +545,15 @@ public final class Player implements gestureDetector = new GestureDetectorCompat(context, playerGestureListener); binding.getRoot().setOnTouchListener(playerGestureListener); - binding.queueButton.setOnClickListener(this); - binding.segmentsButton.setOnClickListener(this); - binding.repeatButton.setOnClickListener(this); - binding.shuffleButton.setOnClickListener(this); - binding.addToPlaylistButton.setOnClickListener(this); + binding.queueButton.setOnClickListener(v -> onQueueClicked()); + binding.segmentsButton.setOnClickListener(v -> onSegmentsClicked()); + binding.repeatButton.setOnClickListener(v -> onRepeatClicked()); + binding.shuffleButton.setOnClickListener(v -> onShuffleClicked()); + binding.addToPlaylistButton.setOnClickListener(v -> { + if (getParentActivity() != null) { + onAddToPlaylistClicked(getParentActivity().getSupportFragmentManager()); + } + }); binding.playPauseButton.setOnClickListener(this); binding.playPreviousButton.setOnClickListener(this); @@ -3727,23 +3731,6 @@ public final class Player implements playPrevious(); } else if (v.getId() == binding.playNextButton.getId()) { playNext(); - } else if (v.getId() == binding.queueButton.getId()) { - onQueueClicked(); - return; - } else if (v.getId() == binding.segmentsButton.getId()) { - onSegmentsClicked(); - return; - } else if (v.getId() == binding.repeatButton.getId()) { - onRepeatClicked(); - return; - } else if (v.getId() == binding.shuffleButton.getId()) { - onShuffleClicked(); - return; - } else if (v.getId() == binding.addToPlaylistButton.getId()) { - if (getParentActivity() != null) { - onAddToPlaylistClicked(getParentActivity().getSupportFragmentManager()); - } - return; } else if (v.getId() == binding.moreOptionsButton.getId()) { onMoreOptionsClicked(); } else if (v.getId() == binding.share.getId()) { diff --git a/app/src/main/res/layout/player.xml b/app/src/main/res/layout/player.xml index f545fc0b9..d748942e0 100644 --- a/app/src/main/res/layout/player.xml +++ b/app/src/main/res/layout/player.xml @@ -563,37 +563,6 @@ android:textColor="@android:color/white" android:visibility="gone" /> - - - - + + + + +