@@ -291,12 +291,14 @@ private void showSettingsDialog() {
291291 TextView tabDashcam = dialog .findViewById (R .id .tabDashcam );
292292 TextView tabOptik = dialog .findViewById (R .id .tabOptik );
293293 TextView tabCredits = dialog .findViewById (R .id .tabCredits );
294+ TextView [] settingsTabs = {tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits };
294295 View sectionUpdate = dialog .findViewById (R .id .sectionUpdate );
295296 View sectionSettings = dialog .findViewById (R .id .sectionSettings );
296297 View sectionSignalCamera = dialog .findViewById (R .id .sectionSignalCamera );
297298 View sectionDashcam = dialog .findViewById (R .id .sectionDashcam );
298299 View sectionOptik = dialog .findViewById (R .id .sectionOptik );
299300 View sectionCredits = dialog .findViewById (R .id .sectionCredits );
301+ View [] settingsSections = {sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits };
300302 View sectionDevTools = dialog .findViewById (R .id .sectionDevTools );
301303 View accentRow = dialog .findViewById (R .id .rowAccentColor );
302304 View accentPreview = dialog .findViewById (R .id .viewAccentPreview );
@@ -350,39 +352,11 @@ private void showSettingsDialog() {
350352 DashcamEventOverlayService .showConfirmation (MainActivity .this ));
351353 }
352354
353- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
354- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 1 );
355- appearanceController .reapplyForActiveTab (1 );
356- tabUpdate .setOnClickListener (v -> {
357- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
358- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 0 );
359- appearanceController .reapplyForActiveTab (0 );
360- });
361- tabSettings .setOnClickListener (v -> {
362- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
363- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 1 );
364- appearanceController .reapplyForActiveTab (1 );
365- });
366- tabSignalCamera .setOnClickListener (v -> {
367- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
368- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 2 );
369- appearanceController .reapplyForActiveTab (2 );
370- });
371- tabDashcam .setOnClickListener (v -> {
372- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
373- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 3 );
374- appearanceController .reapplyForActiveTab (3 );
375- });
376- tabOptik .setOnClickListener (v -> {
377- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
378- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 4 );
379- appearanceController .reapplyForActiveTab (4 );
380- });
381- tabCredits .setOnClickListener (v -> {
382- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
383- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 5 );
384- appearanceController .reapplyForActiveTab (5 );
385- });
355+ switchSettingsTab (settingsTabs , settingsSections , 1 );
356+ for (int i = 0 ; i < settingsTabs .length ; i ++) {
357+ final int tabIndex = i ;
358+ settingsTabs [i ].setOnClickListener (v -> switchSettingsTab (settingsTabs , settingsSections , tabIndex ));
359+ }
386360
387361 TextView tvVersion = dialog .findViewById (R .id .tvDialogVersion );
388362 TextView tvBeta = dialog .findViewById (R .id .tvDialogVersionBeta );
@@ -407,9 +381,7 @@ private void showSettingsDialog() {
407381 if (sectionDevTools != null ) {
408382 sectionDevTools .setVisibility (View .VISIBLE );
409383 }
410- bindSettingsTab (tabUpdate , tabSettings , tabSignalCamera , tabDashcam , tabOptik , tabCredits ,
411- sectionUpdate , sectionSettings , sectionSignalCamera , sectionDashcam , sectionOptik , sectionCredits , 1 );
412- appearanceController .reapplyForActiveTab (1 );
384+ switchSettingsTab (settingsTabs , settingsSections , 1 );
413385 Toast .makeText (this , R .string .settings_dev_unlocked , Toast .LENGTH_SHORT ).show ();
414386 };
415387 tvVersion .setOnClickListener (unlockDevListener );
@@ -446,23 +418,12 @@ private void showSettingsDialog() {
446418 }
447419 }
448420
449- private void bindSettingsTab (
450- TextView tabUpdate , TextView tabSettings , TextView tabSignalCamera , TextView tabDashcam , TextView tabOptik , TextView tabCredits ,
451- View sectionUpdate , View sectionSettings , View sectionSignalCamera , View sectionDashcam , View sectionOptik , View sectionCredits ,
452- int active
453- ) {
454- sectionUpdate .setVisibility (active == 0 ? View .VISIBLE : View .GONE );
455- sectionSettings .setVisibility (active == 1 ? View .VISIBLE : View .GONE );
456- sectionSignalCamera .setVisibility (active == 2 ? View .VISIBLE : View .GONE );
457- sectionDashcam .setVisibility (active == 3 ? View .VISIBLE : View .GONE );
458- sectionOptik .setVisibility (active == 4 ? View .VISIBLE : View .GONE );
459- sectionCredits .setVisibility (active == 5 ? View .VISIBLE : View .GONE );
460- styleSettingsTab (tabUpdate , active == 0 );
461- styleSettingsTab (tabSettings , active == 1 );
462- styleSettingsTab (tabSignalCamera , active == 2 );
463- styleSettingsTab (tabDashcam , active == 3 );
464- styleSettingsTab (tabOptik , active == 4 );
465- styleSettingsTab (tabCredits , active == 5 );
421+ private void switchSettingsTab (TextView [] tabs , View [] sections , int activeIndex ) {
422+ for (int i = 0 ; i < tabs .length ; i ++) {
423+ sections [i ].setVisibility (i == activeIndex ? View .VISIBLE : View .GONE );
424+ styleSettingsTab (tabs [i ], i == activeIndex );
425+ }
426+ appearanceController .reapplyForActiveTab (activeIndex );
466427 }
467428
468429 private void styleSettingsTab (TextView tab , boolean active ) {
0 commit comments