Android: Refactor handleMenuTag
It was a bit silly having four functions for effectively the same thing in all of SettingsFragmentView, SettingsFragment, SettingsActivityView, SettingsActivity, and SettingsActivityPresenter. With this change, we split on the four MenuTag types in SettingsActivityPresenter instead of in SettingsAdapter.
This commit is contained in:
parent
8acc39cc3f
commit
b827b155a0
|
@ -305,27 +305,9 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSerialPort1SettingChanged(MenuTag menuTag, int value)
|
||||
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
|
||||
{
|
||||
mPresenter.onSerialPort1SettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGcPadSettingChanged(MenuTag key, int value)
|
||||
{
|
||||
mPresenter.onGcPadSettingChanged(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiimoteSettingChanged(MenuTag section, int value)
|
||||
{
|
||||
mPresenter.onWiimoteSettingChanged(section, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtensionSettingChanged(MenuTag menuTag, int value)
|
||||
{
|
||||
mPresenter.onExtensionSettingChanged(menuTag, value);
|
||||
mPresenter.onMenuTagAction(menuTag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ package org.dolphinemu.dolphinemu.features.settings.ui;
|
|||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ComponentActivity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
|
@ -128,47 +129,50 @@ public final class SettingsActivityPresenter
|
|||
return mShouldSave;
|
||||
}
|
||||
|
||||
public void onSerialPort1SettingChanged(MenuTag key, int value)
|
||||
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
|
||||
{
|
||||
if (value != 0 && value != 255) // Not disabled or dummy
|
||||
if (menuTag.isSerialPort1Menu())
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsFragmentPresenter.ARG_SERIALPORT1_TYPE, value);
|
||||
mView.showSettingsFragment(key, bundle, true, mGameId);
|
||||
if (value != 0 && value != 255) // Not disabled or dummy
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsFragmentPresenter.ARG_SERIALPORT1_TYPE, value);
|
||||
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onGcPadSettingChanged(MenuTag key, int value)
|
||||
{
|
||||
if (value != 0) // Not disabled
|
||||
if (menuTag.isGCPadMenu())
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
|
||||
mView.showSettingsFragment(key, bundle, true, mGameId);
|
||||
if (value != 0) // Not disabled
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
|
||||
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onWiimoteSettingChanged(MenuTag menuTag, int value)
|
||||
{
|
||||
switch (value)
|
||||
if (menuTag.isWiimoteMenu())
|
||||
{
|
||||
case 1:
|
||||
mView.showSettingsFragment(menuTag, null, true, mGameId);
|
||||
break;
|
||||
switch (value)
|
||||
{
|
||||
case 1:
|
||||
mView.showSettingsFragment(menuTag, null, true, mGameId);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mView.showToastMessage(mActivity.getString(R.string.make_sure_continuous_scan_enabled));
|
||||
break;
|
||||
case 2:
|
||||
mView.showToastMessage(mActivity.getString(R.string.make_sure_continuous_scan_enabled));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onExtensionSettingChanged(MenuTag menuTag, int value)
|
||||
{
|
||||
if (value != 0) // None
|
||||
if (menuTag.isWiimoteExtensionMenu())
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
|
||||
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
|
||||
if (value != 0) // None
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
|
||||
mView.showSettingsFragment(menuTag, bundle, true, mGameId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ package org.dolphinemu.dolphinemu.features.settings.ui;
|
|||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
/**
|
||||
|
@ -59,40 +61,13 @@ public interface SettingsActivityView
|
|||
void onSettingChanged();
|
||||
|
||||
/**
|
||||
* Called by a containing Fragment to tell the containing Activity that the Serial Port 1 setting
|
||||
* was modified.
|
||||
* Called by a containing Fragment to tell the containing Activity that the user wants to open the
|
||||
* MenuTag associated with a setting.
|
||||
*
|
||||
* @param menuTag Identifier for the SerialPort that was modified.
|
||||
* @param value New setting for the SerialPort.
|
||||
* @param menuTag The MenuTag to open.
|
||||
* @param value The current value of the associated setting.
|
||||
*/
|
||||
void onSerialPort1SettingChanged(MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Called by a containing Fragment to tell the containing Activity that a GCPad's setting
|
||||
* was modified.
|
||||
*
|
||||
* @param menuTag Identifier for the GCPad that was modified.
|
||||
* @param value New setting for the GCPad.
|
||||
*/
|
||||
void onGcPadSettingChanged(MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Called by a containing Fragment to tell the containing Activity that a Wiimote's setting
|
||||
* was modified.
|
||||
*
|
||||
* @param menuTag Identifier for Wiimote that was modified.
|
||||
* @param value New setting for the Wiimote.
|
||||
*/
|
||||
void onWiimoteSettingChanged(MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Called by a containing Fragment to tell the containing Activity that an extension setting
|
||||
* was modified.
|
||||
*
|
||||
* @param menuTag Identifier for the extension that was modified.
|
||||
* @param value New setting for the extension.
|
||||
*/
|
||||
void onExtensionSettingChanged(MenuTag menuTag, int value);
|
||||
void onMenuTagAction(@NonNull MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Show loading dialog while loading the settings
|
||||
|
|
|
@ -467,30 +467,9 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
}
|
||||
}
|
||||
|
||||
public void handleMenuTag(MenuTag menuTag, int value)
|
||||
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
|
||||
{
|
||||
if (menuTag != null)
|
||||
{
|
||||
if (menuTag.isSerialPort1Menu())
|
||||
{
|
||||
mView.onSerialPort1SettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
if (menuTag.isGCPadMenu())
|
||||
{
|
||||
mView.onGcPadSettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
if (menuTag.isWiimoteMenu())
|
||||
{
|
||||
mView.onWiimoteSettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
if (menuTag.isWiimoteExtensionMenu())
|
||||
{
|
||||
mView.onExtensionSettingChanged(menuTag, value);
|
||||
}
|
||||
}
|
||||
mView.onMenuTagAction(menuTag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -226,27 +226,9 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSerialPort1SettingChanged(MenuTag menuTag, int value)
|
||||
public void onMenuTagAction(@NonNull MenuTag menuTag, int value)
|
||||
{
|
||||
mActivity.onSerialPort1SettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGcPadSettingChanged(MenuTag menuTag, int value)
|
||||
{
|
||||
mActivity.onGcPadSettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiimoteSettingChanged(MenuTag menuTag, int value)
|
||||
{
|
||||
mActivity.onWiimoteSettingChanged(menuTag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtensionSettingChanged(MenuTag menuTag, int value)
|
||||
{
|
||||
mActivity.onExtensionSettingChanged(menuTag, value);
|
||||
mActivity.onMenuTagAction(menuTag, value);
|
||||
}
|
||||
|
||||
private void setInsets()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
package org.dolphinemu.dolphinemu.features.settings.ui;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
@ -72,35 +73,11 @@ public interface SettingsFragmentView
|
|||
void onSettingChanged();
|
||||
|
||||
/**
|
||||
* Called by a containing Fragment to tell the containing Activity that the Serial Port 1 setting
|
||||
* was modified.
|
||||
* Have the fragment tell the containing Activity that the user wants to open the MenuTag
|
||||
* associated with a setting.
|
||||
*
|
||||
* @param menuTag Identifier for the SerialPort that was modified.
|
||||
* @param value New setting for the SerialPort.
|
||||
* @param menuTag The MenuTag to open.
|
||||
* @param value The current value of the associated setting.
|
||||
*/
|
||||
void onSerialPort1SettingChanged(MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Have the fragment tell the containing Activity that a GCPad's setting was modified.
|
||||
*
|
||||
* @param menuTag Identifier for the GCPad that was modified.
|
||||
* @param value New setting for the GCPad.
|
||||
*/
|
||||
void onGcPadSettingChanged(MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Have the fragment tell the containing Activity that a Wiimote's setting was modified.
|
||||
*
|
||||
* @param menuTag Identifier for Wiimote that was modified.
|
||||
* @param value New setting for the Wiimote.
|
||||
*/
|
||||
void onWiimoteSettingChanged(MenuTag menuTag, int value);
|
||||
|
||||
/**
|
||||
* Have the fragment tell the containing Activity that an extension setting was modified.
|
||||
*
|
||||
* @param menuTag Identifier for the extension that was modified.
|
||||
* @param value New setting for the extension.
|
||||
*/
|
||||
void onExtensionSettingChanged(MenuTag menuTag, int value);
|
||||
void onMenuTagAction(@NonNull MenuTag menuTag, int value);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public final class SingleChoiceViewHolder extends SettingViewHolder
|
|||
final MenuTag finalMenuTag = menuTag;
|
||||
final Function<Settings, Integer> finalGetSelectedValue = getSelectedValue;
|
||||
mBinding.buttonMoreSettings.setOnClickListener((view) ->
|
||||
adapter.handleMenuTag(finalMenuTag, finalGetSelectedValue.apply(settings)));
|
||||
adapter.onMenuTagAction(finalMenuTag, finalGetSelectedValue.apply(settings)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue