-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert MainDialog class to Kotlin. (#663)
1 parent
08f7379
commit 005d73b
Showing
3 changed files
with
92 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 0 additions & 109 deletions
109
app/src/main/java/com/vanniktech/emoji/sample/MainDialog.java
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/vanniktech/emoji/sample/MainDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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.sample | ||
|
||
import android.app.Dialog | ||
import android.graphics.PorterDuff | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.View | ||
import android.widget.EditText | ||
import android.widget.ImageButton | ||
import android.widget.ImageView | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.vanniktech.emoji.EmojiPopup | ||
import com.vanniktech.emoji.emoji.Emoji | ||
import com.vanniktech.emoji.material.MaterialEmojiLayoutFactory | ||
|
||
// We don't care about duplicated code in the sample. | ||
class MainDialog : DialogFragment() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
layoutInflater.factory2 = MaterialEmojiLayoutFactory(null) | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
return AlertDialog.Builder(requireContext()) | ||
.setView(buildView()) | ||
.create() | ||
} | ||
|
||
private fun buildView(): View? { | ||
val context = requireContext() | ||
val result = View.inflate(context, R.layout.dialog_main, null) | ||
val editText = result.findViewById<EditText>(R.id.main_dialog_chat_bottom_message_edittext) | ||
val rootView = result.findViewById<View>(R.id.main_dialog_root_view) | ||
val emojiButton = result.findViewById<ImageButton>(R.id.main_dialog_emoji) | ||
val sendButton = result.findViewById<ImageView>(R.id.main_dialog_send) | ||
|
||
val emojiPopup = EmojiPopup.Builder.fromRootView(rootView) | ||
.setOnEmojiBackspaceClickListener { Log.d(TAG, "Clicked on Backspace") } | ||
.setOnEmojiClickListener { emoji: Emoji -> Log.d(TAG, "Clicked on Emoji " + emoji.unicode) } | ||
.setOnEmojiPopupShownListener { emojiButton.setImageResource(R.drawable.ic_keyboard) } | ||
.setOnSoftKeyboardOpenListener { px -> Log.d(TAG, "Opened soft keyboard with height $px") } | ||
.setOnEmojiPopupDismissListener { emojiButton.setImageResource(R.drawable.emoji_ios_category_smileysandpeople) } | ||
.setOnSoftKeyboardCloseListener { Log.d(TAG, "Closed soft keyboard") } | ||
.setKeyboardAnimationStyle(R.style.emoji_fade_animation_style) | ||
.setPageTransformer(PageTransformer()) | ||
.build(editText) | ||
|
||
emojiButton.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary), PorterDuff.Mode.SRC_IN) | ||
sendButton.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary), PorterDuff.Mode.SRC_IN) | ||
val chatAdapter = ChatAdapter() | ||
emojiButton.setOnClickListener { emojiPopup.toggle() } | ||
sendButton.setOnClickListener { | ||
val text = editText.text.toString().trim { it <= ' ' } | ||
if (text.isNotEmpty()) { | ||
chatAdapter.add(text) | ||
editText.setText("") | ||
} | ||
} | ||
val recyclerView: RecyclerView = result.findViewById(R.id.main_dialog_recycler_view) | ||
recyclerView.adapter = chatAdapter | ||
return rootView | ||
} | ||
|
||
internal companion object { | ||
const val TAG = "MainDialog" | ||
|
||
fun show(activity: AppCompatActivity) { | ||
MainDialog().show(activity.supportFragmentManager, TAG) | ||
} | ||
} | ||
} |