mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Android: Programmatically open/close cheat details
Only has an effect when using a narrow screen.
This commit is contained in:
@ -12,6 +12,8 @@ public class CheatsViewModel extends ViewModel
|
|||||||
|
|
||||||
private final MutableLiveData<Cheat> mSelectedCheat = new MutableLiveData<>(null);
|
private final MutableLiveData<Cheat> mSelectedCheat = new MutableLiveData<>(null);
|
||||||
|
|
||||||
|
private final MutableLiveData<Boolean> mOpenDetailsViewEvent = new MutableLiveData<>(false);
|
||||||
|
|
||||||
private PatchCheat[] mPatchCheats;
|
private PatchCheat[] mPatchCheats;
|
||||||
private ARCheat[] mARCheats;
|
private ARCheat[] mARCheats;
|
||||||
private GeckoCheat[] mGeckoCheats;
|
private GeckoCheat[] mGeckoCheats;
|
||||||
@ -76,6 +78,17 @@ public class CheatsViewModel extends ViewModel
|
|||||||
mSelectedCheat.setValue(cheat);
|
mSelectedCheat.setValue(cheat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Boolean> getOpenDetailsViewEvent()
|
||||||
|
{
|
||||||
|
return mOpenDetailsViewEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openDetailsView()
|
||||||
|
{
|
||||||
|
mOpenDetailsViewEvent.setValue(true);
|
||||||
|
mOpenDetailsViewEvent.setValue(false);
|
||||||
|
}
|
||||||
|
|
||||||
public Cheat[] getPatchCheats()
|
public Cheat[] getPatchCheats()
|
||||||
{
|
{
|
||||||
return mPatchCheats;
|
return mPatchCheats;
|
||||||
|
@ -50,6 +50,7 @@ public class CheatViewHolder extends ViewHolder
|
|||||||
public void onClick(View root)
|
public void onClick(View root)
|
||||||
{
|
{
|
||||||
mViewModel.setSelectedCheat(mCheat);
|
mViewModel.setSelectedCheat(mCheat);
|
||||||
|
mViewModel.openDetailsView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||||
|
@ -8,9 +8,12 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.slidingpanelayout.widget.SlidingPaneLayout;
|
||||||
|
|
||||||
import org.dolphinemu.dolphinemu.R;
|
import org.dolphinemu.dolphinemu.R;
|
||||||
|
import org.dolphinemu.dolphinemu.features.cheats.model.Cheat;
|
||||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||||
|
import org.dolphinemu.dolphinemu.ui.TwoPaneOnBackPressedCallback;
|
||||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||||
|
|
||||||
public class CheatsActivity extends AppCompatActivity
|
public class CheatsActivity extends AppCompatActivity
|
||||||
@ -22,6 +25,8 @@ public class CheatsActivity extends AppCompatActivity
|
|||||||
private int mRevision;
|
private int mRevision;
|
||||||
private CheatsViewModel mViewModel;
|
private CheatsViewModel mViewModel;
|
||||||
|
|
||||||
|
private SlidingPaneLayout mSlidingPaneLayout;
|
||||||
|
|
||||||
public static void launch(Context context, String gameId, int revision)
|
public static void launch(Context context, String gameId, int revision)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(context, CheatsActivity.class);
|
Intent intent = new Intent(context, CheatsActivity.class);
|
||||||
@ -47,6 +52,16 @@ public class CheatsActivity extends AppCompatActivity
|
|||||||
mViewModel.load(mGameId, mRevision);
|
mViewModel.load(mGameId, mRevision);
|
||||||
|
|
||||||
setContentView(R.layout.activity_cheats);
|
setContentView(R.layout.activity_cheats);
|
||||||
|
|
||||||
|
mSlidingPaneLayout = findViewById(R.id.sliding_pane_layout);
|
||||||
|
|
||||||
|
getOnBackPressedDispatcher().addCallback(this,
|
||||||
|
new TwoPaneOnBackPressedCallback(mSlidingPaneLayout));
|
||||||
|
|
||||||
|
mViewModel.getSelectedCheat().observe(this, this::onSelectedCheatChanged);
|
||||||
|
onSelectedCheatChanged(mViewModel.getSelectedCheat().getValue());
|
||||||
|
|
||||||
|
mViewModel.getOpenDetailsViewEvent().observe(this, this::openDetailsView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,4 +71,21 @@ public class CheatsActivity extends AppCompatActivity
|
|||||||
|
|
||||||
mViewModel.saveIfNeeded(mGameId, mRevision);
|
mViewModel.saveIfNeeded(mGameId, mRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onSelectedCheatChanged(Cheat selectedCheat)
|
||||||
|
{
|
||||||
|
boolean cheatSelected = selectedCheat != null;
|
||||||
|
|
||||||
|
if (!cheatSelected && mSlidingPaneLayout.isOpen())
|
||||||
|
mSlidingPaneLayout.close();
|
||||||
|
|
||||||
|
mSlidingPaneLayout.setLockMode(cheatSelected ?
|
||||||
|
SlidingPaneLayout.LOCK_MODE_UNLOCKED : SlidingPaneLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openDetailsView(boolean open)
|
||||||
|
{
|
||||||
|
if (open)
|
||||||
|
mSlidingPaneLayout.open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.dolphinemu.dolphinemu.ui;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.slidingpanelayout.widget.SlidingPaneLayout;
|
||||||
|
|
||||||
|
public class TwoPaneOnBackPressedCallback extends OnBackPressedCallback
|
||||||
|
implements SlidingPaneLayout.PanelSlideListener
|
||||||
|
{
|
||||||
|
private final SlidingPaneLayout mSlidingPaneLayout;
|
||||||
|
|
||||||
|
public TwoPaneOnBackPressedCallback(@NonNull SlidingPaneLayout slidingPaneLayout)
|
||||||
|
{
|
||||||
|
super(slidingPaneLayout.isSlideable() && slidingPaneLayout.isOpen());
|
||||||
|
mSlidingPaneLayout = slidingPaneLayout;
|
||||||
|
slidingPaneLayout.addPanelSlideListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed()
|
||||||
|
{
|
||||||
|
mSlidingPaneLayout.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPanelSlide(@NonNull View panel, float slideOffset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPanelOpened(@NonNull View panel)
|
||||||
|
{
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPanelClosed(@NonNull View panel)
|
||||||
|
{
|
||||||
|
setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user