From 6b68b76aed90f0a2a275774375dd899c0f5874ab Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 8 Aug 2020 12:25:18 +0200 Subject: [PATCH] Android: Remove redundant pause/unpause code --- .../activities/EmulationActivity.java | 23 ------------ .../dolphinemu/fragments/MenuFragment.java | 37 ++++++------------- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 87ee2f8e2a..2e5430d9ee 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -71,9 +71,6 @@ public final class EmulationActivity extends AppCompatActivity private Settings mSettings; - private MenuItem mPauseEmulationButton; - private MenuItem mUnpauseEmulationButton; - private boolean mDeviceHasTouchScreen; private boolean mMenuVisible; @@ -544,13 +541,11 @@ public final class EmulationActivity extends AppCompatActivity case MENU_ACTION_PAUSE_EMULATION: sUserPausedEmulation = true; NativeLibrary.PauseEmulation(); - showUnpauseEmulationButton(); return; case MENU_ACTION_UNPAUSE_EMULATION: sUserPausedEmulation = false; NativeLibrary.UnPauseEmulation(); - showPauseEmulationButton(); return; // Screenshot capturing @@ -653,28 +648,11 @@ public final class EmulationActivity extends AppCompatActivity } } - private void showPauseEmulationButton() - { - mUnpauseEmulationButton.setVisible(false); - mPauseEmulationButton.setVisible(true); - } - - private void showUnpauseEmulationButton() - { - mPauseEmulationButton.setVisible(false); - mUnpauseEmulationButton.setVisible(true); - } - public static boolean getHasUserPausedEmulation() { return sUserPausedEmulation; } - public static void setHasUserPausedEmulation(boolean value) - { - sUserPausedEmulation = value; - } - private void toggleJoystickRelCenter(boolean state) { final SharedPreferences.Editor editor = mPreferences.edit(); @@ -690,7 +668,6 @@ public final class EmulationActivity extends AppCompatActivity Rumble.setPhoneVibrator(state, this); } - private void editControlsPlacement() { if (mEmulationFragment.isConfiguringControls()) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java index 36eb22ffd5..6b46937667 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java @@ -72,10 +72,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener mPauseEmulation = options.findViewById(R.id.menu_pause_emulation); mUnpauseEmulation = options.findViewById(R.id.menu_unpause_emulation); - if (EmulationActivity.getHasUserPausedEmulation()) - { - showUnpauseEmulationButton(); - } + updatePauseUnpauseVisibility(); boolean enableSaveStates = ((EmulationActivity) getActivity()).getSettings() .getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE) @@ -126,16 +123,12 @@ public final class MenuFragment extends Fragment implements View.OnClickListener return rootView; } - private void showPauseEmulationButton() + private void updatePauseUnpauseVisibility() { - mUnpauseEmulation.setVisibility(View.GONE); - mPauseEmulation.setVisibility(View.VISIBLE); - } + boolean paused = EmulationActivity.getHasUserPausedEmulation(); - private void showUnpauseEmulationButton() - { - mPauseEmulation.setVisibility(View.GONE); - mUnpauseEmulation.setVisibility(View.VISIBLE); + mUnpauseEmulation.setVisibility(paused ? View.VISIBLE : View.GONE); + mPauseEmulation.setVisibility(paused ? View.GONE : View.VISIBLE); } @SuppressWarnings("WrongConstant") @@ -145,19 +138,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener int action = buttonsActionsMap.get(button.getId()); EmulationActivity activity = (EmulationActivity) requireActivity(); - if (action == EmulationActivity.MENU_ACTION_PAUSE_EMULATION) - { - EmulationActivity.setHasUserPausedEmulation(true); - NativeLibrary.PauseEmulation(); - showUnpauseEmulationButton(); - } - else if (action == EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION) - { - EmulationActivity.setHasUserPausedEmulation(false); - NativeLibrary.UnPauseEmulation(); - showPauseEmulationButton(); - } - else if (action == EmulationActivity.MENU_ACTION_OVERLAY_CONTROLS) + if (action == EmulationActivity.MENU_ACTION_OVERLAY_CONTROLS) { // We could use the button parameter as the anchor here, but this often results in a tiny menu // (because the button often is in the middle of the screen), so let's use mTitleText instead @@ -167,5 +148,11 @@ public final class MenuFragment extends Fragment implements View.OnClickListener { activity.handleMenuAction(action); } + + if (action == EmulationActivity.MENU_ACTION_PAUSE_EMULATION || + action == EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION) + { + updatePauseUnpauseVisibility(); + } } }