From ee601bb59045e586a9a58b9db28bce810ea285bb Mon Sep 17 00:00:00 2001 From: Smarshal21 Date: Wed, 8 Nov 2023 18:06:56 +0530 Subject: [PATCH] Replaced EmojiPicker in SetStatusDialogFragment Signed-off-by: Smarshal21 --- app/build.gradle | 1 + .../talk/ui/dialog/SetStatusDialogFragment.kt | 98 +++++++++---------- app/src/main/res/layout/dialog_set_status.xml | 9 +- 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 742eece69..fc0f4456c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -180,6 +180,7 @@ dependencies { implementation "androidx.emoji2:emoji2-bundled:${emojiVersion}" implementation "androidx.emoji2:emoji2-views:${emojiVersion}" implementation "androidx.emoji2:emoji2-views-helper:${emojiVersion}" + implementation "androidx.emoji2:emoji2-emojipicker:${emojiVersion}" implementation 'org.michaelevans.colorart:library:0.0.3' implementation "androidx.work:work-runtime:${workVersion}" implementation "androidx.work:work-rxjava2:${workVersion}" diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt index e92ae94b1..523e2c068 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt @@ -29,6 +29,8 @@ import android.os.Bundle import android.util.Log import android.view.LayoutInflater import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE import android.view.ViewGroup import android.view.inputmethod.InputMethodManager import android.widget.AdapterView @@ -62,8 +64,6 @@ import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.vanniktech.emoji.EmojiPopup -import com.vanniktech.emoji.installDisableKeyboardInput -import com.vanniktech.emoji.installForceSingleEmoji import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -90,10 +90,10 @@ private const val FOUR_HOURS = 4 private const val LAST_HOUR_OF_DAY = 23 private const val LAST_MINUTE_OF_HOUR = 59 private const val LAST_SECOND_OF_MINUTE = 59 +private var isEmojiPickerVisible = false @AutoInjector(NextcloudTalkApplication::class) -class SetStatusDialogFragment : - DialogFragment(), PredefinedStatusClickListener { +class SetStatusDialogFragment : DialogFragment(), PredefinedStatusClickListener { private var selectedPredefinedStatus: PredefinedStatus? = null @@ -130,8 +130,7 @@ class SetStatusDialogFragment : credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token) ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(object : Observer { override fun onSubscribe(d: Disposable) { @@ -140,15 +139,11 @@ class SetStatusDialogFragment : override fun onNext(responseBody: ResponseBody) { val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse( - responseBody - .string(), - PredefinedStatusOverall::class.java + responseBody.string(), PredefinedStatusOverall::class.java ) predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) } - if (currentStatus?.messageIsPredefined == true && - currentStatus?.messageId?.isNotEmpty() == true - ) { + if (currentStatus?.messageIsPredefined == true && currentStatus?.messageId?.isNotEmpty() == true) { val messageId = currentStatus!!.messageId selectedPredefinedStatus = predefinedStatusesList.firstOrNull { ps -> messageId == ps.id } } @@ -193,22 +188,13 @@ class SetStatusDialogFragment : binding.clearStatus.setOnClickListener { clearStatus() } binding.setStatus.setOnClickListener { setStatusMessage() } - binding.emoji.setOnClickListener { openEmojiPopup() } - - popup = EmojiPopup( - rootView = view, - editText = binding.emoji, - onEmojiClickListener = { - popup.dismiss() - binding.emoji.clearFocus() - val imm: InputMethodManager = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as - InputMethodManager - imm.hideSoftInputFromWindow(binding.emoji.windowToken, 0) - } - ) - binding.emoji.installDisableKeyboardInput(popup) - binding.emoji.installForceSingleEmoji() - + binding.emojiPicker.setOnEmojiPickedListener() { + binding.emoji.text = (it.emoji) + binding.emojiPicker.visibility = GONE + isEmojiPickerVisible = false + val imm: InputMethodManager = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + imm.hideSoftInputFromWindow(binding.emoji.windowToken, 0) + } binding.clearStatusAfterSpinner.apply { this.adapter = createClearTimesArrayAdapter() onItemSelectedListener = object : OnItemSelectedListener { @@ -247,9 +233,9 @@ class SetStatusDialogFragment : binding.remainingClearTime.apply { binding.clearStatusMessageTextView.text = getString(R.string.clear_status_message) visibility = View.VISIBLE - text = DisplayUtils.getRelativeTimestamp(context, it.clearAt * ONE_SECOND_IN_MILLIS, true) - .toString() - .decapitalize(Locale.getDefault()) + text = + DisplayUtils.getRelativeTimestamp(context, it.clearAt * ONE_SECOND_IN_MILLIS, true).toString() + .decapitalize(Locale.getDefault()) setOnClickListener { visibility = View.GONE binding.clearStatusAfterSpinner.visibility = View.VISIBLE @@ -365,15 +351,23 @@ class SetStatusDialogFragment : return returnValue } - private fun openEmojiPopup() { - popup.show() + private fun toggleEmojiPicker() { + if (!isEmojiPickerVisible) { + val imm: InputMethodManager = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + imm.hideSoftInputFromWindow(binding.emoji.windowToken, 0) + binding.emojiPicker.visibility = VISIBLE + isEmojiPickerVisible = true + } else { + binding.emojiPicker.visibility = GONE + isEmojiPickerVisible = false + } } private fun clearStatus() { val credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token) ncApi.statusDeleteMessage(credentials, ApiUtils.getUrlForStatusMessage(currentUser?.baseUrl)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer { + .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Observer { override fun onSubscribe(d: Disposable) { // unused atm } @@ -397,10 +391,8 @@ class SetStatusDialogFragment : ncApi.setStatusType(credentials, ApiUtils.getUrlForSetStatusType(currentUser?.baseUrl), statusType.string) .subscribeOn( - Schedulers - .io() - ) - .observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer { + Schedulers.io() + ).observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer { override fun onSubscribe(d: Disposable) { // unused atm } @@ -464,19 +456,10 @@ class SetStatusDialogFragment : // The endpoint '/message/custom' expects a valid emoji as string or null val statusIcon = binding.emoji.text.toString().ifEmpty { null } - if (selectedPredefinedStatus == null || - selectedPredefinedStatus!!.message != inputText || - selectedPredefinedStatus!!.icon != binding.emoji.text.toString() - ) { + if (selectedPredefinedStatus == null || selectedPredefinedStatus!!.message != inputText || selectedPredefinedStatus!!.icon != binding.emoji.text.toString()) { ncApi.setCustomStatusMessage( - credentials, - ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl), - statusIcon, - inputText, - clearAt - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) + credentials, ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl), statusIcon, inputText, clearAt + ).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) ?.subscribe(object : Observer { override fun onSubscribe(d: Disposable) { @@ -504,9 +487,8 @@ class SetStatusDialogFragment : ApiUtils.getUrlForSetPredefinedStatus(currentUser?.baseUrl), selectedPredefinedStatus!!.id, if (clearAt == -1L) null else clearAt - ) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread())?.subscribe(object : Observer { + ).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) + ?.subscribe(object : Observer { override fun onSubscribe(d: Disposable) = Unit override fun onNext(t: GenericOverall) { @@ -524,6 +506,7 @@ class SetStatusDialogFragment : } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + binding.emoji.setOnClickListener { toggleEmojiPicker() } return binding.root } @@ -564,6 +547,13 @@ class SetStatusDialogFragment : } } + override fun onResume() { + super.onResume() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + /** * Fragment creator */ diff --git a/app/src/main/res/layout/dialog_set_status.xml b/app/src/main/res/layout/dialog_set_status.xml index f083b87bb..6d7a93a34 100644 --- a/app/src/main/res/layout/dialog_set_status.xml +++ b/app/src/main/res/layout/dialog_set_status.xml @@ -364,7 +364,7 @@ app:cardCornerRadius="24dp" app:cardElevation="0dp"> - + +