mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 04:50:15 +02:00
fix(app/ui): error handling
This commit is contained in:
parent
0b0220ce84
commit
1241d68d3c
@ -18,6 +18,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.ImageBitmap
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import coil.annotation.ExperimentalCoilApi
|
import coil.annotation.ExperimentalCoilApi
|
||||||
@ -161,6 +162,10 @@ fun LoggedStories(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stories.isEmpty()) {
|
||||||
|
Text(text = "No stories found", Modifier.fillMaxWidth(), textAlign = TextAlign.Center)
|
||||||
|
}
|
||||||
|
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Adaptive(100.dp),
|
columns = GridCells.Adaptive(100.dp),
|
||||||
contentPadding = PaddingValues(8.dp),
|
contentPadding = PaddingValues(8.dp),
|
||||||
@ -203,25 +208,29 @@ fun LoggedStories(
|
|||||||
return@withTimeout
|
return@withTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
val response = httpClient.newCall(Request(
|
runCatching {
|
||||||
url = story.url.toHttpUrl()
|
val response = httpClient.newCall(Request(
|
||||||
)).execute()
|
url = story.url.toHttpUrl()
|
||||||
response.body.byteStream().use {
|
)).execute()
|
||||||
val decrypted = story.key?.let { _ ->
|
response.body.byteStream().use {
|
||||||
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
val decrypted = story.key?.let { _ ->
|
||||||
cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(story.key, "AES"), IvParameterSpec(story.iv))
|
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||||
CipherInputStream(it, cipher)
|
cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(story.key, "AES"), IvParameterSpec(story.iv))
|
||||||
} ?: it
|
CipherInputStream(it, cipher)
|
||||||
|
} ?: it
|
||||||
|
|
||||||
context.imageLoader.diskCache?.openEditor(uniqueHash)?.apply {
|
context.imageLoader.diskCache?.openEditor(uniqueHash)?.apply {
|
||||||
data.toFile().outputStream().use { fos ->
|
data.toFile().outputStream().use { fos ->
|
||||||
decrypted.copyTo(fos)
|
decrypted.copyTo(fos)
|
||||||
}
|
}
|
||||||
commitAndOpenSnapshot()?.use { snapshot ->
|
commitAndOpenSnapshot()?.use { snapshot ->
|
||||||
openDiskCacheSnapshot(snapshot)
|
openDiskCacheSnapshot(snapshot)
|
||||||
snapshot.close()
|
snapshot.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.onFailure {
|
||||||
|
context.log.error("Failed to load story", it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,29 +423,34 @@ class MessagingPreview(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onMessagingBridgeReady() {
|
private fun onMessagingBridgeReady() {
|
||||||
messagingBridge = context.bridgeService!!.messagingBridge!!
|
runCatching {
|
||||||
conversationId = if (scope == SocialScope.FRIEND) messagingBridge.getOneToOneConversationId(scopeId) else scopeId
|
messagingBridge = context.bridgeService!!.messagingBridge!!
|
||||||
if (conversationId == null) {
|
conversationId = if (scope == SocialScope.FRIEND) messagingBridge.getOneToOneConversationId(scopeId) else scopeId
|
||||||
context.longToast("Failed to fetch conversation id")
|
if (conversationId == null) {
|
||||||
return
|
context.longToast("Failed to fetch conversation id")
|
||||||
}
|
return
|
||||||
if (!messagingBridge.isSessionStarted) {
|
|
||||||
context.androidContext.packageManager.getLaunchIntentForPackage(
|
|
||||||
Constants.SNAPCHAT_PACKAGE_NAME
|
|
||||||
)?.let {
|
|
||||||
val mainIntent = Intent.makeRestartActivityTask(it.component).apply {
|
|
||||||
putExtra(ReceiversConfig.MESSAGING_PREVIEW_EXTRA, true)
|
|
||||||
}
|
|
||||||
context.androidContext.startActivity(mainIntent)
|
|
||||||
}
|
}
|
||||||
messagingBridge.registerSessionStartListener(object: SessionStartListener.Stub() {
|
if (!messagingBridge.isSessionStarted) {
|
||||||
override fun onConnected() {
|
context.androidContext.packageManager.getLaunchIntentForPackage(
|
||||||
fetchNewMessages()
|
Constants.SNAPCHAT_PACKAGE_NAME
|
||||||
|
)?.let {
|
||||||
|
val mainIntent = Intent.makeRestartActivityTask(it.component).apply {
|
||||||
|
putExtra(ReceiversConfig.MESSAGING_PREVIEW_EXTRA, true)
|
||||||
|
}
|
||||||
|
context.androidContext.startActivity(mainIntent)
|
||||||
}
|
}
|
||||||
})
|
messagingBridge.registerSessionStartListener(object: SessionStartListener.Stub() {
|
||||||
return
|
override fun onConnected() {
|
||||||
|
fetchNewMessages()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fetchNewMessages()
|
||||||
|
}.onFailure {
|
||||||
|
context.longToast("Failed to initialize messaging bridge")
|
||||||
|
context.log.error("Failed to initialize messaging bridge", it)
|
||||||
}
|
}
|
||||||
fetchNewMessages()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user