From 62f0abee473735d9c6e2f83874bc2241ef0ceaa8 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sat, 19 Aug 2023 21:57:15 +0200 Subject: [PATCH] Simplify MainActivity.tabSelected(MenuItem) Rename variables and skip iterations if kiosk was found. --- .../java/org/schabi/newpipe/MainActivity.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index ee2bb3f05..ea047ce61 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -219,14 +219,14 @@ public class MainActivity extends AppCompatActivity { final int currentServiceId = ServiceHelper.getSelectedServiceId(this); final StreamingService service = NewPipe.getService(currentServiceId); - int kioskId = 0; + int kioskMenuItemId = 0; for (final String ks : service.getKioskList().getAvailableKiosks()) { drawerLayoutBinding.navigation.getMenu() - .add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator + .add(R.id.menu_tabs_group, kioskMenuItemId, 0, KioskTranslator .getTranslatedKioskName(ks, this)) .setIcon(KioskTranslator.getKioskIcon(ks)); - kioskId++; + kioskMenuItemId++; } drawerLayoutBinding.navigation.getMenu() @@ -306,20 +306,16 @@ public class MainActivity extends AppCompatActivity { NavigationHelper.openStatisticFragment(getSupportFragmentManager()); break; default: - final int currentServiceId = ServiceHelper.getSelectedServiceId(this); - final StreamingService service = NewPipe.getService(currentServiceId); - String serviceName = ""; - - int kioskId = 0; - for (final String ks : service.getKioskList().getAvailableKiosks()) { - if (kioskId == item.getItemId()) { - serviceName = ks; + final StreamingService currentService = ServiceHelper.getSelectedService(this); + int kioskMenuItemId = 0; + for (final String kioskId : currentService.getKioskList().getAvailableKiosks()) { + if (kioskMenuItemId == item.getItemId()) { + NavigationHelper.openKioskFragment(getSupportFragmentManager(), + currentService.getServiceId(), kioskId); + break; } - kioskId++; + kioskMenuItemId++; } - - NavigationHelper.openKioskFragment(getSupportFragmentManager(), currentServiceId, - serviceName); break; } }