mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 05:25:31 +03:00
migration to coroutines
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
91a18e27f9
commit
99d73e15e0
2 changed files with 33 additions and 55 deletions
|
@ -11,7 +11,6 @@ import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
|
|||
import com.nextcloud.talk.models.json.conversations.RoomOverall
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
||||
import io.reactivex.Observable
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.http.Body
|
||||
|
@ -121,14 +120,14 @@ interface NcApiCoroutines {
|
|||
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
||||
|
||||
@POST
|
||||
fun setReadStatusPrivacy(
|
||||
@Header("Authorization") authorization: String,
|
||||
suspend fun setReadStatusPrivacy(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String,
|
||||
@Body body: RequestBody
|
||||
): GenericOverall
|
||||
|
||||
@POST
|
||||
fun setTypingStatusPrivacy(
|
||||
suspend fun setTypingStatusPrivacy(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String,
|
||||
@Body body: RequestBody
|
||||
|
|
|
@ -49,6 +49,7 @@ import com.nextcloud.talk.R
|
|||
import com.nextcloud.talk.activities.BaseActivity
|
||||
import com.nextcloud.talk.activities.MainActivity
|
||||
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.setAppTheme
|
||||
import com.nextcloud.talk.conversationlist.ConversationsListActivity
|
||||
|
@ -103,6 +104,9 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
|
|||
@Inject
|
||||
lateinit var ncApi: NcApi
|
||||
|
||||
@Inject
|
||||
lateinit var ncApiCoroutines: NcApiCoroutines
|
||||
|
||||
@Inject
|
||||
lateinit var userManager: UserManager
|
||||
|
||||
|
@ -123,6 +127,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
|
|||
private var profileQueryDisposable: Disposable? = null
|
||||
private var dbQueryDisposable: Disposable? = null
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||
|
@ -260,6 +265,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
|
|||
setupNotificationPermissionSettings()
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
@Suppress("LongMethod")
|
||||
private fun setupNotificationPermissionSettings() {
|
||||
if (ClosedInterfaceImpl().isGooglePlayServicesAvailable) {
|
||||
|
@ -603,7 +609,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@SuppressLint("CheckResult", "StringFormatInvalid")
|
||||
private fun removeCurrentAccount() {
|
||||
userManager.scheduleUserForDeletionWithId(currentUser!!.id!!).blockingGet()
|
||||
val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build()
|
||||
|
@ -1278,31 +1284,17 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
|
|||
state = newBoolean
|
||||
val booleanValue = if (newBoolean) "0" else "1"
|
||||
val json = "{\"key\": \"read_status_privacy\", \"value\" : $booleanValue}"
|
||||
ncApi.setReadStatusPrivacy(
|
||||
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
|
||||
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
|
||||
json.toRequestBody("application/json".toMediaTypeOrNull())
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(genericOverall: GenericOverall) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
appPreferences.setReadPrivacy(!newBoolean)
|
||||
binding.settingsReadPrivacySwitch.isChecked = !newBoolean
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
try {
|
||||
ncApiCoroutines.setReadStatusPrivacy(
|
||||
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
|
||||
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
|
||||
json.toRequestBody("application/json".toMediaTypeOrNull())
|
||||
)
|
||||
Log.i(TAG, "reading status set")
|
||||
} catch (e: Exception) {
|
||||
appPreferences.setReadPrivacy(!newBoolean)
|
||||
binding.settingsReadPrivacySwitch.isChecked = !newBoolean
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1316,32 +1308,19 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
|
|||
state = newBoolean
|
||||
val booleanValue = if (newBoolean) "0" else "1"
|
||||
val json = "{\"key\": \"typing_privacy\", \"value\" : $booleanValue}"
|
||||
ncApi.setTypingStatusPrivacy(
|
||||
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
|
||||
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
|
||||
json.toRequestBody("application/json".toMediaTypeOrNull())
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(genericOverall: GenericOverall) {
|
||||
loadCapabilitiesAndUpdateSettings()
|
||||
Log.i(TAG, "onNext called typing status set")
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
appPreferences.typingStatus = !newBoolean
|
||||
binding.settingsTypingStatusSwitch.isChecked = !newBoolean
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
})
|
||||
try {
|
||||
ncApiCoroutines.setTypingStatusPrivacy(
|
||||
ApiUtils.getCredentials(currentUser!!.username, currentUser!!.token),
|
||||
ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!),
|
||||
json.toRequestBody("application/json".toMediaTypeOrNull())
|
||||
)
|
||||
loadCapabilitiesAndUpdateSettings()
|
||||
Log.i(TAG, "typing status set")
|
||||
} catch (e: Exception) {
|
||||
appPreferences.typingStatus = !newBoolean
|
||||
binding.settingsTypingStatusSwitch.isChecked = !newBoolean
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue