Remove, replace redundant/deprecated code

This commit is contained in:
KeatonTheBot 2025-10-07 08:28:39 -05:00
parent 4d1620c330
commit f47be3342f
14 changed files with 58 additions and 219 deletions

View file

@ -42,14 +42,15 @@ class GameController(var activity: Activity) {
companion object {
private fun init(context: Context, controller: GameController): View {
val inflater = LayoutInflater.from(context)
val view = inflater.inflate(R.layout.game_layout, null)
val parent = FrameLayout(context)
val view = inflater.inflate(R.layout.game_layout, parent, false)
view.findViewById<FrameLayout>(R.id.leftcontainer)!!.addView(controller.leftGamePad)
view.findViewById<FrameLayout>(R.id.rightcontainer)!!.addView(controller.rightGamePad)
return view
}
@Composable
fun Compose(viewModel: MainViewModel): Unit {
fun Compose(viewModel: MainViewModel) {
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->

View file

@ -1,170 +0,0 @@
package org.kenjinx.android
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
import androidx.compose.runtime.MutableState
import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
import com.anggrayudi.storage.SimpleStorageHelper
import com.anggrayudi.storage.callback.FileCallback
import com.anggrayudi.storage.file.copyFileTo
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
import androidx.core.net.toUri
class Helpers {
companion object {
fun getPath(context: Context, uri: Uri): String? {
// DocumentProvider
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
val docId = DocumentsContract.getDocumentId(uri)
val split = docId.split(":".toRegex()).toTypedArray()
val type = split[0]
if ("primary".equals(type, ignoreCase = true)) {
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
}
} else if (isDownloadsDocument(uri)) {
val id = DocumentsContract.getDocumentId(uri)
val contentUri = ContentUris.withAppendedId(
"content://downloads/public_downloads".toUri(),
java.lang.Long.valueOf(id)
)
return getDataColumn(context, contentUri, null, null)
} else if (isMediaDocument(uri)) {
val docId = DocumentsContract.getDocumentId(uri)
val split = docId.split(":".toRegex()).toTypedArray()
val type = split[0]
var contentUri: Uri? = null
when (type) {
"image" -> {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
}
"video" -> {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
}
"audio" -> {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
}
}
val selection = "_id=?"
val selectionArgs = arrayOf(split[1])
return getDataColumn(context, contentUri, selection, selectionArgs)
}
} else if ("content".equals(uri.scheme, ignoreCase = true)) {
return getDataColumn(context, uri, null, null)
} else if ("file".equals(uri.scheme, ignoreCase = true)) {
return uri.path
}
return null
}
fun copyToData(
file: DocumentFile, path: String, storageHelper: SimpleStorageHelper,
isCopying: MutableState<Boolean>,
copyProgress: MutableState<Float>,
currentProgressName: MutableState<String>,
finish: () -> Unit
) {
var fPath = path + "/${file.name}"
var callback: FileCallback? = object : FileCallback() {
override fun onFailed(errorCode: ErrorCode) {
super.onFailed(errorCode)
File(fPath).delete()
finish()
}
override fun onStart(file: Any, workerThread: Thread): Long {
copyProgress.value = 0f
(file as DocumentFile).apply {
currentProgressName.value = "Copying ${file.name}"
}
return super.onStart(file, workerThread)
}
override fun onReport(report: Report) {
super.onReport(report)
if (!isCopying.value) {
Thread.currentThread().interrupt()
}
copyProgress.value = report.progress / 100f
}
override fun onCompleted(result: Any) {
super.onCompleted(result)
isCopying.value = false
finish()
}
}
val ioScope = CoroutineScope(Dispatchers.IO)
isCopying.value = true
File(fPath).delete()
file.apply {
val f = this
ioScope.launch {
f.copyFileTo(
storageHelper.storage.context,
File(path),
callback = callback!!
)
}
}
}
private fun getDataColumn(
context: Context,
uri: Uri?,
selection: String?,
selectionArgs: Array<String>?
): String? {
var cursor: Cursor? = null
val column = "_data"
val projection = arrayOf(column)
try {
cursor = uri?.let {
context.contentResolver.query(
it,
projection,
selection,
selectionArgs,
null
)
}
if (cursor != null && cursor.moveToFirst()) {
val column_index: Int = cursor.getColumnIndexOrThrow(column)
return cursor.getString(column_index)
}
} finally {
cursor?.close()
}
return null
}
private fun isExternalStorageDocument(uri: Uri): Boolean {
return "com.android.externalstorage.documents" == uri.authority
}
private fun isDownloadsDocument(uri: Uri): Boolean {
return "com.android.providers.downloads.documents" == uri.authority
}
private fun isMediaDocument(uri: Uri): Boolean {
return "com.android.providers.media.documents" == uri.authority
}
}
}

View file

@ -28,7 +28,6 @@ import org.kenjinx.android.viewmodels.MainViewModel
import org.kenjinx.android.viewmodels.QuickSettings
import org.kenjinx.android.viewmodels.GameModel
import org.kenjinx.android.views.MainView
import android.content.Context
import android.content.pm.ActivityInfo
import android.hardware.display.DisplayManager
import android.view.Surface
@ -231,7 +230,7 @@ class MainActivity : BaseActivity() {
}
uiHandler = UiHandler()
displayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
displayManager = getSystemService(DISPLAY_SERVICE) as DisplayManager
mainViewModel = MainViewModel(this)
mainViewModel!!.physicalControllerManager = physicalControllerManager

View file

@ -22,7 +22,7 @@ class MotionSensorManager(val activity: MainActivity) : SensorEventListener2 {
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
gyro = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)
setOrientation90()
var orientationListener = object : OrientationEventListener(activity) {
object : OrientationEventListener(activity) {
override fun onOrientationChanged(orientation: Int) {
when {
isWithinOrientationRange(orientation, 270) -> {

View file

@ -217,7 +217,7 @@ class DocumentProvider : DocumentsProvider() {
)
removeDocument(sourceDocumentId, sourceParentDocumentId)
return newDocumentId
} catch (e: FileNotFoundException) {
} catch (_: FileNotFoundException) {
throw FileNotFoundException("Couldn't move document '$sourceDocumentId'")
}
}

View file

@ -45,11 +45,12 @@ private val LightColorScheme = lightColorScheme(
onSurface = Gray10,
)
@Suppress("DEPRECATION")
@Composable
fun KenjinxAndroidTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = false, // Cambiato da true a false per usare i nostri colori personalizzati
dynamicColor: Boolean = false, // Changed from true to false to use our custom colors
content: @Composable () -> Unit
) {
val colorScheme = when {

View file

@ -73,7 +73,7 @@ class GameModel(var file: DocumentFile, val context: Context) {
context.contentResolver.openFileDescriptor(file.uri, "rw")
return updateDescriptor?.fd ?: -1
} catch (e: Exception) {
} catch (_: Exception) {
return -2
}
}

View file

@ -33,9 +33,9 @@ class MainViewModel(val activity: MainActivity) {
var controller: GameController? = null
var performanceManager: PerformanceManager? = null
var selected: GameModel? = null
val loadGameModel: MutableState<GameModel?> = mutableStateOf<GameModel?>(null)
val bootPath: MutableState<String?> = mutableStateOf<String?>(null)
val forceNceAndPptc: MutableState<Boolean> = mutableStateOf<Boolean>(false)
val loadGameModel: MutableState<GameModel?> = mutableStateOf(null)
val bootPath: MutableState<String?> = mutableStateOf(null)
val forceNceAndPptc: MutableState<Boolean> = mutableStateOf(false)
var isMiiEditorLaunched = false
val userViewModel = UserViewModel()
val logging = Logging(this)
@ -114,7 +114,7 @@ class MainViewModel(val activity: MainActivity) {
if(overrideSettings == true)
{
settings.overrideSettings(forceNceAndPptc);
settings.overrideSettings(forceNceAndPptc)
}
var success = KenjinxNative.graphicsInitialize(

View file

@ -329,6 +329,7 @@ class SettingsViewModel(val activity: MainActivity) {
} finally {
MainActivity.mainViewModel?.refreshFirmwareVersion()
installState.value = FirmwareInstallState.Done
descriptor.close()
}
}
}
@ -401,7 +402,7 @@ class SettingsViewModel(val activity: MainActivity) {
if (!header.isDirectory) {
val bos = BufferedOutputStream(FileOutputStream(filePath))
val bytesIn = ByteArray(4096)
var read: Int = 0
var read = 0
while (zip.read(bytesIn).also { read = it } > 0) {
bos.write(bytesIn, 0, read)
}

View file

@ -46,7 +46,7 @@ class TitleUpdateViewModel(val titleId: String) {
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
)
} catch (securityException: SecurityException) {
} catch (_: SecurityException) {
}
}

View file

@ -20,6 +20,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.mutableDoubleStateOf
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -33,7 +34,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Popup
import androidx.compose.ui.draw.alpha // ← NEU
import androidx.compose.ui.draw.alpha
import compose.icons.CssGgIcons
import compose.icons.cssggicons.ToolbarBottom
import org.kenjinx.android.GameController
@ -45,6 +46,7 @@ import org.kenjinx.android.viewmodels.MainViewModel
import org.kenjinx.android.viewmodels.QuickSettings
import org.kenjinx.android.viewmodels.VSyncMode
import org.kenjinx.android.widgets.SimpleAlertDialog
import java.util.Locale
import kotlin.math.roundToInt
class GameViews {
@ -82,7 +84,7 @@ class GameViews {
val enableMotion = remember { mutableStateOf(QuickSettings(mainViewModel.activity).enableMotion) }
val showMore = remember { mutableStateOf(false) }
val showLoading = remember { mutableStateOf(true) }
val progressValue = remember { mutableStateOf(0.0f) }
val progressValue = remember { mutableFloatStateOf(0.0f) }
val progress = remember { mutableStateOf("Loading") }
// --- Read overlay settings
@ -90,7 +92,7 @@ class GameViews {
mutableStateOf(QuickSettings(mainViewModel.activity).overlayMenuPosition)
}
val overlayOpacityState = remember {
mutableStateOf(QuickSettings(mainViewModel.activity).overlayMenuOpacity.coerceIn(0f, 1f))
mutableFloatStateOf(QuickSettings(mainViewModel.activity).overlayMenuOpacity.coerceIn(0f, 1f))
}
// Auxiliary mapping position → alignment
@ -160,7 +162,7 @@ class GameViews {
modifier = Modifier
.align(overlayAlignment())
.padding(8.dp)
.alpha(overlayOpacityState.value) // 0f = unsichtbar, aber weiter klickbar
.alpha(overlayOpacityState.floatValue) // 0f = invisible, but still clickable
) {
IconButton(modifier = Modifier.padding(4.dp), onClick = {
showMore.value = true
@ -174,7 +176,7 @@ class GameViews {
if (showMore.value) {
Popup(
alignment = overlayAlignment(), // --- NEU: Panel an gleicher Position
alignment = overlayAlignment(), // --- Panel in the same position
onDismissRequest = { showMore.value = false }
) {
Surface(
@ -264,7 +266,7 @@ class GameViews {
SimpleAlertDialog.Progress(
showDialog = showLoading,
progressText = progress.value,
progressValue = progressValue.value
progressValue = progressValue.floatValue
)
SimpleAlertDialog.Confirmation(
@ -302,9 +304,9 @@ class GameViews {
var gameTimeVal = 0.0
if (!gameTime.doubleValue.isInfinite())
gameTimeVal = gameTime.doubleValue
Text(text = "${String.format("%.3f", fifo.doubleValue)} %")
Text(text = "${String.format("%.3f", gameFps.doubleValue)} FPS")
Text(text = "${String.format("%.3f", gameTimeVal)} ms")
Text(text = "${String.format(Locale.getDefault(), "%.3f", fifo.doubleValue)} %")
Text(text = "${String.format(Locale.getDefault(), "%.3f", gameFps.doubleValue)} FPS")
Text(text = "${String.format(Locale.getDefault(), "%.3f", gameTimeVal)} ms")
Box(modifier = Modifier.width(96.dp)) {
Column {
LazyColumn {

View file

@ -44,10 +44,10 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
@ -255,10 +255,14 @@ class HomeViews {
leadingIcon = { Icon(Icons.Filled.Search, contentDescription = "Search") },
singleLine = true,
shape = RoundedCornerShape(8.dp),
colors = TextFieldDefaults.outlinedTextFieldColors(
focusedBorderColor = MaterialTheme.colorScheme.primary,
unfocusedBorderColor = MaterialTheme.colorScheme.outline
)
colors = OutlinedTextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
errorContainerColor = Color.Transparent,
focusedBorderColor = MaterialTheme.colorScheme.primary,
unfocusedBorderColor = MaterialTheme.colorScheme.outline,
)
)
}
},
@ -332,7 +336,7 @@ class HomeViews {
if (this.isNotEmpty() && (query.value.trim()
.isEmpty() || this.lowercase(Locale.getDefault())
.contains(query.value))) {
Box(modifier = Modifier.animateItemPlacement()) {
Box(modifier = Modifier.animateItem()) {
ListGameItem(
it,
viewModel,
@ -386,7 +390,7 @@ class HomeViews {
viewModel.mainViewModel.loadGameModel.value!!,
true,
viewModel.mainViewModel.forceNceAndPptc.value
) ?: false
)
if (success == 1) {
launchOnUiThread {
viewModel.mainViewModel.navigateToGame()
@ -588,7 +592,7 @@ class HomeViews {
}
Column {
Text(text = gameModel.version ?: "")
Text(text = String.format("%.3f", gameModel.fileSize))
Text(text = String.format(Locale.getDefault(), "%.3f", gameModel.fileSize))
}
}
}

View file

@ -106,8 +106,8 @@ class SettingViews {
val enablePptc = remember { mutableStateOf(false) }
val enableLowPowerPptc = remember { mutableStateOf(false) }
val enableJitCacheEviction = remember { mutableStateOf(false) }
var enableFsIntegrityChecks = remember { mutableStateOf(false) }
var fsGlobalAccessLogMode = remember { mutableIntStateOf(0) }
val enableFsIntegrityChecks = remember { mutableStateOf(false) }
val fsGlobalAccessLogMode = remember { mutableIntStateOf(0) }
val ignoreMissingServices = remember { mutableStateOf(false) }
val enableShaderCache = remember { mutableStateOf(false) }
val enableTextureRecompression = remember { mutableStateOf(false) }
@ -125,7 +125,7 @@ class SettingViews {
val showDataImportDialog = remember { mutableStateOf(false) }
val dataResetState = remember { mutableStateOf(DataResetState.Query) }
val dataImportState = remember { mutableStateOf(DataImportState.File) }
var dataFile = remember { mutableStateOf<DocumentFile?>(null) }
val dataFile = remember { mutableStateOf<DocumentFile?>(null) }
val isGrid = remember { mutableStateOf(true) }
val useSwitchLayout = remember { mutableStateOf(true) }
val enableMotion = remember { mutableStateOf(true) }
@ -1336,7 +1336,7 @@ class SettingViews {
)
var isDriverSelectorOpen = remember { mutableStateOf(false) }
val isDriverSelectorOpen = remember { mutableStateOf(false) }
Row(
modifier = Modifier

View file

@ -28,6 +28,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
@ -42,11 +43,11 @@ class VulkanDriverViews {
companion object {
@Composable
fun Main(activity: MainActivity, openDialog: MutableState<Boolean>) {
var driverViewModel = VulkanDriverViewModel(activity)
var isChanged = remember { mutableStateOf(false) }
var refresh = remember { mutableStateOf(false) }
var drivers = driverViewModel.getAvailableDrivers()
var selectedDriver = remember { mutableStateOf(0) }
val driverViewModel = VulkanDriverViewModel(activity)
val isChanged = remember { mutableStateOf(false) }
val refresh = remember { mutableStateOf(false) }
val drivers = driverViewModel.getAvailableDrivers()
val selectedDriver = remember { mutableIntStateOf(0) }
if (refresh.value) {
isChanged.value = true
@ -54,7 +55,7 @@ class VulkanDriverViews {
}
if (!isChanged.value) {
selectedDriver.value =
selectedDriver.intValue =
drivers.indexOfFirst { it.driverPath == driverViewModel.selected } + 1
isChanged.value = true
}
@ -75,7 +76,7 @@ class VulkanDriverViews {
onClick = {
driverViewModel.add(refresh)
refresh.value = true
selectedDriver.value = 0
selectedDriver.intValue = 0
driverViewModel.selected = ""
}
) {
@ -132,16 +133,16 @@ class VulkanDriverViews {
.fillMaxWidth()
.padding(vertical = 4.dp)
.clickable {
selectedDriver.value = 0
selectedDriver.intValue = 0
isChanged.value = true
driverViewModel.selected = ""
},
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = selectedDriver.value == 0 || driverViewModel.selected.isEmpty(),
selected = selectedDriver.intValue == 0 || driverViewModel.selected.isEmpty(),
onClick = {
selectedDriver.value = 0
selectedDriver.intValue = 0
isChanged.value = true
driverViewModel.selected = ""
}
@ -155,7 +156,7 @@ class VulkanDriverViews {
}
var driverIndex = 1
for (driver in drivers) {
var ind = driverIndex
val ind = driverIndex
Row(
modifier = Modifier
.fillMaxWidth()
@ -163,16 +164,16 @@ class VulkanDriverViews {
vertical = 4.dp
)
.clickable {
selectedDriver.value = ind
selectedDriver.intValue = ind
isChanged.value = true
driverViewModel.selected = driver.driverPath
},
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = selectedDriver.value == ind,
selected = selectedDriver.intValue == ind,
onClick = {
selectedDriver.value = ind
selectedDriver.intValue = ind
isChanged.value = true
driverViewModel.selected = driver.driverPath
}