From 045a02141d48f79380f4761833ed1a50d4ab96f4 Mon Sep 17 00:00:00 2001 From: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> Date: Tue, 12 May 2020 13:13:01 +0300 Subject: [PATCH] #372: Fix emoji (#419) * #372: parse pirat flag emoji * #372: roll back * #372: temporary emoji fix * #372: filter emoji * #372: code style --- .../anytype/emojifier/DefaultEmojifier.kt | 19 +++++++++++++++++-- .../page/picker/PageIconPickerViewModel.kt | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/library-emojifier/src/main/java/com/agileburo/anytype/emojifier/DefaultEmojifier.kt b/library-emojifier/src/main/java/com/agileburo/anytype/emojifier/DefaultEmojifier.kt index 07d01050be..49e55d5bb1 100644 --- a/library-emojifier/src/main/java/com/agileburo/anytype/emojifier/DefaultEmojifier.kt +++ b/library-emojifier/src/main/java/com/agileburo/anytype/emojifier/DefaultEmojifier.kt @@ -10,7 +10,15 @@ class DefaultEmojifier : Emojifier { check(alias.isNotEmpty()) { "Alias cannot be empty" } return EmojiManager.getForAlias(alias).let { result -> Emoji( - unicode = result.unicode, + /** + * Fix pirate flag emoji render, after fixing + * in table https://github.com/vdurmont/emoji-java/blob/master/EMOJIS.md + * can be removed + */ + unicode = result.unicode.filterTextByChar( + value = '☠', + filterBy = '♾' + ), alias = result.aliases.first() ) } @@ -21,4 +29,11 @@ class DefaultEmojifier : Emojifier { val alias = name.substring(1, name.length - 1) return fromAlias(alias) } -} \ No newline at end of file +} + +fun String.filterTextByChar(value: Char, filterBy: Char): String = + if (contains(value)) { + filterNot { it == filterBy } + } else { + this + } \ No newline at end of file diff --git a/presentation/src/main/java/com/agileburo/anytype/presentation/page/picker/PageIconPickerViewModel.kt b/presentation/src/main/java/com/agileburo/anytype/presentation/page/picker/PageIconPickerViewModel.kt index 137c970961..eb9e8a1d65 100644 --- a/presentation/src/main/java/com/agileburo/anytype/presentation/page/picker/PageIconPickerViewModel.kt +++ b/presentation/src/main/java/com/agileburo/anytype/presentation/page/picker/PageIconPickerViewModel.kt @@ -149,11 +149,26 @@ class PageIconPickerViewModel( emojis.map { emoji -> PageIconPickerView.Emoji( alias = emoji.aliases.first(), - unicode = emoji.unicode + /** + * Fix pirate flag emoji render, after fixing + * in table https://github.com/vdurmont/emoji-java/blob/master/EMOJIS.md + * can be removed + */ + unicode = emoji.unicode.filterTextByChar( + value = '☠', + filterBy = '♾' + ) ) } } + private fun String.filterTextByChar(value: Char, filterBy: Char): String = + if (contains(value)) { + filterNot { it == filterBy } + } else { + this + } + fun onEvent(event: Event) { channel.offer(event) }