mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Use correct API endpoint for predefined status
Resolves: #1830 Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
af0065b664
commit
4f80430018
@ -60,7 +60,6 @@ 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
|
||||||
@ -88,6 +87,7 @@ private const val LAST_SECOND_OF_MINUTE = 59
|
|||||||
class SetStatusDialogFragment :
|
class SetStatusDialogFragment :
|
||||||
DialogFragment(), PredefinedStatusClickListener {
|
DialogFragment(), PredefinedStatusClickListener {
|
||||||
|
|
||||||
|
private var selectedPredefinedStatus: PredefinedStatus? = null
|
||||||
private val logTag = SetStatusDialogFragment::class.java.simpleName
|
private val logTag = SetStatusDialogFragment::class.java.simpleName
|
||||||
|
|
||||||
private lateinit var binding: DialogSetStatusBinding
|
private lateinit var binding: DialogSetStatusBinding
|
||||||
@ -133,6 +133,13 @@ class SetStatusDialogFragment :
|
|||||||
)
|
)
|
||||||
predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) }
|
predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) }
|
||||||
|
|
||||||
|
if (currentStatus?.messageIsPredefined == true &&
|
||||||
|
currentStatus?.messageId?.isNotEmpty() == true
|
||||||
|
) {
|
||||||
|
val messageId = currentStatus!!.messageId
|
||||||
|
selectedPredefinedStatus = predefinedStatusesList.first { ps -> messageId == ps.id }
|
||||||
|
}
|
||||||
|
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,24 +307,34 @@ class SetStatusDialogFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ReturnCount")
|
|
||||||
private fun clearAtToUnixTime(clearAt: ClearAt?): Long {
|
private fun clearAtToUnixTime(clearAt: ClearAt?): Long {
|
||||||
|
|
||||||
|
var returnValue = -1L
|
||||||
|
|
||||||
if (clearAt != null) {
|
if (clearAt != null) {
|
||||||
if (clearAt.type == "period") {
|
if (clearAt.type == "period") {
|
||||||
return System.currentTimeMillis() / ONE_SECOND_IN_MILLIS + clearAt.time.toLong()
|
returnValue = System.currentTimeMillis() / ONE_SECOND_IN_MILLIS + clearAt.time.toLong()
|
||||||
} else if (clearAt.type == "end-of") {
|
} else if (clearAt.type == "end-of") {
|
||||||
|
returnValue = clearAtToUnixTimeTypeEndOf(clearAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun clearAtToUnixTimeTypeEndOf(
|
||||||
|
clearAt: ClearAt
|
||||||
|
): Long {
|
||||||
|
var returnValue = -1L
|
||||||
if (clearAt.time == "day") {
|
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)
|
||||||
set(Calendar.SECOND, LAST_SECOND_OF_MINUTE)
|
set(Calendar.SECOND, LAST_SECOND_OF_MINUTE)
|
||||||
}
|
}
|
||||||
return date.timeInMillis / ONE_SECOND_IN_MILLIS
|
returnValue = date.timeInMillis / ONE_SECOND_IN_MILLIS
|
||||||
}
|
}
|
||||||
}
|
return returnValue
|
||||||
}
|
|
||||||
|
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openEmojiPopup() {
|
private fun openEmojiPopup() {
|
||||||
@ -420,6 +437,11 @@ 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 ||
|
||||||
|
selectedPredefinedStatus!!.message != inputText ||
|
||||||
|
selectedPredefinedStatus!!.icon != binding.emoji.text.toString()
|
||||||
|
) {
|
||||||
|
|
||||||
ncApi.setCustomStatusMessage(
|
ncApi.setCustomStatusMessage(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl),
|
ApiUtils.getUrlForSetCustomStatus(currentUser?.baseUrl),
|
||||||
@ -448,6 +470,30 @@ class SetStatusDialogFragment :
|
|||||||
// unused atm
|
// unused atm
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
|
||||||
|
val clearAt = clearAtToUnixTime(selectedPredefinedStatus!!.clearAt)
|
||||||
|
|
||||||
|
ncApi.setPredefinedStatusMessage(
|
||||||
|
credentials, ApiUtils.getUrlForSetPredefinedStatus(currentUser?.baseUrl),
|
||||||
|
selectedPredefinedStatus!!.id, if (clearAt == -1L) null else clearAt
|
||||||
|
)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : Observer<GenericOverall> {
|
||||||
|
override fun onSubscribe(d: Disposable) = Unit
|
||||||
|
|
||||||
|
override fun onNext(t: GenericOverall) {
|
||||||
|
Log.d(logTag, "PredefinedStatusMessage successfully set")
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(e: Throwable) {
|
||||||
|
Log.e(logTag, "failed to set PredefinedStatusMessage", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onComplete() = Unit
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
@ -455,6 +501,9 @@ class SetStatusDialogFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(predefinedStatus: PredefinedStatus) {
|
override fun onClick(predefinedStatus: PredefinedStatus) {
|
||||||
|
|
||||||
|
selectedPredefinedStatus = predefinedStatus
|
||||||
|
|
||||||
clearAt = clearAtToUnixTime(predefinedStatus.clearAt)
|
clearAt = clearAtToUnixTime(predefinedStatus.clearAt)
|
||||||
binding.emoji.setText(predefinedStatus.icon)
|
binding.emoji.setText(predefinedStatus.icon)
|
||||||
binding.customStatusInput.text?.clear()
|
binding.customStatusInput.text?.clear()
|
||||||
@ -467,7 +516,12 @@ class SetStatusDialogFragment :
|
|||||||
if (predefinedStatus.clearAt == null) {
|
if (predefinedStatus.clearAt == null) {
|
||||||
binding.clearStatusAfterSpinner.setSelection(0)
|
binding.clearStatusAfterSpinner.setSelection(0)
|
||||||
} else {
|
} else {
|
||||||
val clearAt = predefinedStatus.clearAt!!
|
setClearAt(predefinedStatus.clearAt!!)
|
||||||
|
}
|
||||||
|
setClearStatusAfterValue(binding.clearStatusAfterSpinner.selectedItemPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setClearAt(clearAt: ClearAt) {
|
||||||
if (clearAt.type == "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)
|
||||||
@ -483,8 +537,6 @@ class SetStatusDialogFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setClearStatusAfterValue(binding.clearStatusAfterSpinner.selectedItemPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment creator
|
* Fragment creator
|
||||||
|
@ -434,6 +434,10 @@ public class ApiUtils {
|
|||||||
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status/message/custom";
|
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status/message/custom";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getUrlForSetPredefinedStatus(String baseUrl) {
|
||||||
|
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/user_status/message/predefined";
|
||||||
|
}
|
||||||
|
|
||||||
public static String getUrlForUserStatuses(String baseUrl) {
|
public static String getUrlForUserStatuses(String baseUrl) {
|
||||||
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/statuses";
|
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/statuses";
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
build:
|
build:
|
||||||
maxIssues: 99
|
maxIssues: 98
|
||||||
weights:
|
weights:
|
||||||
# complexity: 2
|
# complexity: 2
|
||||||
# LongParameterList: 1
|
# LongParameterList: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user