mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 22:29:09 +00:00
uses NcApiCoroutines now
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
parent
46efdf4b0c
commit
d464d714ff
@ -110,4 +110,16 @@ interface NcApiCoroutines {
|
||||
|
||||
@DELETE
|
||||
suspend fun deleteConversationAvatar(@Header("Authorization") authorization: String, @Url url: String): RoomOverall
|
||||
|
||||
@POST
|
||||
suspend fun archiveConversation(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String?
|
||||
): GenericOverall
|
||||
|
||||
@DELETE
|
||||
suspend fun unarchiveConversation(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String?
|
||||
): GenericOverall
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import android.view.View.VISIBLE
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.work.Data
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
@ -85,6 +86,7 @@ import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.util.Calendar
|
||||
@ -746,16 +748,18 @@ class ConversationInfoActivity :
|
||||
}
|
||||
|
||||
binding.archiveConversationBtn.setOnClickListener {
|
||||
if (conversation!!.hasArchived) {
|
||||
viewModel.unarchiveConversation(conversationUser, conversationToken)
|
||||
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.outline_archive_24))
|
||||
binding.archiveConversationText.text = resources.getString(R.string.archive_conversation)
|
||||
binding.archiveConversationTextHint.text = resources.getString(R.string.archive_hint)
|
||||
} else {
|
||||
viewModel.archiveConversation(conversationUser, conversationToken)
|
||||
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.ic_eye))
|
||||
binding.archiveConversationText.text = resources.getString(R.string.unarchive_conversation)
|
||||
binding.archiveConversationTextHint.text = resources.getString(R.string.unarchive_hint)
|
||||
this.lifecycleScope.launch {
|
||||
if (conversation!!.hasArchived) {
|
||||
viewModel.unarchiveConversation(conversationUser, conversationToken)
|
||||
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.outline_archive_24))
|
||||
binding.archiveConversationText.text = resources.getString(R.string.archive_conversation)
|
||||
binding.archiveConversationTextHint.text = resources.getString(R.string.archive_hint)
|
||||
} else {
|
||||
viewModel.archiveConversation(conversationUser, conversationToken)
|
||||
binding.archiveConversationIcon.setImageDrawable(resources.getDrawable(R.drawable.ic_eye))
|
||||
binding.archiveConversationText.text = resources.getString(R.string.unarchive_conversation)
|
||||
binding.archiveConversationTextHint.text = resources.getString(R.string.unarchive_hint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,54 +202,16 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
fun archiveConversation(user: User, token: String) {
|
||||
suspend fun archiveConversation(user: User, token: String) {
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
||||
val url = ApiUtils.getUrlForArchive(apiVersion, user.baseUrl, token)
|
||||
conversationsRepository.archiveConversation(user.getCredentials(), url)
|
||||
.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(p0: Disposable) {
|
||||
// unused
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.d(TAG, "Error in archive $e")
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(n: GenericOverall) {
|
||||
Log.d(TAG, "Archived successful")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun unarchiveConversation(user: User, token: String) {
|
||||
suspend fun unarchiveConversation(user: User, token: String) {
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
|
||||
val url = ApiUtils.getUrlForArchive(apiVersion, user.baseUrl, token)
|
||||
conversationsRepository.unarchiveConversation(user.getCredentials(), url)
|
||||
.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(p0: Disposable) {
|
||||
// unused
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.d(TAG, "Error in unarchive $e")
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(n: GenericOverall) {
|
||||
Log.d(TAG, "unArchived successful")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
inner class GetRoomObserver : Observer<ConversationModel> {
|
||||
|
@ -70,8 +70,11 @@ import okhttp3.OkHttpClient
|
||||
class RepositoryModule {
|
||||
|
||||
@Provides
|
||||
fun provideConversationsRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew): ConversationsRepository {
|
||||
return ConversationsRepositoryImpl(ncApi, userProvider)
|
||||
fun provideConversationsRepository(
|
||||
ncApi: NcApi, ncApiCoroutines: NcApiCoroutines, userProvider:
|
||||
CurrentUserProviderNew
|
||||
): ConversationsRepository {
|
||||
return ConversationsRepositoryImpl(ncApi, ncApiCoroutines, userProvider)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -31,7 +31,7 @@ interface ConversationsRepository {
|
||||
)
|
||||
fun resendInvitations(token: String): Observable<ResendInvitationsResult>
|
||||
|
||||
fun archiveConversation(credentials: String, url: String): Observable<GenericOverall>
|
||||
suspend fun archiveConversation(credentials: String, url: String): GenericOverall
|
||||
|
||||
fun unarchiveConversation(credentials: String, url: String): Observable<GenericOverall>
|
||||
suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ package com.nextcloud.talk.repositories.conversations
|
||||
|
||||
import com.bluelinelabs.logansquare.LoganSquare
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.api.NcApiCoroutines
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.json.conversations.password.PasswordOverall
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
@ -21,6 +22,7 @@ import io.reactivex.Observable
|
||||
|
||||
class ConversationsRepositoryImpl(
|
||||
private val api: NcApi,
|
||||
private val coroutineApi: NcApiCoroutines,
|
||||
private val userProvider: CurrentUserProviderNew
|
||||
) :
|
||||
ConversationsRepository {
|
||||
@ -90,12 +92,12 @@ class ConversationsRepositoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override fun archiveConversation(credentials: String, url: String): Observable<GenericOverall> {
|
||||
return api.archiveConversation(credentials, url)
|
||||
override suspend fun archiveConversation(credentials: String, url: String): GenericOverall {
|
||||
return coroutineApi.archiveConversation(credentials, url)
|
||||
}
|
||||
|
||||
override fun unarchiveConversation(credentials: String, url: String): Observable<GenericOverall> {
|
||||
return api.unarchiveConversation(credentials, url)
|
||||
override suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall {
|
||||
return coroutineApi.unarchiveConversation(credentials, url)
|
||||
}
|
||||
|
||||
private fun apiVersion(): Int {
|
||||
|
Loading…
Reference in New Issue
Block a user