Replaced EmojiPicker in SetStatusDialogFragment

Signed-off-by: Smarshal21 <lcb2021048@iiitl.ac.in>
This commit is contained in:
Smarshal21 2023-11-08 18:06:56 +05:30
parent 2f24c130ca
commit ee601bb590
3 changed files with 53 additions and 55 deletions

View file

@ -180,6 +180,7 @@ dependencies {
implementation "androidx.emoji2:emoji2-bundled:${emojiVersion}" implementation "androidx.emoji2:emoji2-bundled:${emojiVersion}"
implementation "androidx.emoji2:emoji2-views:${emojiVersion}" implementation "androidx.emoji2:emoji2-views:${emojiVersion}"
implementation "androidx.emoji2:emoji2-views-helper:${emojiVersion}" implementation "androidx.emoji2:emoji2-views-helper:${emojiVersion}"
implementation "androidx.emoji2:emoji2-emojipicker:${emojiVersion}"
implementation 'org.michaelevans.colorart:library:0.0.3' implementation 'org.michaelevans.colorart:library:0.0.3'
implementation "androidx.work:work-runtime:${workVersion}" implementation "androidx.work:work-runtime:${workVersion}"
implementation "androidx.work:work-rxjava2:${workVersion}" implementation "androidx.work:work-rxjava2:${workVersion}"

View file

@ -29,6 +29,8 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.AdapterView 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.DisplayUtils
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
import com.vanniktech.emoji.EmojiPopup import com.vanniktech.emoji.EmojiPopup
import com.vanniktech.emoji.installDisableKeyboardInput
import com.vanniktech.emoji.installForceSingleEmoji
import io.reactivex.Observer import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable 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_HOUR_OF_DAY = 23
private const val LAST_MINUTE_OF_HOUR = 59 private const val LAST_MINUTE_OF_HOUR = 59
private const val LAST_SECOND_OF_MINUTE = 59 private const val LAST_SECOND_OF_MINUTE = 59
private var isEmojiPickerVisible = false
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class SetStatusDialogFragment : class SetStatusDialogFragment : DialogFragment(), PredefinedStatusClickListener {
DialogFragment(), PredefinedStatusClickListener {
private var selectedPredefinedStatus: PredefinedStatus? = null private var selectedPredefinedStatus: PredefinedStatus? = null
@ -130,8 +130,7 @@ class SetStatusDialogFragment :
credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token) credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token)
ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl)) ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<ResponseBody> { .subscribe(object : Observer<ResponseBody> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
@ -140,15 +139,11 @@ class SetStatusDialogFragment :
override fun onNext(responseBody: ResponseBody) { override fun onNext(responseBody: ResponseBody) {
val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse( val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse(
responseBody responseBody.string(), PredefinedStatusOverall::class.java
.string(),
PredefinedStatusOverall::class.java
) )
predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) } predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) }
if (currentStatus?.messageIsPredefined == true && if (currentStatus?.messageIsPredefined == true && currentStatus?.messageId?.isNotEmpty() == true) {
currentStatus?.messageId?.isNotEmpty() == true
) {
val messageId = currentStatus!!.messageId val messageId = currentStatus!!.messageId
selectedPredefinedStatus = predefinedStatusesList.firstOrNull { ps -> messageId == ps.id } selectedPredefinedStatus = predefinedStatusesList.firstOrNull { ps -> messageId == ps.id }
} }
@ -193,22 +188,13 @@ class SetStatusDialogFragment :
binding.clearStatus.setOnClickListener { clearStatus() } binding.clearStatus.setOnClickListener { clearStatus() }
binding.setStatus.setOnClickListener { setStatusMessage() } binding.setStatus.setOnClickListener { setStatusMessage() }
binding.emoji.setOnClickListener { openEmojiPopup() } binding.emojiPicker.setOnEmojiPickedListener() {
binding.emoji.text = (it.emoji)
popup = EmojiPopup( binding.emojiPicker.visibility = GONE
rootView = view, isEmojiPickerVisible = false
editText = binding.emoji, val imm: InputMethodManager = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
onEmojiClickListener = { imm.hideSoftInputFromWindow(binding.emoji.windowToken, 0)
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.clearStatusAfterSpinner.apply { binding.clearStatusAfterSpinner.apply {
this.adapter = createClearTimesArrayAdapter() this.adapter = createClearTimesArrayAdapter()
onItemSelectedListener = object : OnItemSelectedListener { onItemSelectedListener = object : OnItemSelectedListener {
@ -247,9 +233,9 @@ class SetStatusDialogFragment :
binding.remainingClearTime.apply { binding.remainingClearTime.apply {
binding.clearStatusMessageTextView.text = getString(R.string.clear_status_message) binding.clearStatusMessageTextView.text = getString(R.string.clear_status_message)
visibility = View.VISIBLE visibility = View.VISIBLE
text = DisplayUtils.getRelativeTimestamp(context, it.clearAt * ONE_SECOND_IN_MILLIS, true) text =
.toString() DisplayUtils.getRelativeTimestamp(context, it.clearAt * ONE_SECOND_IN_MILLIS, true).toString()
.decapitalize(Locale.getDefault()) .decapitalize(Locale.getDefault())
setOnClickListener { setOnClickListener {
visibility = View.GONE visibility = View.GONE
binding.clearStatusAfterSpinner.visibility = View.VISIBLE binding.clearStatusAfterSpinner.visibility = View.VISIBLE
@ -365,15 +351,23 @@ class SetStatusDialogFragment :
return returnValue return returnValue
} }
private fun openEmojiPopup() { private fun toggleEmojiPicker() {
popup.show() 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() { private fun clearStatus() {
val credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token) val credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token)
ncApi.statusDeleteMessage(credentials, ApiUtils.getUrlForStatusMessage(currentUser?.baseUrl)) ncApi.statusDeleteMessage(credentials, ApiUtils.getUrlForStatusMessage(currentUser?.baseUrl))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<GenericOverall> { .subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
// unused atm // unused atm
} }
@ -397,10 +391,8 @@ class SetStatusDialogFragment :
ncApi.setStatusType(credentials, ApiUtils.getUrlForSetStatusType(currentUser?.baseUrl), statusType.string) ncApi.setStatusType(credentials, ApiUtils.getUrlForSetStatusType(currentUser?.baseUrl), statusType.string)
.subscribeOn( .subscribeOn(
Schedulers Schedulers.io()
.io() ).observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<GenericOverall> {
)
.observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
// unused atm // unused atm
} }
@ -464,19 +456,10 @@ class SetStatusDialogFragment :
// The endpoint '/message/custom' expects a valid emoji as string or null // The endpoint '/message/custom' expects a valid emoji as string or null
val statusIcon = binding.emoji.text.toString().ifEmpty { null } val statusIcon = binding.emoji.text.toString().ifEmpty { null }
if (selectedPredefinedStatus == null || if (selectedPredefinedStatus == null || selectedPredefinedStatus!!.message != inputText || selectedPredefinedStatus!!.icon != binding.emoji.text.toString()) {
selectedPredefinedStatus!!.message != inputText ||
selectedPredefinedStatus!!.icon != binding.emoji.text.toString()
) {
ncApi.setCustomStatusMessage( ncApi.setCustomStatusMessage(
credentials, credentials, ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl), statusIcon, inputText, clearAt
ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl), ).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
statusIcon,
inputText,
clearAt
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> { ?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
@ -504,9 +487,8 @@ class SetStatusDialogFragment :
ApiUtils.getUrlForSetPredefinedStatus(currentUser?.baseUrl), ApiUtils.getUrlForSetPredefinedStatus(currentUser?.baseUrl),
selectedPredefinedStatus!!.id, selectedPredefinedStatus!!.id,
if (clearAt == -1L) null else clearAt if (clearAt == -1L) null else clearAt
) ).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io()) ?.subscribe(object : Observer<GenericOverall> {
.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) = Unit override fun onSubscribe(d: Disposable) = Unit
override fun onNext(t: GenericOverall) { override fun onNext(t: GenericOverall) {
@ -524,6 +506,7 @@ class SetStatusDialogFragment :
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding.emoji.setOnClickListener { toggleEmojiPicker() }
return binding.root 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 * Fragment creator
*/ */

View file

@ -364,7 +364,7 @@
app:cardCornerRadius="24dp" app:cardCornerRadius="24dp"
app:cardElevation="0dp"> app:cardElevation="0dp">
<com.vanniktech.emoji.EmojiEditText <androidx.emoji2.widget.EmojiButton
android:id="@+id/emoji" android:id="@+id/emoji"
android:layout_width="@dimen/activity_row_layout_height" android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height" android:layout_height="@dimen/activity_row_layout_height"
@ -462,4 +462,11 @@
</LinearLayout> </LinearLayout>
<androidx.emoji2.emojipicker.EmojiPickerView
android:id="@+id/emoji_picker"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent"
app:emojiGridColumns="9" />
</LinearLayout> </LinearLayout>