1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-21 23:54:26 +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.tooling.preview.Preview
import eu.steffo.twom.matrix.LocalSession
import org.matrix.android.sdk.api.failure.Failure
import java.io.File
@Composable
@Preview(widthDp = 40, heightDp = 40)
@ -41,13 +43,21 @@ fun AvatarFromURL(
bitmap = null
return@GetAvatar
}
Log.d("Avatar", "Downloading avatar at: $url")
val avatarFile = session.fileService().downloadFile(
fileName = "avatar",
url = url,
mimeType = null,
elementToDecrypt = null,
)
lateinit var avatarFile: File
try {
avatarFile = session.fileService().downloadFile(
fileName = "avatar",
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?
Log.d("Avatar", "File for $url is: $avatarFile")
bitmap = BitmapFactory.decodeFile(avatarFile.absolutePath)