add backup message in the predefined status list
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
Родитель
27aafda59f
Коммит
d08b4f51b8
|
@ -24,7 +24,7 @@ class PredefinedStatusViewHolder(private val binding: PredefinedStatusBinding) :
|
|||
binding.icon.text = status.icon
|
||||
binding.name.text = status.message
|
||||
|
||||
binding.resetStatusButton.visibility = if(position == 0) View.VISIBLE else View.GONE
|
||||
binding.resetStatusButton.visibility = if (position == 0) View.VISIBLE else View.GONE
|
||||
|
||||
if (status.clearAt == null) {
|
||||
binding.clearAt.text = context.getString(R.string.dontClear)
|
||||
|
|
|
@ -25,5 +25,5 @@ data class UserStatusCapability(
|
|||
var supportsEmoji: Boolean
|
||||
) : Parcelable {
|
||||
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
|
||||
constructor() : this(false, false,false)
|
||||
constructor() : this(false, false, false)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ data class PredefinedStatus(
|
|||
@JsonField(name = ["id"])
|
||||
var id: String,
|
||||
@JsonField(name = ["icon"])
|
||||
var icon: String,
|
||||
var icon: String?,
|
||||
@JsonField(name = ["message"])
|
||||
var message: String,
|
||||
@JsonField(name = ["clearAt"])
|
||||
|
|
|
@ -115,73 +115,72 @@ class SetStatusDialogFragment :
|
|||
currentStatus = it.getParcelable(ARG_CURRENT_STATUS_PARAM)
|
||||
|
||||
credentials = ApiUtils.getCredentials(currentUser?.username, currentUser?.token)!!
|
||||
ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl!!))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<ResponseBody> {
|
||||
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(responseBody: ResponseBody) {
|
||||
val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse(
|
||||
responseBody
|
||||
.string(),
|
||||
PredefinedStatusOverall::class.java
|
||||
)
|
||||
predefinedStatusOverall.ocs?.data?.let { it1 -> predefinedStatusesList.addAll(it1) }
|
||||
|
||||
if (currentStatus?.messageIsPredefined == true &&
|
||||
currentStatus?.messageId?.isNotEmpty() == true
|
||||
) {
|
||||
val messageId = currentStatus!!.messageId
|
||||
selectedPredefinedStatus = predefinedStatusesList.firstOrNull { ps -> messageId == ps.id }
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error while fetching predefined statuses", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
checkBackupStatus()
|
||||
fetchPredefinedStatuses()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun backupStatus(){
|
||||
ncApi.backupStatus(credentials, ApiUtils.getUrlForBackupStatus(currentUser?.baseUrl!!,currentUser?.userId!!))
|
||||
private fun fetchPredefinedStatuses() {
|
||||
ncApi.getPredefinedStatuses(credentials, ApiUtils.getUrlForPredefinedStatuses(currentUser?.baseUrl!!))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<ResponseBody> {
|
||||
override fun onSubscribe(d: Disposable) {}
|
||||
|
||||
override fun onNext(responseBody: ResponseBody) {
|
||||
val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse(
|
||||
responseBody.string(),
|
||||
PredefinedStatusOverall::class.java
|
||||
)
|
||||
predefinedStatusOverall.ocs?.data?.let { predefinedStatusesList.addAll(it) }
|
||||
|
||||
if (currentStatus?.messageIsPredefined == true && currentStatus?.messageId?.isNotEmpty() == true) {
|
||||
val messageId = currentStatus!!.messageId
|
||||
selectedPredefinedStatus = predefinedStatusesList.firstOrNull { ps -> messageId == ps.id }
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error while fetching predefined statuses", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {}
|
||||
})
|
||||
}
|
||||
|
||||
private fun checkBackupStatus() {
|
||||
ncApi.backupStatus(credentials, ApiUtils.getUrlForBackupStatus(currentUser?.baseUrl!!, currentUser?.userId!!))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<StatusOverall> {
|
||||
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
|
||||
}
|
||||
|
||||
override fun onNext(statusOverall:StatusOverall) {
|
||||
val status = statusOverall
|
||||
Log.d("TAG","$status")
|
||||
override fun onNext(statusOverall: StatusOverall) {
|
||||
if (statusOverall.ocs?.meta?.statusCode == 200) {
|
||||
val status = statusOverall.ocs?.data
|
||||
if (status?.messageIsPredefined == false) {
|
||||
val backupPredefinedStatus = PredefinedStatus(
|
||||
status?.userId!!,
|
||||
status.icon,
|
||||
status.message!!,
|
||||
ClearAt(type = "period", time = status.clearAt.toString())
|
||||
)
|
||||
predefinedStatusesList.add(0, backupPredefinedStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error while fetching predefined statuses", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
|
@ -434,10 +433,6 @@ class SetStatusDialogFragment :
|
|||
})
|
||||
}
|
||||
|
||||
private fun getBackupStatus(){
|
||||
|
||||
}
|
||||
|
||||
private fun visualizeStatus(statusType: String) {
|
||||
StatusType.values().firstOrNull { it.name == statusType.uppercase(Locale.ROOT) }?.let { visualizeStatus(it) }
|
||||
}
|
||||
|
|
|
@ -483,8 +483,8 @@ object ApiUtils {
|
|||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getUrlForBackupStatus(baseUrl:String, userId:String):String{
|
||||
return "$baseUrl$OCS_API_VERSION/apps/user_status/api/v1/user_status/_$userId"
|
||||
fun getUrlForBackupStatus(baseUrl: String, userId: String): String {
|
||||
return "$baseUrl$OCS_API_VERSION/apps/user_status/api/v1/statuses/_$userId"
|
||||
}
|
||||
|
||||
fun getUrlForSetStatusType(baseUrl: String): String {
|
||||
|
|
Загрузка…
Ссылка в новой задаче