Skip to content

Commit ee5e0e1

Browse files
committed
Made onClick less (cognitive) complex
1 parent 30a8f25 commit ee5e0e1

2 files changed

Lines changed: 40 additions & 52 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,15 @@ private void initListeners() {
545545
gestureDetector = new GestureDetectorCompat(context, playerGestureListener);
546546
binding.getRoot().setOnTouchListener(playerGestureListener);
547547

548-
binding.queueButton.setOnClickListener(this);
549-
binding.segmentsButton.setOnClickListener(this);
550-
binding.repeatButton.setOnClickListener(this);
551-
binding.shuffleButton.setOnClickListener(this);
552-
binding.addToPlaylistButton.setOnClickListener(this);
548+
binding.queueButton.setOnClickListener(v -> onQueueClicked());
549+
binding.segmentsButton.setOnClickListener(v -> onSegmentsClicked());
550+
binding.repeatButton.setOnClickListener(v -> onRepeatClicked());
551+
binding.shuffleButton.setOnClickListener(v -> onShuffleClicked());
552+
binding.addToPlaylistButton.setOnClickListener(v -> {
553+
if (getParentActivity() != null) {
554+
onAddToPlaylistClicked(getParentActivity().getSupportFragmentManager());
555+
}
556+
});
553557

554558
binding.playPauseButton.setOnClickListener(this);
555559
binding.playPreviousButton.setOnClickListener(this);
@@ -3727,23 +3731,6 @@ public void onClick(final View v) {
37273731
playPrevious();
37283732
} else if (v.getId() == binding.playNextButton.getId()) {
37293733
playNext();
3730-
} else if (v.getId() == binding.queueButton.getId()) {
3731-
onQueueClicked();
3732-
return;
3733-
} else if (v.getId() == binding.segmentsButton.getId()) {
3734-
onSegmentsClicked();
3735-
return;
3736-
} else if (v.getId() == binding.repeatButton.getId()) {
3737-
onRepeatClicked();
3738-
return;
3739-
} else if (v.getId() == binding.shuffleButton.getId()) {
3740-
onShuffleClicked();
3741-
return;
3742-
} else if (v.getId() == binding.addToPlaylistButton.getId()) {
3743-
if (getParentActivity() != null) {
3744-
onAddToPlaylistClicked(getParentActivity().getSupportFragmentManager());
3745-
}
3746-
return;
37473734
} else if (v.getId() == binding.moreOptionsButton.getId()) {
37483735
onMoreOptionsClicked();
37493736
} else if (v.getId() == binding.share.getId()) {

app/src/main/res/layout/player.xml

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -564,79 +564,80 @@
564564
android:visibility="gone" />
565565

566566
<androidx.appcompat.widget.AppCompatImageButton
567-
android:id="@+id/itemsListClose"
567+
android:id="@+id/repeatButton"
568568
android:layout_width="50dp"
569569
android:layout_height="50dp"
570-
android:layout_alignParentEnd="true"
570+
android:layout_alignParentStart="true"
571+
android:layout_alignParentLeft="true"
571572
android:layout_centerVertical="true"
572-
android:layout_marginEnd="40dp"
573+
android:layout_marginStart="40dp"
574+
android:layout_marginLeft="40dp"
573575
android:background="?attr/selectableItemBackgroundBorderless"
574576
android:clickable="true"
575-
android:contentDescription="@string/close"
576577
android:focusable="true"
577578
android:padding="10dp"
578579
android:scaleType="fitXY"
579-
app:srcCompat="@drawable/ic_close"
580-
app:tint="@color/white" />
580+
android:tint="?attr/colorAccent"
581+
app:srcCompat="@drawable/exo_controls_repeat_off"
582+
tools:ignore="ContentDescription,RtlHardcoded" />
581583

582584
<androidx.appcompat.widget.AppCompatImageButton
583-
android:id="@+id/addToPlaylistButton"
585+
android:id="@+id/shuffleButton"
584586
android:layout_width="50dp"
585587
android:layout_height="50dp"
586588
android:layout_centerVertical="true"
587-
android:layout_toLeftOf="@+id/itemsListClose"
589+
android:layout_toRightOf="@id/repeatButton"
588590
android:background="?attr/selectableItemBackgroundBorderless"
589591
android:clickable="true"
590592
android:focusable="true"
591593
android:padding="10dp"
592594
android:scaleType="fitXY"
593595
android:tint="?attr/colorAccent"
594-
app:srcCompat="@drawable/ic_playlist_add"
596+
app:srcCompat="@drawable/ic_shuffle"
595597
tools:ignore="ContentDescription,RtlHardcoded" />
596598

599+
<androidx.appcompat.widget.AppCompatTextView
600+
android:id="@+id/itemsListHeaderDuration"
601+
style="@style/TextAppearance.AppCompat.Medium"
602+
android:layout_width="wrap_content"
603+
android:layout_height="wrap_content"
604+
android:layout_centerVertical="true"
605+
android:layout_toStartOf="@id/addToPlaylistButton"
606+
android:layout_toEndOf="@id/shuffleButton"
607+
android:gravity="center"
608+
android:textColor="@android:color/white" />
609+
597610
<androidx.appcompat.widget.AppCompatImageButton
598-
android:id="@+id/repeatButton"
611+
android:id="@+id/addToPlaylistButton"
599612
android:layout_width="50dp"
600613
android:layout_height="50dp"
601-
android:layout_alignParentStart="true"
602-
android:layout_alignParentLeft="true"
603614
android:layout_centerVertical="true"
604-
android:layout_marginStart="40dp"
605-
android:layout_marginLeft="40dp"
615+
android:layout_toLeftOf="@+id/itemsListClose"
606616
android:background="?attr/selectableItemBackgroundBorderless"
607617
android:clickable="true"
608618
android:focusable="true"
609619
android:padding="10dp"
610620
android:scaleType="fitXY"
611621
android:tint="?attr/colorAccent"
612-
app:srcCompat="@drawable/exo_controls_repeat_off"
622+
app:srcCompat="@drawable/ic_playlist_add"
613623
tools:ignore="ContentDescription,RtlHardcoded" />
614624

615625
<androidx.appcompat.widget.AppCompatImageButton
616-
android:id="@+id/shuffleButton"
626+
android:id="@+id/itemsListClose"
617627
android:layout_width="50dp"
618628
android:layout_height="50dp"
629+
android:layout_alignParentEnd="true"
619630
android:layout_centerVertical="true"
620-
android:layout_toRightOf="@id/repeatButton"
631+
android:layout_marginEnd="40dp"
621632
android:background="?attr/selectableItemBackgroundBorderless"
622633
android:clickable="true"
634+
android:contentDescription="@string/close"
623635
android:focusable="true"
624636
android:padding="10dp"
625637
android:scaleType="fitXY"
626-
android:tint="?attr/colorAccent"
627-
app:srcCompat="@drawable/ic_shuffle"
628-
tools:ignore="ContentDescription,RtlHardcoded" />
638+
app:srcCompat="@drawable/ic_close"
639+
app:tint="@color/white" />
629640

630-
<androidx.appcompat.widget.AppCompatTextView
631-
android:id="@+id/itemsListHeaderDuration"
632-
style="@style/TextAppearance.AppCompat.Medium"
633-
android:layout_width="wrap_content"
634-
android:layout_height="wrap_content"
635-
android:layout_centerVertical="true"
636-
android:layout_toStartOf="@id/addToPlaylistButton"
637-
android:layout_toEndOf="@id/shuffleButton"
638-
android:gravity="center"
639-
android:textColor="@android:color/white" />
640641
</RelativeLayout>
641642

642643
<androidx.recyclerview.widget.RecyclerView

0 commit comments

Comments
 (0)