Android: Convert RiivolutionAdapter to Kotlin
This commit is contained in:
parent
df21663d4c
commit
4045e213ba
|
@ -1,66 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.riivolution.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemRiivolutionBinding;
|
||||
import org.dolphinemu.dolphinemu.features.riivolution.model.RiivolutionPatches;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RiivolutionAdapter extends RecyclerView.Adapter<RiivolutionViewHolder>
|
||||
{
|
||||
private final Context mContext;
|
||||
private final RiivolutionPatches mPatches;
|
||||
private final ArrayList<RiivolutionItem> mItems = new ArrayList<>();
|
||||
|
||||
public RiivolutionAdapter(Context context, RiivolutionPatches patches)
|
||||
{
|
||||
mContext = context;
|
||||
mPatches = patches;
|
||||
|
||||
int discCount = mPatches.getDiscCount();
|
||||
for (int i = 0; i < discCount; i++)
|
||||
{
|
||||
mItems.add(new RiivolutionItem(i));
|
||||
|
||||
int sectionCount = mPatches.getSectionCount(i);
|
||||
for (int j = 0; j < sectionCount; j++)
|
||||
{
|
||||
mItems.add(new RiivolutionItem(i, j));
|
||||
|
||||
int optionCount = mPatches.getOptionCount(i, j);
|
||||
for (int k = 0; k < optionCount; k++)
|
||||
{
|
||||
mItems.add(new RiivolutionItem(i, j, k));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull @Override
|
||||
public RiivolutionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
ListItemRiivolutionBinding binding = ListItemRiivolutionBinding.inflate(inflater);
|
||||
return new RiivolutionViewHolder(binding.getRoot(), binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RiivolutionViewHolder holder, int position)
|
||||
{
|
||||
holder.bind(mContext, mPatches, mItems.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.riivolution.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.dolphinemu.dolphinemu.databinding.ListItemRiivolutionBinding
|
||||
import org.dolphinemu.dolphinemu.features.riivolution.model.RiivolutionPatches
|
||||
|
||||
class RiivolutionAdapter(private val context: Context, private val patches: RiivolutionPatches) :
|
||||
RecyclerView.Adapter<RiivolutionViewHolder>() {
|
||||
private val items = ArrayList<RiivolutionItem>()
|
||||
|
||||
init {
|
||||
val discCount = patches.getDiscCount()
|
||||
for (i in 0 until discCount) {
|
||||
items.add(RiivolutionItem(i))
|
||||
|
||||
val sectionCount = patches.getSectionCount(i)
|
||||
for (j in 0 until sectionCount) {
|
||||
items.add(RiivolutionItem(i, j))
|
||||
|
||||
val optionCount = patches.getOptionCount(i, j)
|
||||
for (k in 0 until optionCount) {
|
||||
items.add(RiivolutionItem(i, j, k))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RiivolutionViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val binding = ListItemRiivolutionBinding.inflate(inflater)
|
||||
return RiivolutionViewHolder(binding.root, binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RiivolutionViewHolder, position: Int) {
|
||||
holder.bind(context, patches, items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return items.size
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue