Skip to content

Commit

Permalink
Replace Exception by Throwable
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 16, 2025
1 parent 6d5f04a commit 15b58ce
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ class LocaleConfigCompat(context: Context) {

private class Api21Impl(context: Context) : Impl() {
override var status = 0
private set

override var supportedLocales: LocaleListCompat? = null
private set

init {
val resourceId = try {
getLocaleConfigResourceId(context)
} catch (e: Exception) {
} catch (e: Throwable) {
Log.w(TAG, "The resource file pointed to by the given resource ID isn't found.", e)
}
if (resourceId == ResourcesCompat.ID_NULL) {
Expand All @@ -92,7 +90,7 @@ class LocaleConfigCompat(context: Context) {
try {
supportedLocales = resources.getXml(resourceId).use { parseLocaleConfig(it) }
status = STATUS_SUCCESS
} catch (e: Exception) {
} catch (e: Throwable) {
val resourceEntryName = resources.getResourceEntryName(resourceId)
Log.w(TAG, "Failed to parse XML configuration from $resourceEntryName", e)
status = STATUS_PARSING_FAILED
Expand All @@ -113,7 +111,7 @@ class LocaleConfigCompat(context: Context) {
while (true) {
val parser = try {
context.assets.openXmlResourceParser(cookie, FILE_NAME_ANDROID_MANIFEST)
} catch (e: FileNotFoundException) {
} catch (_: FileNotFoundException) {
if (!isAndroidManifestFound) {
++cookie
continue
Expand Down Expand Up @@ -209,10 +207,8 @@ class LocaleConfigCompat(context: Context) {
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private class Api33Impl(context: Context) : Impl() {
override var status: Int = 0
private set

override var supportedLocales: LocaleListCompat? = null
private set

init {
val platformLocaleConfig = LocaleConfig(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fun BasicEnhancedAlertDialog(
onDismissRequest()
delay(400)
scale = 1f
} catch (_: Exception) {
} catch (_: Throwable) {
scale = 1f
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand Down Expand Up @@ -105,6 +104,7 @@ import ru.tech.imageresizershrinker.core.ui.utils.helper.ContextUtils.getFilenam
import ru.tech.imageresizershrinker.core.ui.utils.navigation.Screen
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedTopAppBar
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedTopAppBarDefaults
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedTopAppBarType
import ru.tech.imageresizershrinker.core.ui.widget.modifier.toShape
import ru.tech.imageresizershrinker.core.ui.widget.modifier.withLayoutCorners
Expand Down Expand Up @@ -309,7 +309,7 @@ fun ImagePager(
exit = fadeOut() + slideOutVertically()
) {
EnhancedTopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
colors = EnhancedTopAppBarDefaults.colors(
containerColor = MaterialTheme.colorScheme.scrim.copy(alpha = 0.5f)
),
type = EnhancedTopAppBarType.Center,
Expand Down Expand Up @@ -472,7 +472,7 @@ fun ImagePager(
}
onDismiss()
onUriSelected(null)
} catch (_: Exception) {
} catch (_: Throwable) {
predictiveBackProgress = 0f
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal class AndroidCryptographyManager @Inject constructor() : CryptographyMa
)
}
}
} catch (_: Exception) {
} catch (_: Throwable) {
runCatching {
init(
mode,
Expand Down Expand Up @@ -148,7 +148,7 @@ internal class AndroidCryptographyManager @Inject constructor() : CryptographyMa
private fun Cipher.doOrThrow(data: ByteArray): ByteArray {
return try {
doFinal(data)
} catch (e: Exception) {
} catch (e: Throwable) {
throw if (e.message?.contains("mac") == true && e.message?.contains("failed") == true) {
WrongKeyException()
} else e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fun LibrariesInfoContent(
predictiveBackProgress = event.progress
}
component.selectLibrary(null)
} catch (_: Exception) {
} catch (_: Throwable) {
predictiveBackProgress = 0f
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ suspend fun ContentResolver.getMedia(
while (cursor.moveToNext()) {
try {
media.add(cursor.getMediaFromCursor())
} catch (e: Exception) {
} catch (e: Throwable) {
e.printStackTrace()
}
}
Expand All @@ -91,7 +91,6 @@ suspend fun ContentResolver.getMedia(
}


@Throws(Exception::class)
fun Cursor.getMediaFromCursor(): Media {
val id: Long =
getLong(getColumnIndexOrThrow(MediaStore.MediaColumns._ID))
Expand All @@ -115,25 +114,25 @@ fun Cursor.getMediaFromCursor(): Media {
MediaStore.MediaColumns.BUCKET_DISPLAY_NAME
)
)
} catch (_: Exception) {
} catch (_: Throwable) {
Build.MODEL
}
val takenTimestamp: Long? = try {
getLong(getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_TAKEN))
} catch (_: Exception) {
} catch (_: Throwable) {
null
}
val modifiedTimestamp: Long =
getLong(getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED))
val duration: String? = try {
getString(getColumnIndexOrThrow(MediaStore.MediaColumns.DURATION))
} catch (_: Exception) {
} catch (_: Throwable) {
null
}

val expiryTimestamp: Long? = try {
getLong(getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_EXPIRES))
} catch (_: Exception) {
} catch (_: Throwable) {
null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ package ru.tech.imageresizershrinker.feature.media_picker.data.utils

import android.content.ContentResolver
import android.content.ContentUris
import android.content.Context
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.webkit.MimeTypeMap
import androidx.annotation.RequiresApi
import kotlinx.coroutines.coroutineScope
import ru.tech.imageresizershrinker.core.resources.BuildConfig
import ru.tech.imageresizershrinker.feature.media_picker.domain.model.Album
import ru.tech.imageresizershrinker.feature.media_picker.domain.model.EXTENDED_DATE_FORMAT
import ru.tech.imageresizershrinker.feature.media_picker.domain.model.Media
import ru.tech.imageresizershrinker.feature.media_picker.domain.model.MediaOrder
import ru.tech.imageresizershrinker.feature.media_picker.domain.model.OrderType
import java.io.File
import kotlin.random.Random

@RequiresApi(26)
sealed class Query(
Expand Down Expand Up @@ -234,7 +226,7 @@ suspend fun ContentResolver.getAlbums(
MediaStore.MediaColumns.BUCKET_DISPLAY_NAME
)
)
} catch (_: Exception) {
} catch (_: Throwable) {
Build.MODEL
}
val thumbnailPath =
Expand Down Expand Up @@ -284,57 +276,4 @@ suspend fun ContentResolver.getAlbums(
println("Album parsing took: ${System.currentTimeMillis() - timeStart}ms")
}
}
}

fun mediaFromUri(
context: Context,
uri: Uri
): Media? {
if (uri.path == null) return null
val extension = uri.toString().substringAfterLast(".")
var mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension).toString()
var duration: String? = null
try {
val retriever = MediaMetadataRetriever().apply {
setDataSource(context, uri)
}
val hasVideo =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO)
val isVideo = "yes" == hasVideo
if (isVideo) {
duration =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
}
if (mimeType.isEmpty()) {
mimeType = if (isVideo) "video/*" else "image/*"
}
} catch (_: Exception) {
}
var timestamp = 0L
uri.path?.let { File(it) }?.let {
timestamp = try {
it.lastModified()
} catch (_: Exception) {
0L
}
}
var formattedDate = ""
if (timestamp != 0L) {
formattedDate = timestamp.getDate(EXTENDED_DATE_FORMAT)
}
return Media(
id = Random(System.currentTimeMillis()).nextLong(-1000, 25600000),
label = uri.toString().substringAfterLast("/"),
uri = uri.toString(),
path = uri.path.toString(),
relativePath = uri.path.toString().substringBeforeLast("/"),
albumID = -99L,
albumLabel = "",
timestamp = timestamp,
fullDate = formattedDate,
mimeType = mimeType,
duration = duration,
favorite = 0,
trashed = 0
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import androidx.compose.material.icons.filled.Error
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand Down Expand Up @@ -102,6 +101,7 @@ import ru.tech.imageresizershrinker.core.ui.theme.White
import ru.tech.imageresizershrinker.core.ui.theme.takeColorFromScheme
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedTopAppBar
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedTopAppBarDefaults
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedTopAppBarType
import ru.tech.imageresizershrinker.core.ui.widget.image.Picture
import ru.tech.imageresizershrinker.core.ui.widget.modifier.toShape
Expand Down Expand Up @@ -304,7 +304,7 @@ internal fun MediaImagePager(
exit = fadeOut() + slideOutVertically()
) {
EnhancedTopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
colors = EnhancedTopAppBarDefaults.colors(
containerColor = MaterialTheme.colorScheme.scrim.copy(alpha = 0.5f)
),
type = EnhancedTopAppBarType.Center,
Expand Down Expand Up @@ -437,7 +437,7 @@ internal fun MediaImagePager(
predictiveBackProgress = event.progress
}
onDismiss()
} catch (_: Exception) {
} catch (_: Throwable) {
predictiveBackProgress = 0f
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal fun PdfPage(
bitmap = destinationBitmap.asImage()
}
}
} catch (_: Exception) {
} catch (_: Throwable) {
//Just catch and return in case the renderer is being closed
return@launch
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ fun FullscreenEditOption(
predictiveBackProgress = event.progress
}
internalOnDismiss()
} catch (_: Exception) {
} catch (_: Throwable) {
predictiveBackProgress = 0f
}
}
Expand Down

0 comments on commit 15b58ce

Please sign in to comment.