mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-01 19:13:38 +00:00
Android: Add headers to cheat list
This commit is contained in:
parent
109aef4b81
commit
6934b9a21d
@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.ui;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.Cheat;
|
||||
|
||||
public class CheatItem
|
||||
{
|
||||
public static final int TYPE_CHEAT = 0;
|
||||
public static final int TYPE_HEADER = 1;
|
||||
|
||||
private final @Nullable Cheat mCheat;
|
||||
private final int mString;
|
||||
private final int mType;
|
||||
|
||||
public CheatItem(@NonNull Cheat cheat)
|
||||
{
|
||||
mCheat = cheat;
|
||||
mString = 0;
|
||||
mType = TYPE_CHEAT;
|
||||
}
|
||||
|
||||
public CheatItem(int type, int string)
|
||||
{
|
||||
mCheat = null;
|
||||
mString = string;
|
||||
mType = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Cheat getCheat()
|
||||
{
|
||||
return mCheat;
|
||||
}
|
||||
|
||||
public int getString()
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.cheats.ui;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||
|
||||
public abstract class CheatItemViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
public CheatItemViewHolder(@NonNull View itemView)
|
||||
{
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
public abstract void bind(CheatsViewModel viewModel, CheatItem item, int position);
|
||||
}
|
@ -14,7 +14,7 @@ import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.Cheat;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||
|
||||
public class CheatViewHolder extends ViewHolder
|
||||
public class CheatViewHolder extends CheatItemViewHolder
|
||||
implements View.OnClickListener, CompoundButton.OnCheckedChangeListener
|
||||
{
|
||||
private final View mRoot;
|
||||
@ -34,17 +34,17 @@ public class CheatViewHolder extends ViewHolder
|
||||
mCheckbox = itemView.findViewById(R.id.checkbox);
|
||||
}
|
||||
|
||||
public void bind(CheatsViewModel viewModel, Cheat item, int position)
|
||||
public void bind(CheatsViewModel viewModel, CheatItem item, int position)
|
||||
{
|
||||
mCheckbox.setOnCheckedChangeListener(null);
|
||||
|
||||
mName.setText(item.getName());
|
||||
mCheckbox.setChecked(item.getEnabled());
|
||||
|
||||
mViewModel = viewModel;
|
||||
mCheat = item;
|
||||
mCheat = item.getCheat();
|
||||
mPosition = position;
|
||||
|
||||
mName.setText(mCheat.getName());
|
||||
mCheckbox.setChecked(mCheat.getEnabled());
|
||||
|
||||
mRoot.setOnClickListener(this);
|
||||
mCheckbox.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ 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>
|
||||
public class CheatsAdapter extends RecyclerView.Adapter<CheatItemViewHolder>
|
||||
{
|
||||
private final CheatsViewModel mViewModel;
|
||||
|
||||
@ -31,15 +31,25 @@ public class CheatsAdapter extends RecyclerView.Adapter<CheatViewHolder>
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CheatViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
|
||||
public CheatItemViewHolder 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);
|
||||
|
||||
switch (viewType)
|
||||
{
|
||||
case CheatItem.TYPE_CHEAT:
|
||||
View cheatView = inflater.inflate(R.layout.list_item_cheat, parent, false);
|
||||
return new CheatViewHolder(cheatView);
|
||||
case CheatItem.TYPE_HEADER:
|
||||
View headerView = inflater.inflate(R.layout.list_item_header, parent, false);
|
||||
return new HeaderViewHolder(headerView);
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CheatViewHolder holder, int position)
|
||||
public void onBindViewHolder(@NonNull CheatItemViewHolder holder, int position)
|
||||
{
|
||||
holder.bind(mViewModel, getItemAt(position), position);
|
||||
}
|
||||
@ -48,30 +58,42 @@ public class CheatsAdapter extends RecyclerView.Adapter<CheatViewHolder>
|
||||
public int getItemCount()
|
||||
{
|
||||
return mViewModel.getARCheats().length + mViewModel.getGeckoCheats().length +
|
||||
mViewModel.getPatchCheats().length;
|
||||
mViewModel.getPatchCheats().length + 3;
|
||||
}
|
||||
|
||||
private Cheat getItemAt(int position)
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
return getItemAt(position).getType();
|
||||
}
|
||||
|
||||
private CheatItem getItemAt(int position)
|
||||
{
|
||||
if (position == 0)
|
||||
return new CheatItem(CheatItem.TYPE_HEADER, R.string.cheats_header_patch);
|
||||
position -= 1;
|
||||
|
||||
Cheat[] patchCheats = mViewModel.getPatchCheats();
|
||||
if (position < patchCheats.length)
|
||||
{
|
||||
return patchCheats[position];
|
||||
}
|
||||
return new CheatItem(patchCheats[position]);
|
||||
position -= patchCheats.length;
|
||||
|
||||
if (position == 0)
|
||||
return new CheatItem(CheatItem.TYPE_HEADER, R.string.cheats_header_ar);
|
||||
position -= 1;
|
||||
|
||||
Cheat[] arCheats = mViewModel.getARCheats();
|
||||
if (position < arCheats.length)
|
||||
{
|
||||
return arCheats[position];
|
||||
}
|
||||
return new CheatItem(arCheats[position]);
|
||||
position -= arCheats.length;
|
||||
|
||||
if (position == 0)
|
||||
return new CheatItem(CheatItem.TYPE_HEADER, R.string.cheats_header_gecko);
|
||||
position -= 1;
|
||||
|
||||
Cheat[] geckoCheats = mViewModel.getGeckoCheats();
|
||||
if (position < geckoCheats.length)
|
||||
{
|
||||
return geckoCheats[position];
|
||||
}
|
||||
return new CheatItem(geckoCheats[position]);
|
||||
position -= geckoCheats.length;
|
||||
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
@ -0,0 +1,28 @@
|
||||
// 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 org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel;
|
||||
|
||||
public class HeaderViewHolder extends CheatItemViewHolder
|
||||
{
|
||||
private TextView mHeaderName;
|
||||
|
||||
public HeaderViewHolder(@NonNull View itemView)
|
||||
{
|
||||
super(itemView);
|
||||
|
||||
mHeaderName = itemView.findViewById(R.id.text_header_name);
|
||||
}
|
||||
|
||||
public void bind(CheatsViewModel viewModel, CheatItem item, int position)
|
||||
{
|
||||
mHeaderName.setText(item.getString());
|
||||
}
|
||||
}
|
@ -18,9 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AdHocBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.FloatSliderSetting;
|
||||
@ -43,7 +41,6 @@ import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SettingViewHold
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SingleChoiceViewHolder;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SliderViewHolder;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SubmenuViewHolder;
|
||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
@ -51,10 +48,7 @@ import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder>
|
||||
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
|
||||
@ -87,7 +81,7 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
||||
switch (viewType)
|
||||
{
|
||||
case SettingsItem.TYPE_HEADER:
|
||||
view = inflater.inflate(R.layout.list_item_settings_header, parent, false);
|
||||
view = inflater.inflate(R.layout.list_item_header, parent, false);
|
||||
return new HeaderViewHolder(view, this);
|
||||
|
||||
case SettingsItem.TYPE_CHECKBOX:
|
||||
|
@ -389,6 +389,9 @@
|
||||
<!-- Cheats Screen -->
|
||||
<string name="cheats">Cheats</string>
|
||||
<string name="cheats_with_game_id">Cheats: %1$s</string>
|
||||
<string name="cheats_header_ar">AR Codes</string>
|
||||
<string name="cheats_header_gecko">Gecko Codes</string>
|
||||
<string name="cheats_header_patch">Patches</string>
|
||||
<string name="cheats_name">Name</string>
|
||||
<string name="cheats_creator">Creator</string>
|
||||
<string name="cheats_notes">Notes</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user