mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-17 17:55:02 +01:00
convert rxjava to coroutines - notification calls
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
77b55dcd9b
commit
f4f943ff5a
@ -131,6 +131,14 @@ interface NcApiCoroutines {
|
||||
@Url url: String
|
||||
): GenericOverall
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
suspend fun notificationCalls(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Url url: String,
|
||||
@Field("level") level: Int
|
||||
): GenericOverall
|
||||
|
||||
@POST
|
||||
suspend fun setReadStatusPrivacy(
|
||||
@Header("Authorization") authorization: String,
|
||||
|
@ -835,7 +835,9 @@ class ConversationInfoActivity :
|
||||
binding.lockConversation.setOnClickListener {
|
||||
val isLocked = binding.lockConversationSwitch.isChecked
|
||||
binding.lockConversationSwitch.isChecked = !isLocked
|
||||
databaseStorageModule!!.saveBoolean("lock_switch", !isLocked)
|
||||
lifecycleScope.launch{
|
||||
databaseStorageModule!!.saveBoolean("lock_switch", !isLocked)
|
||||
}
|
||||
val state = if (isLocked) 0 else 1
|
||||
makeConversationReadOnly(conversationToken, state)
|
||||
}
|
||||
@ -1516,12 +1518,17 @@ class ConversationInfoActivity :
|
||||
binding.notificationSettingsView.notificationSettingsImportantConversation.setOnClickListener {
|
||||
val isChecked = binding.notificationSettingsView.importantConversationSwitch.isChecked
|
||||
binding.notificationSettingsView.importantConversationSwitch.isChecked = !isChecked
|
||||
module.saveBoolean("important_conversation_switch", !isChecked)
|
||||
lifecycleScope.launch{
|
||||
module.saveBoolean("important_conversation_switch", !isChecked)
|
||||
}
|
||||
|
||||
}
|
||||
binding.notificationSettingsView.notificationSettingsCallNotifications.setOnClickListener {
|
||||
val isChecked = binding.notificationSettingsView.callNotificationsSwitch.isChecked
|
||||
binding.notificationSettingsView.callNotificationsSwitch.isChecked = !isChecked
|
||||
module.saveBoolean("call_notifications_switch", !isChecked)
|
||||
lifecycleScope.launch{
|
||||
module.saveBoolean("call_notifications_switch", !isChecked)
|
||||
}
|
||||
}
|
||||
binding.notificationSettingsView.conversationInfoMessageNotificationsDropdown
|
||||
.setOnItemClickListener { _, _, position, _ ->
|
||||
|
@ -12,6 +12,7 @@ import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import autodagger.AutoInjector
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.api.NcApiCoroutines
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
|
||||
@ -31,10 +32,13 @@ 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.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
|
||||
@JvmField
|
||||
@Inject
|
||||
var arbitraryStorageManager: ArbitraryStorageManager? = null
|
||||
@ -43,6 +47,10 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
@Inject
|
||||
var ncApi: NcApi? = null
|
||||
|
||||
@JvmField
|
||||
@Inject
|
||||
var ncApiCoroutines: NcApiCoroutines?= null
|
||||
|
||||
private var messageExpiration = 0
|
||||
private val conversationUser: User
|
||||
private val conversationToken: String
|
||||
@ -60,42 +68,20 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
||||
this.conversationToken = conversationToken
|
||||
}
|
||||
|
||||
fun saveBoolean(key: String, value: Boolean) {
|
||||
suspend fun saveBoolean(key: String, value: Boolean) {
|
||||
if ("call_notifications_switch" == key) {
|
||||
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4))
|
||||
ncApi!!.notificationCalls(
|
||||
getCredentials(
|
||||
conversationUser.username,
|
||||
conversationUser.token
|
||||
),
|
||||
getUrlForRoomNotificationCalls(
|
||||
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")
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error when trying to toggle notification calls", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
}
|
||||
)
|
||||
val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl,conversationToken)
|
||||
val credentials = getCredentials(conversationUser.username,conversationUser.token)
|
||||
val notificationLevel = if(value) 1 else 0
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel)
|
||||
Log.d(TAG, "Toggled notification calls")
|
||||
} catch (e: Throwable) {
|
||||
Log.e(TAG, "Error when trying to toggle notification calls", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("lobby_switch" != key) {
|
||||
|
Loading…
Reference in New Issue
Block a user