mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Android: Implement basic read-only cheats list
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.model;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class ARCheat implements Cheat
|
||||
{
|
||||
@Keep
|
||||
private final long mPointer;
|
||||
|
||||
@Keep
|
||||
private ARCheat(long pointer)
|
||||
{
|
||||
mPointer = pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public native void finalize();
|
||||
|
||||
@NonNull
|
||||
public native String getName();
|
||||
|
||||
@NonNull
|
||||
public static native ARCheat[] loadCodes(String gameId, int revision);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.model;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public interface Cheat
|
||||
{
|
||||
@NonNull
|
||||
String getName();
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.model;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class CheatsViewModel extends ViewModel
|
||||
{
|
||||
private boolean mLoaded = false;
|
||||
|
||||
private PatchCheat[] mPatchCheats;
|
||||
private ARCheat[] mARCheats;
|
||||
private GeckoCheat[] mGeckoCheats;
|
||||
|
||||
public void load(String gameID, int revision)
|
||||
{
|
||||
if (mLoaded)
|
||||
return;
|
||||
|
||||
mPatchCheats = PatchCheat.loadCodes(gameID, revision);
|
||||
mARCheats = ARCheat.loadCodes(gameID, revision);
|
||||
mGeckoCheats = GeckoCheat.loadCodes(gameID, revision);
|
||||
|
||||
mLoaded = true;
|
||||
}
|
||||
|
||||
public Cheat[] getPatchCheats()
|
||||
{
|
||||
return mPatchCheats;
|
||||
}
|
||||
|
||||
public ARCheat[] getARCheats()
|
||||
{
|
||||
return mARCheats;
|
||||
}
|
||||
|
||||
public Cheat[] getGeckoCheats()
|
||||
{
|
||||
return mGeckoCheats;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.model;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class GeckoCheat implements Cheat
|
||||
{
|
||||
@Keep
|
||||
private final long mPointer;
|
||||
|
||||
@Keep
|
||||
private GeckoCheat(long pointer)
|
||||
{
|
||||
mPointer = pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public native void finalize();
|
||||
|
||||
@NonNull
|
||||
public native String getName();
|
||||
|
||||
@NonNull
|
||||
public static native GeckoCheat[] loadCodes(String gameId, int revision);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.model;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class PatchCheat implements Cheat
|
||||
{
|
||||
@Keep
|
||||
private final long mPointer;
|
||||
|
||||
@Keep
|
||||
private PatchCheat(long pointer)
|
||||
{
|
||||
mPointer = pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public native void finalize();
|
||||
|
||||
@NonNull
|
||||
public native String getName();
|
||||
|
||||
@NonNull
|
||||
public static native PatchCheat[] loadCodes(String gameId, int revision);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||
import org.dolphinemu.dolphinemu.ui.DividerItemDecoration;
|
||||
|
||||
public class CheatListFragment extends Fragment
|
||||
{
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.fragment_cheat_list, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
RecyclerView recyclerView = view.findViewById(R.id.cheat_list);
|
||||
|
||||
CheatsActivity activity = (CheatsActivity) requireActivity();
|
||||
CheatsViewModel viewModel = new ViewModelProvider(activity).get(CheatsViewModel.class);
|
||||
|
||||
recyclerView.setAdapter(new CheatsAdapter(viewModel));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(activity, null));
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.ui;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.Cheat;
|
||||
|
||||
public class CheatViewHolder extends ViewHolder
|
||||
{
|
||||
private TextView mName;
|
||||
|
||||
public CheatViewHolder(@NonNull View itemView)
|
||||
{
|
||||
super(itemView);
|
||||
|
||||
mName = itemView.findViewById(R.id.text_name);
|
||||
}
|
||||
|
||||
public void bind(Cheat item)
|
||||
{
|
||||
mName.setText(item.getName());
|
||||
}
|
||||
}
|
@ -4,8 +4,14 @@ package org.dolphinemu.dolphinemu.features.cheats.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||
|
||||
public class CheatsActivity extends AppCompatActivity
|
||||
{
|
||||
@ -19,4 +25,23 @@ public class CheatsActivity extends AppCompatActivity
|
||||
intent.putExtra(ARG_REVISION, revision);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
MainPresenter.skipRescanningLibrary();
|
||||
|
||||
Intent intent = getIntent();
|
||||
String gameId = intent.getStringExtra(ARG_GAME_ID);
|
||||
int revision = intent.getIntExtra(ARG_REVISION, 0);
|
||||
|
||||
setTitle(getString(R.string.cheats_with_game_id, gameId));
|
||||
|
||||
CheatsViewModel viewModel = new ViewModelProvider(this).get(CheatsViewModel.class);
|
||||
viewModel.load(gameId, revision);
|
||||
|
||||
setContentView(R.layout.activity_cheats);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.ui;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.Cheat;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||
|
||||
public class CheatsAdapter extends RecyclerView.Adapter<CheatViewHolder>
|
||||
{
|
||||
private final CheatsViewModel mViewModel;
|
||||
|
||||
public CheatsAdapter(CheatsViewModel viewModel)
|
||||
{
|
||||
mViewModel = viewModel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CheatViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
View view = inflater.inflate(R.layout.list_item_cheat, parent, false);
|
||||
return new CheatViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CheatViewHolder holder, int position)
|
||||
{
|
||||
holder.bind(getItemAt(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return mViewModel.getARCheats().length + mViewModel.getGeckoCheats().length +
|
||||
mViewModel.getPatchCheats().length;
|
||||
}
|
||||
|
||||
private Cheat getItemAt(int position)
|
||||
{
|
||||
Cheat[] patchCheats = mViewModel.getPatchCheats();
|
||||
if (position < patchCheats.length)
|
||||
{
|
||||
return patchCheats[position];
|
||||
}
|
||||
position -= patchCheats.length;
|
||||
|
||||
Cheat[] arCheats = mViewModel.getARCheats();
|
||||
if (position < arCheats.length)
|
||||
{
|
||||
return arCheats[position];
|
||||
}
|
||||
position -= arCheats.length;
|
||||
|
||||
Cheat[] geckoCheats = mViewModel.getGeckoCheats();
|
||||
if (position < geckoCheats.length)
|
||||
{
|
||||
return geckoCheats[position];
|
||||
}
|
||||
position -= geckoCheats.length;
|
||||
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/cheat_list"
|
||||
android:name="org.dolphinemu.dolphinemu.features.cheats.ui.CheatListFragment" />
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/cheat_list" />
|
23
Source/Android/app/src/main/res/layout/list_item_cheat.xml
Normal file
23
Source/Android/app/src/main/res/layout/list_item_cheat.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.AppCompat.Headline"
|
||||
android:textSize="16sp"
|
||||
tools:text="Hyrule Field Speed Hack"
|
||||
android:layout_margin="@dimen/spacing_large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Reference in New Issue
Block a user