mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Android: Convert ProfileAdapter to Kotlin
This commit is contained in:
@ -1,65 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.dolphinemu.dolphinemu.features.input.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.ListItemProfileBinding;
|
|
||||||
|
|
||||||
public final class ProfileAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|
||||||
{
|
|
||||||
private final Context mContext;
|
|
||||||
private final ProfileDialogPresenter mPresenter;
|
|
||||||
|
|
||||||
private final String[] mStockProfileNames;
|
|
||||||
private final String[] mUserProfileNames;
|
|
||||||
|
|
||||||
public ProfileAdapter(Context context, ProfileDialogPresenter presenter)
|
|
||||||
{
|
|
||||||
mContext = context;
|
|
||||||
mPresenter = presenter;
|
|
||||||
|
|
||||||
mStockProfileNames = presenter.getProfileNames(true);
|
|
||||||
mUserProfileNames = presenter.getProfileNames(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull @Override
|
|
||||||
public ProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
|
|
||||||
{
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
|
||||||
|
|
||||||
ListItemProfileBinding binding = ListItemProfileBinding.inflate(inflater, parent, false);
|
|
||||||
return new ProfileViewHolder(mPresenter, binding);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull ProfileViewHolder holder, int position)
|
|
||||||
{
|
|
||||||
if (position < mStockProfileNames.length)
|
|
||||||
{
|
|
||||||
holder.bind(mStockProfileNames[position], true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
position -= mStockProfileNames.length;
|
|
||||||
|
|
||||||
if (position < mUserProfileNames.length)
|
|
||||||
{
|
|
||||||
holder.bind(mUserProfileNames[position], false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.bindAsEmpty(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount()
|
|
||||||
{
|
|
||||||
return mStockProfileNames.length + mUserProfileNames.length + 1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,42 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.dolphinemu.dolphinemu.features.input.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.dolphinemu.dolphinemu.databinding.ListItemProfileBinding
|
||||||
|
|
||||||
|
class ProfileAdapter(
|
||||||
|
private val context: Context,
|
||||||
|
private val presenter: ProfileDialogPresenter
|
||||||
|
) : RecyclerView.Adapter<ProfileViewHolder>() {
|
||||||
|
private val stockProfileNames: Array<String> = presenter.getProfileNames(true)
|
||||||
|
private val userProfileNames: Array<String> = presenter.getProfileNames(false)
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProfileViewHolder {
|
||||||
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
|
val binding = ListItemProfileBinding.inflate(inflater, parent, false)
|
||||||
|
return ProfileViewHolder(presenter, binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) {
|
||||||
|
var profilePosition = position
|
||||||
|
if (profilePosition < stockProfileNames.size) {
|
||||||
|
holder.bind(stockProfileNames[profilePosition], true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
profilePosition -= stockProfileNames.size
|
||||||
|
|
||||||
|
if (profilePosition < userProfileNames.size) {
|
||||||
|
holder.bind(userProfileNames[profilePosition], false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.bindAsEmpty(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = stockProfileNames.size + userProfileNames.size + 1
|
||||||
|
}
|
@ -16,13 +16,13 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag
|
|||||||
import org.dolphinemu.dolphinemu.utils.SerializableHelper.serializable
|
import org.dolphinemu.dolphinemu.utils.SerializableHelper.serializable
|
||||||
|
|
||||||
class ProfileDialog : BottomSheetDialogFragment() {
|
class ProfileDialog : BottomSheetDialogFragment() {
|
||||||
private var presenter: ProfileDialogPresenter? = null
|
private lateinit var presenter: ProfileDialogPresenter
|
||||||
|
|
||||||
private var _binding: DialogInputProfilesBinding? = null
|
private var _binding: DialogInputProfilesBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
val menuTag = requireArguments().serializable<MenuTag>(KEY_MENU_TAG)
|
val menuTag = requireArguments().serializable<MenuTag>(KEY_MENU_TAG)!!
|
||||||
|
|
||||||
presenter = ProfileDialogPresenter(this, menuTag)
|
presenter = ProfileDialogPresenter(this, menuTag)
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class ProfileDialog : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
binding.profileList.adapter = ProfileAdapter(context, presenter)
|
binding.profileList.adapter = ProfileAdapter(requireContext(), presenter)
|
||||||
binding.profileList.layoutManager = LinearLayoutManager(context)
|
binding.profileList.layoutManager = LinearLayoutManager(context)
|
||||||
val divider = MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL)
|
val divider = MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL)
|
||||||
divider.isLastItemDecorated = false
|
divider.isLastItemDecorated = false
|
||||||
|
Reference in New Issue
Block a user