mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-12-18 14:42:16 +03:00
Replaced EmojiPicker in SetStatusDialogFragment
Signed-off-by: Smarshal21 <lcb2021048@iiitl.ac.in>
This commit is contained in:
parent
2f24c130ca
commit
ee601bb590
3 changed files with 53 additions and 55 deletions
|
@ -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}"
|
||||
|
|
|
@ -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<ResponseBody> {
|
||||
|
||||
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<GenericOverall> {
|
||||
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
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<GenericOverall> {
|
||||
Schedulers.io()
|
||||
).observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<GenericOverall> {
|
||||
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<GenericOverall> {
|
||||
|
||||
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<GenericOverall> {
|
||||
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<GenericOverall> {
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -364,7 +364,7 @@
|
|||
app:cardCornerRadius="24dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
<com.vanniktech.emoji.EmojiEditText
|
||||
<androidx.emoji2.widget.EmojiButton
|
||||
android:id="@+id/emoji"
|
||||
android:layout_width="@dimen/activity_row_layout_height"
|
||||
android:layout_height="@dimen/activity_row_layout_height"
|
||||
|
@ -462,4 +462,11 @@
|
|||
|
||||
</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>
|
||||
|
|
Loading…
Reference in a new issue