From 953cdea115d3ba7c54ff8423cb3cf8cc1d76096e Mon Sep 17 00:00:00 2001 From: tateisu Date: Fri, 3 Mar 2023 01:38:58 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B5=B5=E6=96=87=E5=AD=97=E3=83=94=E3=83=83?= =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=81=AE=E3=83=98=E3=83=83=E3=83=80=E3=81=BE?= =?UTF-8?q?=E3=82=8F=E3=82=8A=E3=82=92isWrapBefore=E3=81=A7=E8=AA=BF?= =?UTF-8?q?=E6=95=B4=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subwaytooter/dialog/EmojiPicker.kt | 42 +++++++++++++++---- .../main/res/layout/emoji_picker_dialog.xml | 3 ++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt b/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt index 9ea1df9a..36ce764d 100644 --- a/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt +++ b/app/src/main/java/jp/juggler/subwaytooter/dialog/EmojiPicker.kt @@ -66,8 +66,14 @@ private class EmojiPicker( } private sealed interface PickerItem - private class PickerItemUnicode(val unicodeEmoji: UnicodeEmoji) : PickerItem - private class PickerItemCustom(val customEmoji: CustomEmoji) : PickerItem + + private class PickerItemUnicode(val unicodeEmoji: UnicodeEmoji) : PickerItem { + var isWrapBefore = false + } + + private class PickerItemCustom(val customEmoji: CustomEmoji) : PickerItem { + var isWrapBefore = false + } private open class PickerItemCategory( var name: String, @@ -198,6 +204,7 @@ private class EmojiPicker( } private inner class VhCategory( + parent: ViewGroup, view: FrameLayout = FrameLayout(activity), ) : ViewHolderBase(view) { var lastItem: PickerItemCategory? = null @@ -228,9 +235,11 @@ private class EmojiPicker( } init { - view.layoutParams = FlexboxLayoutManager.LayoutParams(0, wrapContent).apply { - flexBasisPercent = 100f - } + view.layoutParams = FlexboxLayoutManager.LayoutParams(wrapContent, wrapContent) + .apply { + flexGrow = 1f + isWrapBefore = true + } view.setPadding(cellMargin, cellMargin, cellMargin, cellMargin) view.addView(tv) } @@ -255,6 +264,12 @@ private class EmojiPicker( } } + private fun View.updateWrapBefore(isWrapBefore:Boolean){ + val lp = layoutParams as FlexboxLayoutManager.LayoutParams + lp.isWrapBefore = isWrapBefore + layoutParams = lp + } + private inner class VhCustomEmoji( val view: FrameLayout = FrameLayout(activity), ) : ViewHolderBase(view) { @@ -277,6 +292,7 @@ private class EmojiPicker( override fun bind(item: PickerItem) { if (activity.isDestroyed) return if (item is PickerItemCustom) { + view.updateWrapBefore(item.isWrapBefore) view.setTag(R.id.btnAbout, item) niv.setEmoji( url = if (disableAnimation) { @@ -310,6 +326,7 @@ private class EmojiPicker( override fun bind(item: PickerItem) { if (activity.isDestroyed) return if (item is PickerItemUnicode) { + view.updateWrapBefore(item.isWrapBefore) view.setTag(R.id.btnAbout, item) val emoji = applySkinTone(item.unicodeEmoji) if (emoji.isSvg) { @@ -347,6 +364,7 @@ private class EmojiPicker( override fun bind(item: PickerItem) { if (activity.isDestroyed) return if (item is PickerItemUnicode) { + view.updateWrapBefore(item.isWrapBefore) view.setTag(R.id.btnAbout, item) val unicodeEmoji = applySkinTone(item.unicodeEmoji) tv.text = unicodeEmoji.unifiedCode @@ -383,7 +401,7 @@ private class EmojiPicker( override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int) = when (viewType) { - VT_CATEGORY -> VhCategory() + VT_CATEGORY -> VhCategory(viewGroup) VT_CUSTOM_EMOJI -> VhCustomEmoji() VT_TWEMOJI -> VhTwemoji() VT_COMPAT_EMOJI -> VhAppCompatEmoji() @@ -616,7 +634,7 @@ private class EmojiPicker( keywordLower.isNullOrEmpty() && (selectedCategory == null || selectedCategory == EmojiCategory.Custom) - adapter.list = buildList { + val list = buildList { val filteredCategories = pickerCategries.filter { selectedCategory == null || it.category == selectedCategory }.mapNotNull { category -> @@ -645,6 +663,16 @@ private class EmojiPicker( } } } + list.forEachIndexed { i,v-> + fun isPreviousHeader()=list.elementAtOrNull(i-1) is PickerItemCategory + when(v) { + is PickerItemUnicode -> v.isWrapBefore = isPreviousHeader() + is PickerItemCustom -> v.isWrapBefore = isPreviousHeader() + else -> Unit + } + } + + adapter.list = list val targetCategory = lastExpandCategory if (scrollToCategory && targetCategory != null) { diff --git a/app/src/main/res/layout/emoji_picker_dialog.xml b/app/src/main/res/layout/emoji_picker_dialog.xml index 7790d7ef..b79aaa6a 100644 --- a/app/src/main/res/layout/emoji_picker_dialog.xml +++ b/app/src/main/res/layout/emoji_picker_dialog.xml @@ -2,6 +2,7 @@