|
@@ -35,6 +35,7 @@ import android.widget.AdapterView
|
|
import android.widget.AdapterView.OnItemSelectedListener
|
|
import android.widget.AdapterView.OnItemSelectedListener
|
|
import android.widget.ArrayAdapter
|
|
import android.widget.ArrayAdapter
|
|
import androidx.appcompat.app.AlertDialog
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
+import androidx.core.widget.doAfterTextChanged
|
|
import androidx.fragment.app.DialogFragment
|
|
import androidx.fragment.app.DialogFragment
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import autodagger.AutoInjector
|
|
import autodagger.AutoInjector
|
|
@@ -59,6 +60,7 @@ 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
|
|
import io.reactivex.schedulers.Schedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
|
|
+import kotlinx.android.synthetic.main.dialog_set_status.*
|
|
import okhttp3.ResponseBody
|
|
import okhttp3.ResponseBody
|
|
import java.util.Calendar
|
|
import java.util.Calendar
|
|
import java.util.Locale
|
|
import java.util.Locale
|
|
@@ -157,7 +159,8 @@ class SetStatusDialogFragment :
|
|
currentStatus?.let {
|
|
currentStatus?.let {
|
|
binding.emoji.setText(it.icon)
|
|
binding.emoji.setText(it.icon)
|
|
binding.customStatusInput.text?.clear()
|
|
binding.customStatusInput.text?.clear()
|
|
- binding.customStatusInput.setText(it.message)
|
|
|
|
|
|
+ binding.customStatusInput.setText(it.message?.trim())
|
|
|
|
+ binding.setStatus.isEnabled = it.message?.isEmpty() == false
|
|
visualizeStatus(it.status)
|
|
visualizeStatus(it.status)
|
|
|
|
|
|
if (it.clearAt > 0) {
|
|
if (it.clearAt > 0) {
|
|
@@ -231,6 +234,10 @@ class SetStatusDialogFragment :
|
|
binding.setStatus.setBackgroundColor(resources.getColor(R.color.colorPrimary))
|
|
binding.setStatus.setBackgroundColor(resources.getColor(R.color.colorPrimary))
|
|
|
|
|
|
binding.customStatusInput.highlightColor = resources.getColor(R.color.colorPrimary)
|
|
binding.customStatusInput.highlightColor = resources.getColor(R.color.colorPrimary)
|
|
|
|
+
|
|
|
|
+ binding.customStatusInput.doAfterTextChanged { text ->
|
|
|
|
+ binding.setStatus.isEnabled = !text.isNullOrEmpty()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Suppress("ComplexMethod")
|
|
@Suppress("ComplexMethod")
|
|
@@ -289,10 +296,10 @@ class SetStatusDialogFragment :
|
|
@Suppress("ReturnCount")
|
|
@Suppress("ReturnCount")
|
|
private fun clearAtToUnixTime(clearAt: ClearAt?): Long {
|
|
private fun clearAtToUnixTime(clearAt: ClearAt?): Long {
|
|
if (clearAt != null) {
|
|
if (clearAt != null) {
|
|
- if (clearAt.type.equals("period")) {
|
|
|
|
|
|
+ if (clearAt.type == "period") {
|
|
return System.currentTimeMillis() / ONE_SECOND_IN_MILLIS + clearAt.time.toLong()
|
|
return System.currentTimeMillis() / ONE_SECOND_IN_MILLIS + clearAt.time.toLong()
|
|
- } else if (clearAt.type.equals("end-of")) {
|
|
|
|
- if (clearAt.time.equals("day")) {
|
|
|
|
|
|
+ } else if (clearAt.type == "end-of") {
|
|
|
|
+ if (clearAt.time == "day") {
|
|
val date = Calendar.getInstance().apply {
|
|
val date = Calendar.getInstance().apply {
|
|
set(Calendar.HOUR_OF_DAY, LAST_HOUR_OF_DAY)
|
|
set(Calendar.HOUR_OF_DAY, LAST_HOUR_OF_DAY)
|
|
set(Calendar.MINUTE, LAST_MINUTE_OF_HOUR)
|
|
set(Calendar.MINUTE, LAST_MINUTE_OF_HOUR)
|
|
@@ -393,15 +400,15 @@ class SetStatusDialogFragment :
|
|
}
|
|
}
|
|
|
|
|
|
private fun setStatusMessage() {
|
|
private fun setStatusMessage() {
|
|
- var inputText = binding.customStatusInput.text.toString()
|
|
|
|
- if (inputText.isEmpty()) {
|
|
|
|
- inputText = " "
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ val inputText = binding.customStatusInput.text.toString().ifEmpty { "" }
|
|
|
|
+ // The endpoint '/message/custom' expects a valid emoji as string or null
|
|
|
|
+ val statusIcon = binding.emoji.text.toString().ifEmpty { null }
|
|
|
|
|
|
ncApi.setCustomStatusMessage(
|
|
ncApi.setCustomStatusMessage(
|
|
credentials,
|
|
credentials,
|
|
ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl),
|
|
ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl),
|
|
- binding.emoji.text.toString(),
|
|
|
|
|
|
+ statusIcon,
|
|
inputText,
|
|
inputText,
|
|
clearAt
|
|
clearAt
|
|
)
|
|
)
|
|
@@ -443,14 +450,14 @@ class SetStatusDialogFragment :
|
|
binding.clearStatusAfterSpinner.setSelection(0)
|
|
binding.clearStatusAfterSpinner.setSelection(0)
|
|
} else {
|
|
} else {
|
|
val clearAt = predefinedStatus.clearAt!!
|
|
val clearAt = predefinedStatus.clearAt!!
|
|
- if (clearAt.type.equals("period")) {
|
|
|
|
|
|
+ if (clearAt.type == "period") {
|
|
when (clearAt.time) {
|
|
when (clearAt.time) {
|
|
"1800" -> binding.clearStatusAfterSpinner.setSelection(POS_HALF_AN_HOUR)
|
|
"1800" -> binding.clearStatusAfterSpinner.setSelection(POS_HALF_AN_HOUR)
|
|
"3600" -> binding.clearStatusAfterSpinner.setSelection(POS_AN_HOUR)
|
|
"3600" -> binding.clearStatusAfterSpinner.setSelection(POS_AN_HOUR)
|
|
"14400" -> binding.clearStatusAfterSpinner.setSelection(POS_FOUR_HOURS)
|
|
"14400" -> binding.clearStatusAfterSpinner.setSelection(POS_FOUR_HOURS)
|
|
else -> binding.clearStatusAfterSpinner.setSelection(POS_DONT_CLEAR)
|
|
else -> binding.clearStatusAfterSpinner.setSelection(POS_DONT_CLEAR)
|
|
}
|
|
}
|
|
- } else if (clearAt.type.equals("end-of")) {
|
|
|
|
|
|
+ } else if (clearAt.type == "end-of") {
|
|
when (clearAt.time) {
|
|
when (clearAt.time) {
|
|
"day" -> binding.clearStatusAfterSpinner.setSelection(POS_TODAY)
|
|
"day" -> binding.clearStatusAfterSpinner.setSelection(POS_TODAY)
|
|
"week" -> binding.clearStatusAfterSpinner.setSelection(POS_END_OF_WEEK)
|
|
"week" -> binding.clearStatusAfterSpinner.setSelection(POS_END_OF_WEEK)
|