From 84c35269fe2c7da38dc80e53d37f35c4e21547c8 Mon Sep 17 00:00:00 2001 From: nvgurova Date: Wed, 5 Feb 2025 12:45:46 +0300 Subject: [PATCH] - Refactored `CustomImageResizeTransformation` to use try-catch. - Removed unnecessary code in `DefaultUserSettingsCache` and `UserSettingsCache`. - Changed `urlBuilder.original(image)` to `urlBuilder.large(image)` (width = 1080px). --- .../other/CustomImageResizeTransformation.kt | 49 ++++++++++--------- .../data/auth/repo/UserSettingsCache.kt | 5 -- .../repo/DefaultUserSettingsCache.kt | 16 ------ .../editor/render/DefaultBlockViewRenderer.kt | 2 +- 4 files changed, 28 insertions(+), 44 deletions(-) diff --git a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/other/CustomImageResizeTransformation.kt b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/other/CustomImageResizeTransformation.kt index d59cc5d152..f8082f2ba3 100644 --- a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/other/CustomImageResizeTransformation.kt +++ b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/other/CustomImageResizeTransformation.kt @@ -16,35 +16,40 @@ class CustomImageResizeTransformation( outWidth: Int, outHeight: Int ): Bitmap { - val imageWidth = toTransform.width - val imageHeight = toTransform.height - val targetAspectRatio = maxWidth.toFloat() / maxHeight + return try { + val imageWidth = toTransform.width + val imageHeight = toTransform.height + val targetAspectRatio = maxWidth.toFloat() / maxHeight - return when { - imageWidth > maxWidth && imageHeight > maxHeight -> { - val imageAspectRatio = imageWidth.toFloat() / imageHeight + when { + imageWidth > maxWidth && imageHeight > maxHeight -> { + val imageAspectRatio = imageWidth.toFloat() / imageHeight - if (imageAspectRatio > targetAspectRatio) { - val cropWidth = (imageHeight * targetAspectRatio).toInt() - val cropStartX = (imageWidth - cropWidth) / 2 - Bitmap.createBitmap(toTransform, cropStartX, 0, cropWidth, imageHeight) - } else { + if (imageAspectRatio > targetAspectRatio) { + val cropWidth = (imageHeight * targetAspectRatio).toInt() + val cropStartX = (imageWidth - cropWidth) / 2 + Bitmap.createBitmap(toTransform, cropStartX, 0, cropWidth, imageHeight) + } else { + val cropHeight = (imageWidth / targetAspectRatio).toInt() + val cropStartY = (imageHeight - cropHeight) / 2 + Bitmap.createBitmap(toTransform, 0, cropStartY, imageWidth, cropHeight) + } + } + imageWidth > maxWidth && imageHeight <= maxHeight -> { + val scaleFactor = maxWidth.toFloat() / imageWidth + val newHeight = (imageHeight * scaleFactor).toInt() + Bitmap.createScaledBitmap(toTransform, maxWidth, newHeight, true) + } + imageHeight > maxHeight && imageWidth <= maxWidth -> { val cropHeight = (imageWidth / targetAspectRatio).toInt() val cropStartY = (imageHeight - cropHeight) / 2 Bitmap.createBitmap(toTransform, 0, cropStartY, imageWidth, cropHeight) } + else -> toTransform } - imageWidth > maxWidth && imageHeight <= maxHeight -> { - val scaleFactor = maxWidth.toFloat() / imageWidth - val newHeight = (imageHeight * scaleFactor).toInt() - Bitmap.createScaledBitmap(toTransform, maxWidth, newHeight, true) - } - imageHeight > maxHeight && imageWidth <= maxWidth -> { - val cropHeight = (imageWidth / targetAspectRatio).toInt() - val cropStartY = (imageHeight - cropHeight) / 2 - Bitmap.createBitmap(toTransform, 0, cropStartY, imageWidth, cropHeight) - } - else -> toTransform + } catch (e: Exception) { + e.printStackTrace() + toTransform } } diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt index 41bbf39ee2..0023c2c440 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt @@ -47,11 +47,6 @@ interface UserSettingsCache { suspend fun getAllContentSort(space: SpaceId): Pair? suspend fun setAllContentSort(space: SpaceId, sort: Id, isAsc: Boolean) - suspend fun setTooltipShown(shown: Boolean) - suspend fun isTooltipShown(): Boolean - suspend fun setSpaceSwitchCount(count: Int) - suspend fun getSpaceSwitchCount(): Int - suspend fun setRelativeDates(account: Account, enabled: Boolean) suspend fun setDateFormat(account: Account, format: String) diff --git a/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt b/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt index d66c4c80af..264f0899df 100644 --- a/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt +++ b/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt @@ -570,22 +570,6 @@ class DefaultUserSettingsCache( } } - override suspend fun setTooltipShown(shown: Boolean) { - prefs.edit().putBoolean(TOOLTIP_SHOWN_KEY, shown).apply() - } - - override suspend fun isTooltipShown(): Boolean { - return prefs.getBoolean(TOOLTIP_SHOWN_KEY, false) - } - - override suspend fun setSpaceSwitchCount(count: Int) { - prefs.edit().putInt(SPACE_SWITCH_COUNT_KEY, count).apply() - } - - override suspend fun getSpaceSwitchCount(): Int { - return prefs.getInt(SPACE_SWITCH_COUNT_KEY, 0) - } - companion object { const val CURRENT_SPACE_KEY = "prefs.user_settings.current_space" const val DEFAULT_OBJECT_TYPE_ID_KEY = "prefs.user_settings.default_object_type.id" diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt index a7de42cee0..f69226bb9a 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt @@ -1516,7 +1516,7 @@ class DefaultBlockViewRenderer @Inject constructor( text = fieldParser.getObjectName(currentObject), image = currentObject.iconImage?.let { image -> if (image.isNotBlank()) - urlBuilder.original(image) + urlBuilder.large(image) else null },