convert rxjava to coroutines - notification calls

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-17 20:32:55 +01:00 committed by Marcel Hibbe
parent 77b55dcd9b
commit f4f943ff5a
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 38 additions and 37 deletions

View File

@ -131,6 +131,14 @@ interface NcApiCoroutines {
@Url url: String @Url url: String
): GenericOverall ): GenericOverall
@FormUrlEncoded
@POST
suspend fun notificationCalls(
@Header("Authorization") authorization: String,
@Url url: String,
@Field("level") level: Int
): GenericOverall
@POST @POST
suspend fun setReadStatusPrivacy( suspend fun setReadStatusPrivacy(
@Header("Authorization") authorization: String, @Header("Authorization") authorization: String,

View File

@ -835,7 +835,9 @@ class ConversationInfoActivity :
binding.lockConversation.setOnClickListener { binding.lockConversation.setOnClickListener {
val isLocked = binding.lockConversationSwitch.isChecked val isLocked = binding.lockConversationSwitch.isChecked
binding.lockConversationSwitch.isChecked = !isLocked binding.lockConversationSwitch.isChecked = !isLocked
lifecycleScope.launch{
databaseStorageModule!!.saveBoolean("lock_switch", !isLocked) databaseStorageModule!!.saveBoolean("lock_switch", !isLocked)
}
val state = if (isLocked) 0 else 1 val state = if (isLocked) 0 else 1
makeConversationReadOnly(conversationToken, state) makeConversationReadOnly(conversationToken, state)
} }
@ -1516,13 +1518,18 @@ class ConversationInfoActivity :
binding.notificationSettingsView.notificationSettingsImportantConversation.setOnClickListener { binding.notificationSettingsView.notificationSettingsImportantConversation.setOnClickListener {
val isChecked = binding.notificationSettingsView.importantConversationSwitch.isChecked val isChecked = binding.notificationSettingsView.importantConversationSwitch.isChecked
binding.notificationSettingsView.importantConversationSwitch.isChecked = !isChecked binding.notificationSettingsView.importantConversationSwitch.isChecked = !isChecked
lifecycleScope.launch{
module.saveBoolean("important_conversation_switch", !isChecked) module.saveBoolean("important_conversation_switch", !isChecked)
} }
}
binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener { binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener {
val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked
binding.notificationSettingsView.callNotificationsSwitch.isChecked = !isChecked binding.notificationSettingsView.callNotificationsSwitch.isChecked = !isChecked
lifecycleScope.launch{
module.saveBoolean("call_notifications_switch", !isChecked) module.saveBoolean("call_notifications_switch", !isChecked)
} }
}
binding.notificationSettingsView.conversationInfoMessageNotificationsDropdown binding.notificationSettingsView.conversationInfoMessageNotificationsDropdown
.setOnItemClickListener { _, _, position, _ -> .setOnItemClickListener { _, _, position, _ ->
val value = resources.getStringArray(R.array.message_notification_levels_entry_values)[position] val value = resources.getStringArray(R.array.message_notification_levels_entry_values)[position]

View File

@ -12,6 +12,7 @@ import android.text.TextUtils
import android.util.Log import android.util.Log
import autodagger.AutoInjector import autodagger.AutoInjector
import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.api.NcApiCoroutines
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
@ -31,10 +32,13 @@ import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import javax.inject.Inject import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class DatabaseStorageModule(conversationUser: User, conversationToken: String) { class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
@JvmField @JvmField
@Inject @Inject
var arbitraryStorageManager: ArbitraryStorageManager? = null var arbitraryStorageManager: ArbitraryStorageManager? = null
@ -43,6 +47,10 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
@Inject @Inject
var ncApi: NcApi? = null var ncApi: NcApi? = null
@JvmField
@Inject
var ncApiCoroutines: NcApiCoroutines?= null
private var messageExpiration = 0 private var messageExpiration = 0
private val conversationUser: User private val conversationUser: User
private val conversationToken: String private val conversationToken: String
@ -60,43 +68,21 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
this.conversationToken = conversationToken this.conversationToken = conversationToken
} }
fun saveBoolean(key: String, value: Boolean) { suspend fun saveBoolean(key: String, value: Boolean) {
if ("call_notifications_switch" == key) { if ("call_notifications_switch" == key) {
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4)) val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4))
ncApi!!.notificationCalls( val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl,conversationToken)
getCredentials( val credentials = getCredentials(conversationUser.username,conversationUser.token)
conversationUser.username, val notificationLevel = if(value) 1 else 0
conversationUser.token withContext(Dispatchers.IO) {
), try {
getUrlForRoomNotificationCalls( ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel)
apiVersion,
conversationUser.baseUrl,
conversationToken
),
if (value) 1 else 0
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(genericOverall: GenericOverall) {
Log.d(TAG, "Toggled notification calls") Log.d(TAG, "Toggled notification calls")
} } catch (e: Throwable) {
override fun onError(e: Throwable) {
Log.e(TAG, "Error when trying to toggle notification calls", e) Log.e(TAG, "Error when trying to toggle notification calls", e)
} }
override fun onComplete() {
// unused atm
} }
} }
)
}
if ("lobby_switch" != key) { if ("lobby_switch" != key) {
arbitraryStorageManager!!.storeStorageSetting( arbitraryStorageManager!!.storeStorageSetting(