refactor: adopt androidx.core KTX helpers (Bitmap/Uri/SharedPreferences)

This commit is contained in:
davotoula
2026-07-11 17:00:40 +01:00
parent 56e4b1ec7d
commit 0053edf2dd
18 changed files with 63 additions and 29 deletions
@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.commons.blurhash
import android.graphics.Bitmap
import androidx.core.graphics.scale
actual class PlatformImage(
val bitmap: Bitmap,
@@ -43,7 +44,7 @@ actual class PlatformImage(
actual fun scale(
width: Int,
height: Int,
): PlatformImage = PlatformImage(Bitmap.createScaledBitmap(bitmap, width, height, false))
): PlatformImage = PlatformImage(bitmap.scale(width, height, false))
actual companion object {
actual fun create(
@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.commons.keystorage
import android.content.Context
import androidx.core.content.edit
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import kotlinx.coroutines.Dispatchers
@@ -86,7 +87,7 @@ actual class SecureKeyStorage private actual constructor() {
) {
withContext(Dispatchers.IO) {
try {
encryptedPrefs.edit().putString(KEY_PREFIX + npub, privKeyHex).apply()
encryptedPrefs.edit { putString(KEY_PREFIX + npub, privKeyHex) }
} catch (e: Exception) {
throw SecureStorageException("Failed to save private key", e)
}
@@ -108,7 +109,7 @@ actual class SecureKeyStorage private actual constructor() {
val key = KEY_PREFIX + npub
val existed = encryptedPrefs.contains(key)
if (existed) {
encryptedPrefs.edit().remove(key).apply()
encryptedPrefs.edit { remove(key) }
}
existed
} catch (e: Exception) {
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.commons.nip64Chess
import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
actual class ChessDismissedGamesStorage private actual constructor() {
private var prefs: SharedPreferences? = null
@@ -48,6 +49,6 @@ actual class ChessDismissedGamesStorage private actual constructor() {
userPubkey: String,
ids: Set<String>,
) {
prefs?.edit()?.putStringSet(prefsKey(userPubkey), ids)?.apply()
prefs?.edit { putStringSet(prefsKey(userPubkey), ids) }
}
}