mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-07 21:37:02 +09:00
- Refactored CustomImageResizeTransformation
to use try-catch.
- Removed unnecessary code in `DefaultUserSettingsCache` and `UserSettingsCache`. - Changed `urlBuilder.original(image)` to `urlBuilder.large(image)` (width = 1080px).
This commit is contained in:
parent
a96ebb9aea
commit
84c35269fe
4 changed files with 28 additions and 44 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,11 +47,6 @@ interface UserSettingsCache {
|
|||
suspend fun getAllContentSort(space: SpaceId): Pair<Id, Boolean>?
|
||||
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)
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue