Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <[email protected]>
  • Loading branch information
sowjanyakch committed Nov 13, 2024
1 parent a872947 commit 11ea134
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1280,23 +1280,21 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
}

private fun observeReadPrivacy() {
lifecycleScope.launch {
lifecycleScope.launch(Dispatchers.IO) {
var state = appPreferences.readPrivacy
readPrivacyFlow.collect { newBoolean ->
if (state != newBoolean) {
state = newBoolean
val booleanValue = if (newBoolean) "0" else "1"
val json = "{\"key\": \"read_status_privacy\", \"value\" : $booleanValue}"
try {
withContext(Dispatchers.IO) {
credentials?.let { credentials ->
ncApiCoroutines.setReadStatusPrivacy(
credentials,
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
json.toRequestBody("application/json".toMediaTypeOrNull())
)
Log.i(TAG, "reading status set")
}
credentials?.let { credentials ->
ncApiCoroutines.setReadStatusPrivacy(
credentials,
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
json.toRequestBody("application/json".toMediaTypeOrNull())
)
Log.i(TAG, "reading status set")
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
Expand All @@ -1315,7 +1313,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
}

private fun observeTypingStatus() {
lifecycleScope.launch {
lifecycleScope.launch(Dispatchers.IO) {
var state = appPreferences.typingStatus
typingStatusFlow.collect { newBoolean ->
if (state != newBoolean) {
Expand All @@ -1324,18 +1322,16 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
val json = "{\"key\": \"typing_privacy\", \"value\" : $booleanValue}"

try {
withContext(Dispatchers.IO) {
credentials?.let { credentials ->
ncApiCoroutines.setTypingStatusPrivacy(
credentials,
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
json.toRequestBody("application/json".toMediaTypeOrNull())
)
}
withContext(Dispatchers.Main) {
loadCapabilitiesAndUpdateSettings()
Log.i(TAG, "typing status set")
}
credentials?.let { credentials ->
ncApiCoroutines.setTypingStatusPrivacy(
credentials,
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
json.toRequestBody("application/json".toMediaTypeOrNull())
)
}
withContext(Dispatchers.Main) {
loadCapabilitiesAndUpdateSettings()
Log.i(TAG, "typing status set")
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
Expand Down

0 comments on commit 11ea134

Please sign in to comment.