@@ -18,9 +18,15 @@ import androidx.appcompat.content.res.AppCompatResources
1818import androidx.core.content.ContextCompat
1919import androidx.core.content.edit
2020import androidx.core.graphics.toColorInt
21+ import androidx.core.view.updateLayoutParams
22+ import androidx.recyclerview.widget.GridLayoutManager
2123import be.scri.R
2224import be.scri.R.color.white
2325import be.scri.databinding.InputMethodViewBinding
26+ import be.scri.helpers.AutoGridLayoutManager
27+ import be.scri.helpers.EMOJI_SPEC_FILE_PATH
28+ import be.scri.helpers.EmojiAdapter
29+ import be.scri.helpers.EmojiData
2430import be.scri.helpers.KeyboardBase
2531import be.scri.helpers.KeyboardLanguageMappingConstants.conjugatePlaceholder
2632import be.scri.helpers.KeyboardLanguageMappingConstants.pluralPlaceholder
@@ -29,18 +35,11 @@ import be.scri.helpers.LanguageMappingConstants.getLanguageAlias
2935import be.scri.helpers.PreferencesHelper
3036import be.scri.helpers.PreferencesHelper.getIsDarkModeOrNot
3137import be.scri.helpers.english.ENInterfaceVariables.ALREADY_PLURAL_MSG
38+ import be.scri.helpers.getCategoryIconRes
39+ import be.scri.helpers.parseRawEmojiSpecsFile
3240import be.scri.models.ScribeState
3341import be.scri.services.GeneralKeyboardIME
3442import be.scri.views.KeyboardView
35- import be.scri.helpers.EmojiAdapter
36- import be.scri.helpers.EMOJI_SPEC_FILE_PATH
37- import be.scri.helpers.parseRawEmojiSpecsFile
38- import be.scri.helpers.getCategoryIconRes
39-
40- import be.scri.helpers.AutoGridLayoutManager
41- import be.scri.helpers.EmojiData
42- import androidx.recyclerview.widget.GridLayoutManager
43- import androidx.core.view.updateLayoutParams
4443
4544/* *
4645 * Manages the UI elements and state transitions for the GeneralKeyboardIME.
@@ -764,23 +763,22 @@ class KeyboardUIManager(
764763 }
765764
766765 /* *
767- * Displays the emoji palette by showing the emoji palette holder and hiding the keyboard view.
768- * Based on Fossify's openEmojiPalette() and setupEmojis() approach.
766+ * Displays the emoji palette and hides the keyboard view.
769767 * Loads emojis from the emoji spec file on a background thread and populates the grid.
770768 */
771769 fun showEmojiPalette () {
772770 binding.keyboardView.post {
773771 val keyboardHeight = binding.keyboardView.measuredHeight
774- val toolbarHeight = binding.commandOptionsBar.measuredHeight.takeIf { it > 0 }
775- ? : context.resources.getDimensionPixelSize(R .dimen.toolbar_height)
772+ val toolbarHeight =
773+ binding.commandOptionsBar.measuredHeight.takeIf { it > 0 }
774+ ? : context.resources.getDimensionPixelSize(R .dimen.toolbar_height)
776775
777776 binding.emojiPaletteHolder.updateLayoutParams {
778777 height = keyboardHeight + toolbarHeight
779778 }
780779 binding.emojiPaletteHolder.requestLayout()
781780 }
782781
783-
784782 binding.emojiPaletteHolder.visibility = View .VISIBLE
785783
786784 binding.keyboardView.visibility = View .GONE
@@ -795,7 +793,7 @@ class KeyboardUIManager(
795793 }
796794 binding.emojiPaletteModeChange.text = " ABC"
797795 binding.emojiPaletteModeChange.setTextColor(
798- ContextCompat .getColor(context, R .color.emoji_palette_icons)
796+ ContextCompat .getColor(context, R .color.emoji_palette_icons),
799797 )
800798
801799 binding.emojiPaletteBackspace.setOnClickListener {
@@ -804,28 +802,23 @@ class KeyboardUIManager(
804802
805803 Thread {
806804 val fullEmojiList = parseRawEmojiSpecsFile(context, EMOJI_SPEC_FILE_PATH )
807- val systemFontPaint = android.graphics.Paint ().apply {
808- typeface = android.graphics.Typeface .DEFAULT
809- }
810- val emojis = fullEmojiList.filter { emoji ->
811- systemFontPaint.hasGlyph(emoji.emoji)
812- }
805+ val systemFontPaint =
806+ android.graphics.Paint ().apply {
807+ typeface = android.graphics.Typeface .DEFAULT
808+ }
809+ val emojis =
810+ fullEmojiList.filter { emoji ->
811+ systemFontPaint.hasGlyph(emoji.emoji)
812+ }
813813
814814 android.os.Handler (android.os.Looper .getMainLooper()).post {
815815 setupEmojiAdapter(emojis)
816816 }
817817 }.start()
818818 }
819819
820- /* *
821- * Sets up the emoji RecyclerView grid and category strip.
822- *
823- * @param items The flat list of category headers and emojis.
824- * @param categories The map of category name to emoji list for category strip setup.
825- */
826820 /* *
827821 * Sets up the emoji RecyclerView adapter and category strip.
828- * Based on Fossify's setupEmojiAdapter() implementation.
829822 *
830823 * @param emojis The filtered list of emojis the device can render.
831824 */
@@ -836,36 +829,35 @@ class KeyboardUIManager(
836829 val emojiItemSize = context.resources.getDimensionPixelSize(R .dimen.emoji_item_size)
837830 val emojiLayoutManager = AutoGridLayoutManager (context, emojiItemSize)
838831
839- emojiLayoutManager.spanSizeLookup = object : GridLayoutManager .SpanSizeLookup () {
840- override fun getSpanSize (position : Int ): Int =
841- if (emojiItems[position] is EmojiAdapter .Item .Category ) {
842- emojiLayoutManager.spanCount
843- } else {
844- 1
845- }
846- }
832+ emojiLayoutManager.spanSizeLookup =
833+ object : GridLayoutManager .SpanSizeLookup () {
834+ override fun getSpanSize (position : Int ): Int =
835+ if (emojiItems[position] is EmojiAdapter .Item .Category ) {
836+ emojiLayoutManager.spanCount
837+ } else {
838+ 1
839+ }
840+ }
847841
848842 binding.emojisList.layoutManager = emojiLayoutManager
849- binding.emojisList.adapter = EmojiAdapter (context, emojiItems) { emojiData ->
850- listener.onEmojiSelected(emojiData.emoji)
851- }
843+ binding.emojisList.adapter =
844+ EmojiAdapter (context, emojiItems) { emojiData ->
845+ listener.onEmojiSelected(emojiData.emoji)
846+ }
852847
853848 setupEmojiCategoryStrip(emojiCategories, emojiItems, emojiLayoutManager)
854849 }
855850
856851 /* *
857852 * Groups emojis by category.
858- * Based on Fossify's prepareEmojiCategories() implementation.
859853 *
860854 * @param emojis The full list of emojis.
861- * @return A map of category name to list of emojis in that category.
855+ * @return A map of category name to list of emojis in corresponding category.
862856 */
863- private fun prepareEmojiCategories (emojis : List <EmojiData >): Map <String , List <EmojiData >> =
864- emojis.groupBy { it.category }
857+ private fun prepareEmojiCategories (emojis : List <EmojiData >): Map <String , List <EmojiData >> = emojis.groupBy { it.category }
865858
866859 /* *
867- * Builds a flat list of category headers and emoji items for the RecyclerView.
868- * Based on Fossify's prepareEmojiItems() implementation.
860+ * Builds a list of category headers and emoji items for the RecyclerView.
869861 *
870862 * @param categories The map of categories to their emojis.
871863 * @return A flat list of [EmojiAdapter.Item] objects.
@@ -884,15 +876,6 @@ class KeyboardUIManager(
884876 * Tapping a category icon scrolls the emoji list to that category.
885877 *
886878 * @param categories The map of category names to their emojis.
887- * @param items The full flat list used to find category positions.
888- * @param layoutManager The GridLayoutManager used to scroll to positions.
889- */
890- /* *
891- * Populates the emoji category strip at the bottom of the palette.
892- * Tapping a category icon scrolls the emoji list to that category.
893- * Based on Fossify's setupEmojiAdapter() category strip implementation.
894- *
895- * @param categories The map of category names to their emojis.
896879 * @param emojiItems The full flat list used to find category positions.
897880 * @param layoutManager The AutoGridLayoutManager used to scroll to positions.
898881 */
@@ -906,29 +889,32 @@ class KeyboardUIManager(
906889 var activeButton: android.widget.ImageButton ? = null
907890
908891 categories.keys.forEachIndexed { index, category ->
909- val button = android.widget.ImageButton (context).apply {
910- setImageResource(getCategoryIconRes(category))
911- background = null
912- imageAlpha = if (index == 0 ) 255 else 128 // 50% opacity for inactive
913- layoutParams = android.widget.LinearLayout .LayoutParams (
914- 0 ,
915- android.widget.LinearLayout .LayoutParams .MATCH_PARENT ,
916- 1f ,
917- )
918- setOnClickListener {
919- activeButton?.imageAlpha = 128 // dim previous
920- imageAlpha = 255 // full opacity for active
921- activeButton = this
922-
923- val position = emojiItems.indexOfFirst {
924- it is EmojiAdapter .Item .Category && it.value == category
925- }
926- if (position != - 1 ) {
927- (layoutManager as androidx.recyclerview.widget.LinearLayoutManager )
928- .scrollToPositionWithOffset(position, 0 )
892+ val button =
893+ android.widget.ImageButton (context).apply {
894+ setImageResource(getCategoryIconRes(category))
895+ background = null
896+ imageAlpha = if (index == 0 ) 255 else 128 // 50% opacity for inactive
897+ layoutParams =
898+ android.widget.LinearLayout .LayoutParams (
899+ 0 ,
900+ android.widget.LinearLayout .LayoutParams .MATCH_PARENT ,
901+ 1f ,
902+ )
903+ setOnClickListener {
904+ activeButton?.imageAlpha = 128 // dim previous.
905+ imageAlpha = 255 // full opacity for active.
906+ activeButton = this
907+
908+ val position =
909+ emojiItems.indexOfFirst {
910+ it is EmojiAdapter .Item .Category && it.value == category
911+ }
912+ if (position != - 1 ) {
913+ (layoutManager as androidx.recyclerview.widget.LinearLayoutManager )
914+ .scrollToPositionWithOffset(position, 0 )
915+ }
929916 }
930917 }
931- }
932918
933919 if (index == 0 ) activeButton = button
934920 binding.emojiCategoriesStrip.addView(button)
0 commit comments