feat: Limit emoji loading to 500 for performance and optimize image request size for faster loading
This commit is contained in:
@@ -52,10 +52,8 @@ data class EmojiCategory(
|
|||||||
val ranges: List<Pair<Int, Int>>
|
val ranges: List<Pair<Int, Int>>
|
||||||
)
|
)
|
||||||
|
|
||||||
// Порядок категорий: "All" первая, затем стандартные
|
// Порядок категорий
|
||||||
val EMOJI_CATEGORIES = listOf(
|
val EMOJI_CATEGORIES = listOf(
|
||||||
// 🔥 ALL - все эмодзи (первая категория)
|
|
||||||
EmojiCategory("All", "Все", Icons.Default.Apps, emptyList()),
|
|
||||||
// 😀 Smileys & Emotion
|
// 😀 Smileys & Emotion
|
||||||
EmojiCategory("Smileys", "Смайлы", Icons.Default.SentimentSatisfied, listOf(
|
EmojiCategory("Smileys", "Смайлы", Icons.Default.SentimentSatisfied, listOf(
|
||||||
0x1F600 to 0x1F64F,
|
0x1F600 to 0x1F64F,
|
||||||
@@ -177,18 +175,14 @@ object EmojiCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getEmojisForCategory(categoryKey: String): List<String> {
|
fun getEmojisForCategory(categoryKey: String): List<String> {
|
||||||
return if (categoryKey == "All") {
|
return emojisByCategory?.get(categoryKey) ?: emptyList()
|
||||||
allEmojis ?: emptyList()
|
|
||||||
} else {
|
|
||||||
emojisByCategory?.get(categoryKey) ?: emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun groupEmojis(allEmojis: List<String>): Map<String, List<String>> {
|
private fun groupEmojis(allEmojis: List<String>): Map<String, List<String>> {
|
||||||
val result = mutableMapOf<String, MutableList<String>>()
|
val result = mutableMapOf<String, MutableList<String>>()
|
||||||
val usedEmojis = mutableSetOf<String>()
|
val usedEmojis = mutableSetOf<String>()
|
||||||
|
|
||||||
EMOJI_CATEGORIES.filter { it.key != "All" }.forEach { category ->
|
EMOJI_CATEGORIES.forEach { category ->
|
||||||
result[category.key] = mutableListOf()
|
result[category.key] = mutableListOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,13 +245,14 @@ fun EmojiButton(
|
|||||||
label = "emojiScale"
|
label = "emojiScale"
|
||||||
)
|
)
|
||||||
|
|
||||||
val imageRequest = remember(unified, context) {
|
val imageRequest = remember(unified) {
|
||||||
ImageRequest.Builder(context)
|
ImageRequest.Builder(context)
|
||||||
.data("file:///android_asset/emoji/${unified.lowercase()}.png")
|
.data("file:///android_asset/emoji/${unified.lowercase()}.png")
|
||||||
.crossfade(false)
|
.crossfade(false)
|
||||||
.size(64)
|
.size(48) // Меньше размер = быстрее загрузка
|
||||||
.memoryCachePolicy(CachePolicy.ENABLED)
|
.memoryCachePolicy(CachePolicy.ENABLED)
|
||||||
.diskCachePolicy(CachePolicy.ENABLED)
|
.diskCachePolicy(CachePolicy.ENABLED)
|
||||||
|
.allowHardware(true) // Аппаратное ускорение
|
||||||
.memoryCacheKey("emoji_$unified")
|
.memoryCacheKey("emoji_$unified")
|
||||||
.diskCacheKey("emoji_$unified")
|
.diskCacheKey("emoji_$unified")
|
||||||
.build()
|
.build()
|
||||||
@@ -348,15 +343,18 @@ fun AppleEmojiPickerPanel(
|
|||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var selectedCategory by remember { mutableStateOf(EMOJI_CATEGORIES[0]) } // "All" по умолчанию
|
var selectedCategory by remember { mutableStateOf(EMOJI_CATEGORIES[0]) } // "All" по умолчанию
|
||||||
val gridState = rememberLazyGridState()
|
val gridState = rememberLazyGridState()
|
||||||
|
var shouldLoad by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// Загружаем эмодзи в фоне
|
// Отложенная загрузка эмодзи (чтобы не блокировать UI при открытии)
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
kotlinx.coroutines.delay(100) // Задержка 100ms для плавности
|
||||||
|
shouldLoad = true
|
||||||
EmojiCache.loadEmojis(context)
|
EmojiCache.loadEmojis(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Текущие эмодзи для выбранной категории
|
// Текущие эмодзи для выбранной категории
|
||||||
val currentEmojis = remember(selectedCategory.key, EmojiCache.isLoaded) {
|
val currentEmojis = remember(selectedCategory.key, EmojiCache.isLoaded, shouldLoad) {
|
||||||
if (EmojiCache.isLoaded) {
|
if (shouldLoad && EmojiCache.isLoaded) {
|
||||||
EmojiCache.getEmojisForCategory(selectedCategory.key)
|
EmojiCache.getEmojisForCategory(selectedCategory.key)
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
emptyList()
|
||||||
@@ -405,7 +403,7 @@ fun AppleEmojiPickerPanel(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Сетка эмодзи
|
// Сетка эмодзи
|
||||||
if (!EmojiCache.isLoaded) {
|
if (!shouldLoad || !EmojiCache.isLoaded) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -439,9 +437,9 @@ fun AppleEmojiPickerPanel(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(horizontal = 4.dp),
|
.padding(horizontal = 4.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(2.dp),
|
horizontalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
contentPadding = PaddingValues(vertical = 8.dp)
|
contentPadding = PaddingValues(vertical = 4.dp)
|
||||||
) {
|
) {
|
||||||
items(
|
items(
|
||||||
items = currentEmojis,
|
items = currentEmojis,
|
||||||
|
|||||||
Reference in New Issue
Block a user