Skip to content

Commit

Permalink
Merge pull request #4455 from nextcloud/coroutine_3
Browse files Browse the repository at this point in the history
Migrate Rxjava to Coroutines
  • Loading branch information
sowjanyakch authored Nov 19, 2024
2 parents 8e20f5b + 0db401d commit 8228f77
Showing 16 changed files with 237 additions and 292 deletions.
29 changes: 0 additions & 29 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
@@ -118,26 +118,6 @@ Observable<RoomOverall> createRoom(@Header("Authorization") String authorization
@Url String url,
@QueryMap Map<String, String> options);

/*
QueryMap items are as follows:
- "roomName" : "newName"
Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken
*/

@FormUrlEncoded
@PUT
Observable<GenericOverall> renameRoom(@Header("Authorization") String authorization,
@Url String url,
@Field("roomName") String roomName);


@FormUrlEncoded
@PUT
Observable<GenericOverall> setConversationDescription(@Header("Authorization") String authorization,
@Url String url,
@Field("description") String description);

/*
QueryMap items are as follows:
- "newParticipant" : "user"
@@ -413,12 +393,6 @@ Observable<GenericOverall> setNotificationLevel(@Header("Authorization") String
@Url String url,
@Field("level") int level);

@FormUrlEncoded
@PUT
Observable<GenericOverall> setConversationReadOnly(@Header("Authorization") String authorization,
@Url String url,
@Field("state") int state);

@FormUrlEncoded
@POST
Observable<GenericOverall> createRemoteShare(@Nullable @Header("Authorization") String authorization,
@@ -492,9 +466,6 @@ Observable<GenericOverall> sendLocation(@Header("Authorization") String authoriz
@Field("objectId") String objectId,
@Field("metaData") String metaData);

@DELETE
Observable<GenericOverall> clearChatHistory(@Header("Authorization") String authorization, @Url String url);

@FormUrlEncoded
@POST
Observable<GenericOverall> notificationCalls(@Header("Authorization") String authorization,
7 changes: 5 additions & 2 deletions app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt
Original file line number Diff line number Diff line change
@@ -133,11 +133,14 @@ interface NcApiCoroutines {
@Body body: RequestBody
): GenericOverall

@DELETE
suspend fun clearChatHistory(@Header("Authorization") authorization: String, @Url url: String): GenericOverall

@FormUrlEncoded
@PUT
suspend fun setPassword2(
suspend fun setConversationReadOnly(
@Header("Authorization") authorization: String,
@Url url: String,
@Field("password") password: String
@Field("state") state: Int
): GenericOverall
}
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ import com.google.android.material.snackbar.Snackbar
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.conversation.viewmodel.RenameConversationViewModel
import com.nextcloud.talk.conversationinfoedit.viewmodel.ConversationInfoEditViewModel
import com.nextcloud.talk.conversationlist.ConversationsListActivity
import com.nextcloud.talk.databinding.DialogRenameConversationBinding
import com.nextcloud.talk.events.ConversationsListFetchDataEvent
@@ -49,7 +49,7 @@ class RenameConversationDialogFragment : DialogFragment() {
lateinit var eventBus: EventBus

private lateinit var binding: DialogRenameConversationBinding
private lateinit var viewModel: RenameConversationViewModel
private lateinit var viewModel: ConversationInfoEditViewModel

private var emojiPopup: EmojiPopup? = null

@@ -61,7 +61,7 @@ class RenameConversationDialogFragment : DialogFragment() {

NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)

viewModel = ViewModelProvider(this, viewModelFactory)[RenameConversationViewModel::class.java]
viewModel = ViewModelProvider(this, viewModelFactory)[ConversationInfoEditViewModel::class.java]
roomToken = arguments?.getString(KEY_ROOM_TOKEN)!!
initialName = arguments?.getString(INITIAL_NAME)!!
}
@@ -102,7 +102,7 @@ class RenameConversationDialogFragment : DialogFragment() {
val positiveButton = (dialog as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE)
positiveButton.isEnabled = false
positiveButton.setOnClickListener {
viewModel.renameConversation(roomToken, binding.textEdit.text.toString())
viewModel.renameRoom(roomToken, binding.textEdit.text.toString())
}

themeDialog()
@@ -169,17 +169,21 @@ class RenameConversationDialogFragment : DialogFragment() {
}

private fun setupStateObserver() {
viewModel.viewState.observe(viewLifecycleOwner) { state ->
viewModel.renameRoomUiState.observe(viewLifecycleOwner) { state ->
when (state) {
is RenameConversationViewModel.InitialState -> {}
is RenameConversationViewModel.RenamingState -> {}
is RenameConversationViewModel.RenamingSuccessState -> handleSuccess()
is RenameConversationViewModel.RenamingFailedState -> showError()
else -> {}
is ConversationInfoEditViewModel.RenameRoomUiState.None -> {
}
is ConversationInfoEditViewModel.RenameRoomUiState.Success -> {
handleSuccess()
}
is ConversationInfoEditViewModel.RenameRoomUiState.Error -> {
showError()
}
}
}
}

@SuppressLint("StringFormatInvalid")
private fun handleSuccess() {
eventBus.post(ConversationsListFetchDataEvent())

Original file line number Diff line number Diff line change
@@ -8,13 +8,10 @@ package com.nextcloud.talk.conversation.repository

import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import io.reactivex.Observable

interface ConversationRepository {

fun renameConversation(roomToken: String, roomNameNew: String): Observable<GenericOverall>

fun createConversation(
roomName: String,
conversationType: ConversationEnums.ConversationType?
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.RetrofitBucket
import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
import io.reactivex.Observable
@@ -24,23 +23,6 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider:
val currentUser: User = currentUserProvider.currentUser.blockingGet()
val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)!!

override fun renameConversation(roomToken: String, roomNameNew: String): Observable<GenericOverall> {
val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))

return ncApi.renameRoom(
credentials,
ApiUtils.getUrlForRoom(
apiVersion,
currentUser.baseUrl!!,
roomToken
),
roomNameNew
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(API_RETRIES)
}

override fun createConversation(
roomName: String,
conversationType: ConversationEnums.ConversationType?
@@ -76,6 +58,5 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider:
companion object {
private const val ROOM_TYPE_PUBLIC = "3"
private const val ROOM_TYPE_GROUP = "2"
const val API_RETRIES: Long = 3
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -260,12 +260,30 @@ class ConversationInfoActivity :

viewModel.getConversationReadOnlyState.observe(this) { state ->
when (state) {
is ConversationInfoViewModel.SetConversationReadOnlySuccessState -> {
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Success -> {
}
is ConversationInfoViewModel.SetConversationReadOnlyErrorState -> {
is ConversationInfoViewModel.SetConversationReadOnlyViewState.Error -> {
Snackbar.make(binding.root, R.string.conversation_read_only_failed, Snackbar.LENGTH_LONG).show()
}
else -> {
is ConversationInfoViewModel.SetConversationReadOnlyViewState.None -> {
}
}
}

viewModel.clearChatHistoryViewState.observe(this) { uiState ->
when (uiState) {
is ConversationInfoViewModel.ClearChatHistoryViewState.None -> {
}
is ConversationInfoViewModel.ClearChatHistoryViewState.Success -> {
Snackbar.make(
binding.root,
context.getString(R.string.nc_clear_history_success),
Snackbar.LENGTH_LONG
).show()
}
is ConversationInfoViewModel.ClearChatHistoryViewState.Error -> {
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
Log.e(TAG, "failed to clear chat history", uiState.exception)
}
}
}
@@ -670,7 +688,6 @@ class ConversationInfoActivity :
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
}

WorkInfo.State.FAILED -> {
val errorType = workInfo.outputData.getString("error_type")
if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) {
@@ -687,7 +704,6 @@ class ConversationInfoActivity :
).show()
}
}

else -> {
}
}
@@ -726,35 +742,7 @@ class ConversationInfoActivity :

private fun clearHistory() {
val apiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(1))

ncApi.clearChatHistory(
credentials,
ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl!!, conversationToken)
)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}

override fun onNext(genericOverall: GenericOverall) {
Snackbar.make(
binding.root,
context.getString(R.string.nc_clear_history_success),
Snackbar.LENGTH_LONG
).show()
}

override fun onError(e: Throwable) {
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
Log.e(TAG, "failed to clear chat history", e)
}

override fun onComplete() {
// unused atm
}
})
viewModel.clearChatHistory(apiVersion, conversationToken)
}

private fun deleteConversation() {
@@ -849,7 +837,7 @@ class ConversationInfoActivity :
binding.lockConversationSwitch.isChecked = !isLocked
databaseStorageModule!!.saveBoolean("lock_switch", !isLocked)
val state = if (isLocked) 0 else 1
makeConversationReadOnly(conversationUser, conversationToken, state)
makeConversationReadOnly(conversationToken, state)
}
} else {
binding.lockConversation.visibility = GONE
@@ -929,8 +917,8 @@ class ConversationInfoActivity :
}
}

private fun makeConversationReadOnly(conversationUser: User, roomToken: String, state: Int) {
viewModel.setConversationReadOnly(conversationUser, roomToken, state)
private fun makeConversationReadOnly(roomToken: String, state: Int) {
viewModel.setConversationReadOnly(roomToken, state)
}

private fun initRecordingConsentOption() {
Loading

0 comments on commit 8228f77

Please sign in to comment.