mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-23 21:50:31 +01:00
convert rxjava to coroutines - set expiration and set notification levels for messages
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
1d9f475768
commit
5094cf5719
@ -163,4 +163,20 @@ interface NcApiCoroutines {
|
|||||||
@Url url: String,
|
@Url url: String,
|
||||||
@Field("state") state: Int
|
@Field("state") state: Int
|
||||||
): GenericOverall
|
): GenericOverall
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST
|
||||||
|
suspend fun setNotificationLevel(
|
||||||
|
@Header("Authorization") authorization: String,
|
||||||
|
@Url url: String,
|
||||||
|
@Field("level") level: Int
|
||||||
|
): GenericOverall
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST
|
||||||
|
suspend fun setMessageExpiration(
|
||||||
|
@Header("Authorization") authorization: String,
|
||||||
|
@Url url: String,
|
||||||
|
@Field("seconds") seconds: Int
|
||||||
|
): GenericOverall
|
||||||
}
|
}
|
||||||
|
@ -835,7 +835,7 @@ 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{
|
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
|
||||||
@ -1016,7 +1016,9 @@ class ConversationInfoActivity :
|
|||||||
.setSimpleItems(resources.getStringArray(R.array.message_expiring_descriptions))
|
.setSimpleItems(resources.getStringArray(R.array.message_expiring_descriptions))
|
||||||
binding.conversationSettingsDropdown.setOnItemClickListener { _, _, position, _ ->
|
binding.conversationSettingsDropdown.setOnItemClickListener { _, _, position, _ ->
|
||||||
val v: String = resources.getStringArray(R.array.message_expiring_values)[position]
|
val v: String = resources.getStringArray(R.array.message_expiring_values)[position]
|
||||||
databaseStorageModule!!.saveString("conversation_settings_dropdown", v)
|
lifecycleScope.launch {
|
||||||
|
databaseStorageModule!!.saveString("conversation_settings_dropdown", v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
binding.messageExpirationSettings.visibility = VISIBLE
|
binding.messageExpirationSettings.visibility = VISIBLE
|
||||||
} else {
|
} else {
|
||||||
@ -1518,15 +1520,14 @@ 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{
|
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{
|
lifecycleScope.launch {
|
||||||
module.saveBoolean("call_notifications_switch", !isChecked)
|
module.saveBoolean("call_notifications_switch", !isChecked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1534,7 +1535,9 @@ class ConversationInfoActivity :
|
|||||||
.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]
|
||||||
Log.i(TAG, "saved $value to module from $position")
|
Log.i(TAG, "saved $value to module from $position")
|
||||||
module.saveString("conversation_info_message_notifications_dropdown", value)
|
lifecycleScope.launch {
|
||||||
|
module.saveString("conversation_info_message_notifications_dropdown", value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.notificationSettingsView.importantConversationSwitch.isChecked = module
|
binding.notificationSettingsView.importantConversationSwitch.isChecked = module
|
||||||
|
@ -18,7 +18,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA
|
|||||||
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
|
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
|
||||||
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
|
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import com.nextcloud.talk.utils.ApiUtils.getConversationApiVersion
|
import com.nextcloud.talk.utils.ApiUtils.getConversationApiVersion
|
||||||
import com.nextcloud.talk.utils.ApiUtils.getCredentials
|
import com.nextcloud.talk.utils.ApiUtils.getCredentials
|
||||||
@ -28,10 +27,6 @@ import com.nextcloud.talk.utils.ApiUtils.getUrlForRoomNotificationLevel
|
|||||||
import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability
|
import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability
|
||||||
import com.nextcloud.talk.utils.SpreedFeatures
|
import com.nextcloud.talk.utils.SpreedFeatures
|
||||||
import com.nextcloud.talk.utils.UserIdUtils.getIdForUser
|
import com.nextcloud.talk.utils.UserIdUtils.getIdForUser
|
||||||
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.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -49,7 +44,7 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
|||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
var ncApiCoroutines: NcApiCoroutines?= null
|
var ncApiCoroutines: NcApiCoroutines? = null
|
||||||
|
|
||||||
private var messageExpiration = 0
|
private var messageExpiration = 0
|
||||||
private val conversationUser: User
|
private val conversationUser: User
|
||||||
@ -71,9 +66,9 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
|||||||
suspend 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))
|
||||||
val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl,conversationToken)
|
val url = getUrlForRoomNotificationCalls(apiVersion, conversationUser.baseUrl, conversationToken)
|
||||||
val credentials = getCredentials(conversationUser.username,conversationUser.token)
|
val credentials = getCredentials(conversationUser.username, conversationUser.token)
|
||||||
val notificationLevel = if(value) 1 else 0
|
val notificationLevel = if (value) 1 else 0
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel)
|
ncApiCoroutines!!.notificationCalls(credentials!!, url, notificationLevel)
|
||||||
@ -83,7 +78,6 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("lobby_switch" != key) {
|
if ("lobby_switch" != key) {
|
||||||
arbitraryStorageManager!!.storeStorageSetting(
|
arbitraryStorageManager!!.storeStorageSetting(
|
||||||
accountIdentifier,
|
accountIdentifier,
|
||||||
@ -96,96 +90,70 @@ class DatabaseStorageModule(conversationUser: User, conversationToken: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveString(key: String, value: String) {
|
suspend fun saveString(key: String, value: String) {
|
||||||
if ("conversation_settings_dropdown" == key) {
|
when (key) {
|
||||||
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4))
|
"conversation_settings_dropdown" -> {
|
||||||
|
try {
|
||||||
val trimmedValue = value.replace("expire_", "")
|
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(4))
|
||||||
val valueInt = trimmedValue.toInt()
|
val trimmedValue = value.replace("expire_", "")
|
||||||
|
val valueInt = trimmedValue.toInt()
|
||||||
ncApi!!.setMessageExpiration(
|
withContext(Dispatchers.IO) {
|
||||||
getCredentials(
|
ncApiCoroutines!!.setMessageExpiration(
|
||||||
conversationUser.username,
|
getCredentials(conversationUser.username, conversationUser.token)!!,
|
||||||
conversationUser.token
|
getUrlForMessageExpiration(
|
||||||
),
|
apiVersion,
|
||||||
getUrlForMessageExpiration(
|
conversationUser.baseUrl,
|
||||||
apiVersion,
|
conversationToken
|
||||||
conversationUser.baseUrl,
|
),
|
||||||
conversationToken
|
valueInt
|
||||||
),
|
)
|
||||||
valueInt
|
|
||||||
)
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(object : Observer<GenericOverall> {
|
|
||||||
override fun onSubscribe(d: Disposable) {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNext(genericOverall: GenericOverall) {
|
|
||||||
messageExpiration = valueInt
|
messageExpiration = valueInt
|
||||||
}
|
}
|
||||||
|
} catch (exception: Exception) {
|
||||||
override fun onError(e: Throwable) {
|
Log.e(TAG, "Error when trying to set message expiration", exception)
|
||||||
Log.e(TAG, "Error when trying to set message expiration", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onComplete() {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else if ("conversation_info_message_notifications_dropdown" == key) {
|
|
||||||
if (hasSpreedFeatureCapability(
|
|
||||||
conversationUser.capabilities!!.spreedCapability!!,
|
|
||||||
SpreedFeatures.NOTIFICATION_LEVELS
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if (TextUtils.isEmpty(messageNotificationLevel) || messageNotificationLevel != value) {
|
|
||||||
val intValue = when (value) {
|
|
||||||
"never" -> 3
|
|
||||||
"mention" -> 2
|
|
||||||
"always" -> 1
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
|
|
||||||
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1))
|
|
||||||
|
|
||||||
ncApi!!.setNotificationLevel(
|
|
||||||
getCredentials(
|
|
||||||
conversationUser.username,
|
|
||||||
conversationUser.token
|
|
||||||
),
|
|
||||||
getUrlForRoomNotificationLevel(
|
|
||||||
apiVersion,
|
|
||||||
conversationUser.baseUrl,
|
|
||||||
conversationToken
|
|
||||||
),
|
|
||||||
intValue
|
|
||||||
)
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.subscribe(object : Observer<GenericOverall?> {
|
|
||||||
override fun onSubscribe(d: Disposable) {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNext(p0: GenericOverall) {
|
|
||||||
messageNotificationLevel = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onComplete() {
|
|
||||||
// unused atm
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
messageNotificationLevel = value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
"conversation_info_message_notifications_dropdown" -> {
|
||||||
arbitraryStorageManager!!.storeStorageSetting(accountIdentifier, key, value, conversationToken)
|
try {
|
||||||
|
if (hasSpreedFeatureCapability(
|
||||||
|
conversationUser.capabilities!!.spreedCapability!!,
|
||||||
|
SpreedFeatures.NOTIFICATION_LEVELS
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (TextUtils.isEmpty(messageNotificationLevel) || messageNotificationLevel != value) {
|
||||||
|
val intValue = when (value) {
|
||||||
|
"never" -> 3
|
||||||
|
"mention" -> 2
|
||||||
|
"always" -> 1
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
val apiVersion = getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.API_V4, 1))
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
ncApiCoroutines!!.setNotificationLevel(
|
||||||
|
getCredentials(
|
||||||
|
conversationUser.username,
|
||||||
|
conversationUser.token
|
||||||
|
)!!,
|
||||||
|
getUrlForRoomNotificationLevel(
|
||||||
|
apiVersion,
|
||||||
|
conversationUser.baseUrl,
|
||||||
|
conversationToken
|
||||||
|
),
|
||||||
|
intValue
|
||||||
|
)
|
||||||
|
messageNotificationLevel = value
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
messageNotificationLevel = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
Log.e(TAG, "Error trying to set notification level", exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
arbitraryStorageManager!!.storeStorageSetting(accountIdentifier, key, value, conversationToken)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user