1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-17 04:00:48 +01:00

crash fixes

This commit is contained in:
Mariotaku Lee 2017-07-07 20:25:33 +08:00
parent 34966dfd4e
commit ff0968f4a6
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 14 additions and 6 deletions

View File

@ -39,8 +39,7 @@ class AccountPreferences(
private val preferences: SharedPreferences,
val accountKey: UserKey
) {
private val accountPreferences = context.getSharedPreferences(
"$ACCOUNT_PREFERENCES_NAME_PREFIX$accountKey", Context.MODE_PRIVATE)
private val accountPreferences = getSharedPreferencesForAccount(context, accountKey)
val defaultNotificationLightColor: Int
get() {
@ -154,8 +153,12 @@ class AccountPreferences(
}
fun getSharedPreferencesForAccount(context: Context, accountKey: UserKey): SharedPreferences {
return context.getSharedPreferences("$ACCOUNT_PREFERENCES_NAME_PREFIX$accountKey",
return context.getSharedPreferences("$ACCOUNT_PREFERENCES_NAME_PREFIX${accountKey.sanitized()}",
Context.MODE_PRIVATE)
}
private fun UserKey.sanitized(): String {
return toString().replace(Regex("[^\\w\\d@-_.]"), "_")
}
}
}

View File

@ -917,9 +917,14 @@ class UpdateStatusTask(
o.inSampleSize = o.calculateInSampleSize(imageLimit.maxWidth, imageLimit.maxHeight)
o.inJustDecodeBounds = false
// Do actual image decoding
val bitmap = context.contentResolver.openInputStream(mediaUri).use {
BitmapFactory.decodeStream(it, null, o)
} ?: return null
val bitmap = try {
context.contentResolver.openInputStream(mediaUri).use {
BitmapFactory.decodeStream(it, null, o)
} ?: return null
} catch (oome: OutOfMemoryError) {
Analyzer.logException(OutOfMemoryError("OOM Image size: $imageSize, width: ${o.outWidth}, height: ${o.outHeight}, type: ${o.outMimeType}"))
return null
}
val size = Point(bitmap.width, bitmap.height)
val ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType)