Fix: Compilation errors in MainActivity.kt

- Corrected 'Unresolved reference 'prefs'' by updating 'OnSharedPreferenceChangeListener' to use 'sharedPreferences' parameter.
- Reverted 'showDeleteConfirmationDialog' to 'var ... by remember' to resolve ''val' cannot be reassigned' and 'Assignment type mismatch' errors.
This commit is contained in:
2025-11-01 12:23:03 +01:00
parent f9cbd3d2c3
commit c0d36e82f8
2 changed files with 20 additions and 17 deletions

View File

@@ -224,6 +224,7 @@ class BiometricAuthenticator(private val context: Context) {
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle(title)
.setSubtitle(subtitle)
.setNegativeButtonText(negativeButtonText)
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL)
.build()
@@ -357,7 +358,7 @@ class MainActivity : FragmentActivity() {
subtitle = getString(R.string.confirm_to_unlock),
negativeButtonText = getString(R.string.cancel),
fragmentActivity = this,
onSuccess = { isUnlocked = true },
onSuccess = { _ -> isUnlocked = true },
onFailed = {
android.widget.Toast.makeText(context, R.string.unlock_failed, android.widget.Toast.LENGTH_SHORT).show()
},
@@ -391,9 +392,9 @@ fun AppShell(
var syncFolderUriString by rememberSaveable { mutableStateOf(sharedPrefs.getString("sync_folder_uri", null)) }
DisposableEffect(sharedPrefs) {
val listener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { prefs, key ->
val listener = android.content.SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == "sync_folder_uri") {
syncFolderUriString = prefs.getString(key, null)
syncFolderUriString = sharedPreferences.getString(key, null)
}
}
sharedPrefs.registerOnSharedPreferenceChangeListener(listener)
@@ -482,7 +483,7 @@ fun AppShell(
subtitle = context.getString(R.string.confirm_to_change_password),
negativeButtonText = context.getString(R.string.cancel),
fragmentActivity = activity,
onSuccess = { showPasswordDialog = true },
onSuccess = { _ -> showPasswordDialog = true },
onFailed = { },
onError = { _, _ -> }
)
@@ -1132,12 +1133,13 @@ fun AppShell(
Row(verticalAlignment = Alignment.CenterVertically) {
Column(modifier = Modifier.weight(1f)) {
Text(stringResource(id = R.string.select_sync_folder))
val displayPath = if (syncFolderUriString.isNullOrBlank()) {
val currentSyncFolderUriString = syncFolderUriString
val displayPath = if (currentSyncFolderUriString.isNullOrBlank()) {
stringResource(id = R.string.no_folder_selected)
} else {
val path = remember(syncFolderUriString) {
val path = remember(currentSyncFolderUriString) {
try {
val uri = Uri.parse(syncFolderUriString)
val uri = currentSyncFolderUriString.toUri()
val docFile = DocumentFile.fromTreeUri(context, uri)
if (docFile?.name == "Noteshop") {
val parent = docFile.parentFile
@@ -1931,7 +1933,7 @@ fun AppShell(
subtitle = "",
negativeButtonText = context.getString(R.string.cancel),
fragmentActivity = activity,
onSuccess = {
onSuccess = { _ ->
if (isPassword) {
webAppIntegrationViewModel.togglePasswordVisibility()
} else {
@@ -1985,11 +1987,11 @@ fun AppShell(
val syncFolderUriString = sharedPrefs.getString("sync_folder_uri", null)
if (syncFolderUriString != null) {
try {
val uri = Uri.parse(syncFolderUriString)
val uri = syncFolderUriString.toUri()
val docFile = DocumentFile.fromTreeUri(context, uri)
docFile?.delete()
context.contentResolver.releasePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
sharedPrefs.edit().remove("sync_folder_uri").apply()
sharedPrefs.edit { remove("sync_folder_uri") }
} catch (e: Exception) {
Log.e("MainActivity", "Error deleting sync folder", e)
}

View File

@@ -15,22 +15,23 @@ import io.ktor.http.ContentType
import io.ktor.http.Parameters
import io.ktor.http.contentType
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
@Serializable
data class TokenResponse(
val access_token: String,
val token_type: String
@SerialName("access_token") val accessToken: String,
@SerialName("token_type") val tokenType: String
)
@Serializable
data class Item(
val id: Int,
val name: String,
val is_standard: Int,
val created_by_user_id: Int?,
val marked: Int
@SerialName("is_standard") val isStandard: Int,
@SerialName("created_by_user_id") val createdByUserId: Int?,
@SerialName("marked") val isMarked: Int
)
@Serializable
@@ -75,14 +76,14 @@ class WebAppClient {
if (response.status.value in 200..299) {
val tokenResponse: TokenResponse = response.body()
token = tokenResponse.access_token
token = tokenResponse.accessToken
return Pair(true, "")
} else {
val errorBody = response.bodyAsText()
return try {
val errorDetail = Json.decodeFromString<ErrorDetail>(errorBody)
Pair(false, "Login failed: ${errorDetail.detail}")
} catch (e: Exception) {
} catch (_: Exception) {
Pair(false, "Login failed with status: ${response.status.value}. Response: $errorBody")
}
}