Remove rxjava from API calls used by AccountViewModel::changeRelationship() (#3008)

* Remove rxjava from API calls used by AccountListFragment

* Remove rxjava from API calls used by AccountViewModel::changeRelationship()

The affected API functions are also called from

- ReportViewModel.kt
- SearchViewModel.kt
- AccountListFragment.kt
- SFragment.java
- TimelineCases.kt

so they have also been updated.

This change requires bridging from Java code to Kotlin `suspend` functions,
by creating wrappers for the `mute` and `block` functions that can be
called from Java and create a coroutine scope.

I've deliberately made this fairly ugly so that it sticks out and can be
removed later.

* Use "Throwable" type and name

* Delete 46.json

Not sure where this came from.

* Emit log messages with the correct tag

* Add another log tag, and lint

* Move viewModelScope.launch in to changeRelationshop()
This commit is contained in:
Nik Clayton 2022-12-28 19:06:31 +01:00 committed by GitHub
commit a21f2fadf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 145 additions and 142 deletions

View file

@ -133,20 +133,18 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
}
override fun onMute(mute: Boolean, id: String, position: Int, notifications: Boolean) {
if (!mute) {
api.unmuteAccount(id)
} else {
api.muteAccount(id, notifications)
}
.autoDispose(from(this))
.subscribe(
{
onMuteSuccess(mute, id, position, notifications)
},
{
onMuteFailure(mute, id, notifications)
lifecycleScope.launch {
try {
if (!mute) {
api.unmuteAccount(id)
} else {
api.muteAccount(id, notifications)
}
)
onMuteSuccess(mute, id, position, notifications)
} catch (_: Throwable) {
onMuteFailure(mute, id, notifications)
}
}
}
private fun onMuteSuccess(muted: Boolean, id: String, position: Int, notifications: Boolean) {
@ -181,20 +179,18 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
}
override fun onBlock(block: Boolean, id: String, position: Int) {
if (!block) {
api.unblockAccount(id)
} else {
api.blockAccount(id)
}
.autoDispose(from(this))
.subscribe(
{
onBlockSuccess(block, id, position)
},
{
onBlockFailure(block, id)
lifecycleScope.launch {
try {
if (!block) {
api.unblockAccount(id)
} else {
api.blockAccount(id)
}
)
onBlockSuccess(block, id, position)
} catch (_: Throwable) {
onBlockFailure(block, id)
}
}
}
private fun onBlockSuccess(blocked: Boolean, id: String, position: Int) {

View file

@ -62,8 +62,6 @@ import com.keylesspalace.tusky.view.showMuteAccountDialog
import com.keylesspalace.tusky.viewdata.AttachmentViewData
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import kotlinx.coroutines.launch
import java.lang.IllegalStateException
import java.util.LinkedHashSet
import javax.inject.Inject
/* Note from Andrew on Jan. 22, 2017: This class is a design problem for me, so I left it with an
@ -311,7 +309,9 @@ abstract class SFragment : Fragment(), Injectable {
private fun onMute(accountId: String, accountUsername: String) {
showMuteAccountDialog(this.requireActivity(), accountUsername) { notifications: Boolean?, duration: Int? ->
timelineCases.mute(accountId, notifications == true, duration)
lifecycleScope.launch {
timelineCases.mute(accountId, notifications == true, duration)
}
}
}
@ -319,7 +319,9 @@ abstract class SFragment : Fragment(), Injectable {
AlertDialog.Builder(requireContext())
.setMessage(getString(R.string.dialog_block_warning, accountUsername))
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
timelineCases.block(accountId)
lifecycleScope.launch {
timelineCases.block(accountId)
}
}
.setNegativeButton(android.R.string.cancel, null)
.show()