Универсальные обои для всех разрешений
This commit is contained in:
@@ -2,13 +2,7 @@ package com.rosetta.messenger.ui.chats
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.graphics.Shader
|
|
||||||
import android.graphics.drawable.BitmapDrawable
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.View
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
@@ -80,7 +74,6 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
@@ -2335,10 +2328,9 @@ fun ChatDetailScreen(
|
|||||||
// Keep wallpaper on a fixed full-screen layer so it doesn't rescale
|
// Keep wallpaper on a fixed full-screen layer so it doesn't rescale
|
||||||
// when content paddings (bottom bar/IME) change.
|
// when content paddings (bottom bar/IME) change.
|
||||||
if (chatWallpaperResId != null) {
|
if (chatWallpaperResId != null) {
|
||||||
TiledChatWallpaper(
|
ChatWallpaperBackground(
|
||||||
wallpaperResId = chatWallpaperResId,
|
wallpaperResId = chatWallpaperResId,
|
||||||
modifier = Modifier.matchParentSize(),
|
modifier = Modifier.matchParentSize()
|
||||||
tileScale = 0.9f
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Box(
|
Box(
|
||||||
@@ -3676,60 +3668,14 @@ private fun GroupMembersSubtitleSkeleton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun TiledChatWallpaper(
|
private fun ChatWallpaperBackground(
|
||||||
wallpaperResId: Int,
|
wallpaperResId: Int,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier
|
||||||
tileScale: Float = 0.9f
|
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
Image(
|
||||||
val wallpaperDrawable =
|
painter = painterResource(id = wallpaperResId),
|
||||||
remember(wallpaperResId, tileScale, context) {
|
contentDescription = "Chat wallpaper",
|
||||||
val decoded = BitmapFactory.decodeResource(context.resources, wallpaperResId)
|
|
||||||
val normalizedScale = tileScale.coerceIn(0.2f, 2f)
|
|
||||||
|
|
||||||
val scaledBitmap =
|
|
||||||
decoded?.let { original ->
|
|
||||||
if (normalizedScale == 1f) {
|
|
||||||
original
|
|
||||||
} else {
|
|
||||||
val width =
|
|
||||||
(original.width * normalizedScale)
|
|
||||||
.toInt()
|
|
||||||
.coerceAtLeast(1)
|
|
||||||
val height =
|
|
||||||
(original.height * normalizedScale)
|
|
||||||
.toInt()
|
|
||||||
.coerceAtLeast(1)
|
|
||||||
val scaled =
|
|
||||||
Bitmap.createScaledBitmap(
|
|
||||||
original,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
if (scaled != original) {
|
|
||||||
original.recycle()
|
|
||||||
}
|
|
||||||
scaled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val safeBitmap =
|
|
||||||
scaledBitmap
|
|
||||||
?: Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
|
|
||||||
.apply {
|
|
||||||
eraseColor(android.graphics.Color.TRANSPARENT)
|
|
||||||
}
|
|
||||||
|
|
||||||
BitmapDrawable(context.resources, safeBitmap).apply {
|
|
||||||
setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)
|
|
||||||
gravity = Gravity.TOP or Gravity.START
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AndroidView(
|
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
factory = { ctx -> View(ctx).apply { background = wallpaperDrawable } },
|
contentScale = ContentScale.Crop
|
||||||
update = { view -> view.background = wallpaperDrawable }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user