1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2025-02-16 16:23:57 +00:00

Handle case where server is unreachable for avatar download

This commit is contained in:
Steffo 2024-01-06 18:26:56 +01:00
parent ff786fbf68
commit a7240b50a5
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -13,6 +13,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import eu.steffo.twom.matrix.LocalSession import eu.steffo.twom.matrix.LocalSession
import org.matrix.android.sdk.api.failure.Failure
import java.io.File
@Composable @Composable
@Preview(widthDp = 40, heightDp = 40) @Preview(widthDp = 40, heightDp = 40)
@ -41,13 +43,21 @@ fun AvatarFromURL(
bitmap = null bitmap = null
return@GetAvatar return@GetAvatar
} }
Log.d("Avatar", "Downloading avatar at: $url") Log.d("Avatar", "Downloading avatar at: $url")
val avatarFile = session.fileService().downloadFile( lateinit var avatarFile: File
fileName = "avatar", try {
url = url, avatarFile = session.fileService().downloadFile(
mimeType = null, fileName = "avatar",
elementToDecrypt = null, url = url,
) mimeType = null,
elementToDecrypt = null,
)
} catch (f: Failure.OtherServerError) {
Log.e("Avatar", "Unable to download avatar at: $url", f)
return@GetAvatar
}
// TODO: Should I check the MIME type? And the size of the image? // TODO: Should I check the MIME type? And the size of the image?
Log.d("Avatar", "File for $url is: $avatarFile") Log.d("Avatar", "File for $url is: $avatarFile")
bitmap = BitmapFactory.decodeFile(avatarFile.absolutePath) bitmap = BitmapFactory.decodeFile(avatarFile.absolutePath)