From 6ad18e4ee59688bb3ee6aaab73073dd92dbce4c2 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 10 Jun 2023 05:17:49 -0400 Subject: [PATCH] Android: Convert ProfileAdapter to Kotlin --- .../features/input/ui/ProfileAdapter.java | 65 ------------------- .../features/input/ui/ProfileAdapter.kt | 42 ++++++++++++ .../features/input/ui/ProfileDialog.kt | 6 +- 3 files changed, 45 insertions(+), 68 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.java deleted file mode 100644 index 9908d6f5fd..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.java +++ /dev/null @@ -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 -{ - 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; - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.kt new file mode 100644 index 0000000000..71aa166cc9 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileAdapter.kt @@ -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() { + private val stockProfileNames: Array = presenter.getProfileNames(true) + private val userProfileNames: Array = 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 +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialog.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialog.kt index acc3f605a9..4ef3dae51f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialog.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/ui/ProfileDialog.kt @@ -16,13 +16,13 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag import org.dolphinemu.dolphinemu.utils.SerializableHelper.serializable class ProfileDialog : BottomSheetDialogFragment() { - private var presenter: ProfileDialogPresenter? = null + private lateinit var presenter: ProfileDialogPresenter private var _binding: DialogInputProfilesBinding? = null private val binding get() = _binding!! override fun onCreate(savedInstanceState: Bundle?) { - val menuTag = requireArguments().serializable(KEY_MENU_TAG) + val menuTag = requireArguments().serializable(KEY_MENU_TAG)!! presenter = ProfileDialogPresenter(this, menuTag) @@ -39,7 +39,7 @@ class ProfileDialog : BottomSheetDialogFragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - binding.profileList.adapter = ProfileAdapter(context, presenter) + binding.profileList.adapter = ProfileAdapter(requireContext(), presenter) binding.profileList.layoutManager = LinearLayoutManager(context) val divider = MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL) divider.isLastItemDecorated = false