mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 05:25:31 +03:00
convert rxjava to coroutines - setConversationDescription
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
1beffd9e22
commit
6cce2783b9
4 changed files with 65 additions and 42 deletions
|
@ -36,15 +36,10 @@ import com.nextcloud.talk.extensions.loadUserAvatar
|
|||
import com.nextcloud.talk.models.domain.ConversationModel
|
||||
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationEnums
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil
|
||||
import com.nextcloud.talk.utils.PickImage
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -195,6 +190,27 @@ class ConversationInfoEditActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
conversationInfoEditViewModel.setConversationDescriptionUiState.observe(this){ uiState ->
|
||||
when(uiState){
|
||||
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.None ->{
|
||||
|
||||
}
|
||||
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Success ->{
|
||||
finish()
|
||||
}
|
||||
is ConversationInfoEditViewModel.SetConversationDescriptionUiState.Error ->{
|
||||
Snackbar.make(
|
||||
binding.root,
|
||||
context.getString(R.string.default_error_msg),
|
||||
Snackbar.LENGTH_LONG
|
||||
).show()
|
||||
Log.e(TAG, "Error while saving conversation description", uiState.exception)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun setupAvatarOptions() {
|
||||
|
@ -267,43 +283,8 @@ class ConversationInfoEditActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
fun saveConversationDescription() {
|
||||
val apiVersion =
|
||||
ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
||||
|
||||
ncApi.setConversationDescription(
|
||||
credentials,
|
||||
ApiUtils.getUrlForConversationDescription(
|
||||
apiVersion,
|
||||
conversationUser.baseUrl!!,
|
||||
conversation!!.token
|
||||
),
|
||||
binding.conversationDescription.text.toString()
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.retry(1)
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(genericOverall: GenericOverall) {
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Snackbar.make(
|
||||
binding.root,
|
||||
context.getString(R.string.default_error_msg),
|
||||
Snackbar.LENGTH_LONG
|
||||
).show()
|
||||
Log.e(TAG, "Error while saving conversation description", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
val conversationDescription = binding.conversationDescription.text.toString()
|
||||
conversationInfoEditViewModel.setConversationDescription(conversation!!.token, conversationDescription)
|
||||
}
|
||||
|
||||
private fun handleResult(result: ActivityResult, onResult: (result: ActivityResult) -> Unit) {
|
||||
|
|
|
@ -19,4 +19,6 @@ interface ConversationInfoEditRepository {
|
|||
fun deleteConversationAvatar(user: User, roomToken: String): Observable<ConversationModel>
|
||||
|
||||
suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall
|
||||
|
||||
suspend fun setConversationDescription(roomToken:String, conversationDescription:String?): GenericOverall
|
||||
}
|
||||
|
|
|
@ -71,4 +71,19 @@ class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi,
|
|||
newRoomName
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setConversationDescription(
|
||||
roomToken: String,
|
||||
conversationDescription: String?
|
||||
): GenericOverall {
|
||||
return ncApiCoroutines.setConversationDescription(
|
||||
credentials,
|
||||
ApiUtils.getUrlForConversationDescription(
|
||||
apiVersion,
|
||||
currentUser.baseUrl!!,
|
||||
roomToken
|
||||
),
|
||||
conversationDescription
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ class ConversationInfoEditViewModel @Inject constructor(
|
|||
val renameRoomUiState:LiveData<RenameRoomUiState>
|
||||
get() = _renameRoomUiState
|
||||
|
||||
private val _setConversationDescriptionUiState = MutableLiveData<SetConversationDescriptionUiState>(SetConversationDescriptionUiState.None)
|
||||
val setConversationDescriptionUiState:LiveData<SetConversationDescriptionUiState>
|
||||
get() = _setConversationDescriptionUiState
|
||||
|
||||
fun getRoom(user: User, token: String) {
|
||||
_viewState.value = GetRoomStartState
|
||||
repository.getRoom(user, token)
|
||||
|
@ -87,6 +91,21 @@ class ConversationInfoEditViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun setConversationDescription(roomToken:String, conversationDescription:String?){
|
||||
viewModelScope.launch{
|
||||
try{
|
||||
val setConversationDescriptionResult = conversationInfoEditRepository.setConversationDescription(roomToken, conversationDescription)
|
||||
val statusCode: GenericMeta? = setConversationDescriptionResult.ocs?.meta
|
||||
val result = statusCode?.statusCode == STATUS_CODE_OK
|
||||
if(result){
|
||||
_setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Success(result)
|
||||
}
|
||||
}catch(exception:Exception){
|
||||
_setConversationDescriptionUiState.value = SetConversationDescriptionUiState.Error(exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class GetRoomObserver : Observer<ConversationModel> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
|
@ -153,4 +172,10 @@ class ConversationInfoEditViewModel @Inject constructor(
|
|||
data class Success(val result:Boolean): RenameRoomUiState()
|
||||
data class Error(val exception:Exception): RenameRoomUiState()
|
||||
}
|
||||
|
||||
sealed class SetConversationDescriptionUiState{
|
||||
data object None: SetConversationDescriptionUiState()
|
||||
data class Success(val result:Boolean):SetConversationDescriptionUiState()
|
||||
data class Error(val exception:Exception):SetConversationDescriptionUiState()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue