mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 20:45:29 +03:00
convert rxjava to coroutine - favourite conversation
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
eb9eb99ca3
commit
262f5b1cf4
2 changed files with 30 additions and 31 deletions
|
@ -116,4 +116,10 @@ interface NcApiCoroutines {
|
|||
|
||||
@DELETE
|
||||
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
||||
|
||||
@POST
|
||||
suspend fun addConversationToFavorites(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Url url: String
|
||||
): GenericOverall
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.os.Bundle
|
|||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.work.Data
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkInfo
|
||||
|
@ -21,6 +22,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
|||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.activities.MainActivity
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.api.NcApiCoroutines
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.conversation.RenameConversationDialogFragment
|
||||
import com.nextcloud.talk.conversationlist.ConversationsListActivity
|
||||
|
@ -42,6 +44,9 @@ import io.reactivex.Observer
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
|
@ -56,6 +61,9 @@ class ConversationsListBottomDialog(
|
|||
@Inject
|
||||
lateinit var ncApi: NcApi
|
||||
|
||||
@Inject
|
||||
lateinit var ncApiCoroutines: NcApiCoroutines
|
||||
|
||||
@Inject
|
||||
lateinit var viewThemeUtils: ViewThemeUtils
|
||||
|
||||
|
@ -195,42 +203,27 @@ class ConversationsListBottomDialog(
|
|||
|
||||
private fun addConversationToFavorites() {
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
||||
ncApi.addConversationToFavorites(
|
||||
credentials,
|
||||
ApiUtils.getUrlForRoomFavorite(
|
||||
apiVersion,
|
||||
currentUser.baseUrl!!,
|
||||
conversation.token
|
||||
)
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.retry(1)
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl!!, conversation.token)
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
withContext(Dispatchers.IO) {
|
||||
ncApiCoroutines.addConversationToFavorites(credentials, url)
|
||||
}
|
||||
|
||||
override fun onNext(genericOverall: GenericOverall) {
|
||||
activity.fetchRooms()
|
||||
activity.showSnackbar(
|
||||
String.format(
|
||||
context.resources.getString(R.string.added_to_favorites),
|
||||
conversation.displayName
|
||||
)
|
||||
activity.fetchRooms()
|
||||
activity.showSnackbar(
|
||||
String.format(
|
||||
context.resources.getString(R.string.added_to_favorites),
|
||||
conversation.displayName
|
||||
)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
)
|
||||
dismiss()
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
activity.showSnackbar(context.resources.getString(R.string.nc_common_error_sorry))
|
||||
dismiss()
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeConversationFromFavorites() {
|
||||
|
|
Loading…
Reference in a new issue