Skip to content

Commit

Permalink
Convert EmojiArrayAdapter class to Kotlin. (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored Apr 28, 2022
1 parent b6392c4 commit 6496c6a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 80 deletions.
79 changes: 0 additions & 79 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiArrayAdapter.java

This file was deleted.

56 changes: 56 additions & 0 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiArrayAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.vanniktech.emoji

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import com.vanniktech.emoji.emoji.Emoji
import com.vanniktech.emoji.listeners.OnEmojiClickListener
import com.vanniktech.emoji.listeners.OnEmojiLongClickListener

internal class EmojiArrayAdapter(
context: Context,
emojis: Array<Emoji>,
private val variantManager: VariantEmoji?,
private val listener: OnEmojiClickListener?,
private val longListener: OnEmojiLongClickListener?,
private val theming: EmojiTheming,
) : ArrayAdapter<Emoji>(context, 0, Utils.asListWithoutDuplicates(emojis)) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var image = convertView as? EmojiImageView
val context = context
if (image == null) {
image = LayoutInflater.from(context).inflate(R.layout.emoji_adapter_item_emoji, parent, false) as EmojiImageView
image.setOnEmojiClickListener(listener)
image.setOnEmojiLongClickListener(longListener)
}
val emoji = getItem(position)!!
val variantToUse = variantManager?.getVariant(emoji) ?: emoji
image.contentDescription = emoji.unicode
image.setEmoji(theming, variantToUse)
return image
}

fun updateEmojis(emojis: Collection<Emoji>) {
clear()
addAll(emojis)
notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private View initView(@NonNull final Context context, @NonNull final Emoji emoji
final LayoutInflater inflater = LayoutInflater.from(context);

for (final Emoji variant : variants) {
final ImageView emojiImage = (ImageView) inflater.inflate(R.layout.emoji_adapter_item, imageContainer, false);
final ImageView emojiImage = (ImageView) inflater.inflate(R.layout.emoji_adapter_item_emoji, imageContainer, false);
final ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) emojiImage.getLayoutParams();
final int margin = Utils.dpToPx(context, MARGIN);

Expand Down

0 comments on commit 6496c6a

Please sign in to comment.