52 lines
1.7 KiB
Kotlin
52 lines
1.7 KiB
Kotlin
package com.catlas.escapepenacony
|
|||
|
|
|
||
|
|
import android.content.Intent
|
||
|
|
import android.net.Uri
|
||
|
|
import android.os.Bundle
|
||
|
|
import androidx.activity.ComponentActivity
|
||
|
|
import androidx.activity.compose.setContent
|
||
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
||
|
|
import androidx.compose.runtime.*
|
||
|
|
import com.catlas.escapepenacony.data.StorageManager
|
||
|
|
import com.catlas.escapepenacony.ui.MainScreen
|
||
|
|
import com.catlas.escapepenacony.ui.theme.EscapePenaconyTheme
|
||
|
|
|
||
|
|
class MainActivity : ComponentActivity() {
|
||
|
|
|
||
|
|
private var currentPersistentUri by mutableStateOf<Uri?>(null)
|
||
|
|
|
||
|
|
// Storage Access Framework Document Picker for persistent.json
|
||
|
|
private val openDocumentLauncher = registerForActivityResult(
|
||
|
|
ActivityResultContracts.OpenDocument()
|
||
|
|
) { uri: Uri? ->
|
||
|
|
if (uri != null) {
|
||
|
|
try {
|
||
|
|
contentResolver.takePersistableUriPermission(
|
||
|
|
uri,
|
||
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||
|
|
)
|
||
|
|
} catch (_: Exception) {}
|
||
|
|
|
||
|
|
StorageManager.savePersistentUri(this, uri)
|
||
|
|
currentPersistentUri = uri
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||
|
|
super.onCreate(savedInstanceState)
|
||
|
|
|
||
|
|
// Restore previously selected persistent.json if available
|
||
|
|
currentPersistentUri = StorageManager.getPersistentUri(this)
|
||
|
|
|
||
|
|
setContent {
|
||
|
|
EscapePenaconyTheme {
|
||
|
|
MainScreen(
|
||
|
|
currentPersistentUri = currentPersistentUri,
|
||
|
|
onPickPersistentFile = {
|
||
|
|
openDocumentLauncher.launch(arrayOf("application/json", "*/*"))
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|