Skip to content
Permalink
Browse files
Merge pull request #11615 from t895/kotlin-riivolution
Android: Convert Riivolution Boot Activity to Kotlin
  • Loading branch information
lioncash committed Mar 2, 2023
2 parents b9fd7e7 + 4045e21 commit 1b7969b
Show file tree
Hide file tree
Showing 11 changed files with 380 additions and 418 deletions.

This file was deleted.

@@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-2.0-or-later

package org.dolphinemu.dolphinemu.features.riivolution.model

import androidx.annotation.Keep

class RiivolutionPatches(
private val gameId: String,
private val revision: Int,
private val discNumber: Int
) {
private var unsavedChanges = false

@Keep
private val pointer: Long = initialize()

external fun finalize()

external fun getDiscCount(): Int

external fun getDiscName(discIndex: Int): String

external fun getSectionCount(discIndex: Int): Int

external fun getSectionName(discIndex: Int, sectionIndex: Int): String

external fun getOptionCount(discIndex: Int, sectionIndex: Int): Int

external fun getOptionName(discIndex: Int, sectionIndex: Int, optionIndex: Int): String

external fun getChoiceCount(discIndex: Int, sectionIndex: Int, optionIndex: Int): Int

external fun getChoiceName(
discIndex: Int,
sectionIndex: Int,
optionIndex: Int,
choiceIndex: Int
): String

/**
* @return 0 if no choice is selected, otherwise the index of the selected choice plus one.
*/
external fun getSelectedChoice(discIndex: Int, sectionIndex: Int, optionIndex: Int): Int

/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
fun setSelectedChoice(discIndex: Int, sectionIndex: Int, optionIndex: Int, choiceIndex: Int) {
unsavedChanges = true
setSelectedChoiceImpl(discIndex, sectionIndex, optionIndex, choiceIndex)
}

/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
private external fun setSelectedChoiceImpl(
discIndex: Int, sectionIndex: Int, optionIndex: Int,
choiceIndex: Int
)

fun loadConfig() {
loadConfigImpl(gameId, revision, discNumber)
}

private external fun loadConfigImpl(gameId: String, revision: Int, discNumber: Int)

fun saveConfig() {
if (unsavedChanges) {
unsavedChanges = false
saveConfigImpl(gameId)
}
}

private external fun saveConfigImpl(gameId: String)

companion object {
@JvmStatic
private external fun initialize(): Long
}
}

This file was deleted.

@@ -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
}
}

0 comments on commit 1b7969b

Please sign in to comment.