Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert EmojiArrayAdapter class to Kotlin. #644

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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