Remove rxjava from deletestatus API (#3041)

* 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.

* Remove rxjava from the deleteStatus call path

* Emit log messages with the correct tag

* Add another log tag, and lint

* Use TAG in log messages now it's present

* Lint

* Move viewModelScope.launch in to changeRelationshop()

* Use onSuccess/onFailure pair instead of fold

* Return Deferred when deleting statuses
This commit is contained in:
Nik Clayton 2023-01-10 21:20:00 +01:00 committed by GitHub
commit 561eda8482
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 50 deletions

View file

@ -364,18 +364,19 @@ abstract class SFragment : Fragment(), Injectable {
AlertDialog.Builder(requireActivity())
.setMessage(R.string.dialog_delete_post_warning)
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
timelineCases.delete(id)
.observeOn(AndroidSchedulers.mainThread())
.to(
AutoDispose.autoDisposable(
AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)
)
)
.subscribe({ }) { error: Throwable? ->
Log.w("SFragment", "error deleting status", error)
lifecycleScope.launch {
val result = timelineCases.delete(id).exceptionOrNull()
if (result != null) {
Log.w("SFragment", "error deleting status", result)
Toast.makeText(context, R.string.error_generic, Toast.LENGTH_SHORT).show()
}
removeItem(position)
// XXX: Removes the item even if there was an error. This is probably not
// correct (see similar code in showConfirmEditDialog() which only
// removes the item if the timelineCases.delete() call succeeded.
//
// Either way, this logic should be in the view model.
removeItem(position)
}
}
.setNegativeButton(android.R.string.cancel, null)
.show()
@ -388,14 +389,8 @@ abstract class SFragment : Fragment(), Injectable {
AlertDialog.Builder(requireActivity())
.setMessage(R.string.dialog_redraft_post_warning)
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
timelineCases.delete(id)
.observeOn(AndroidSchedulers.mainThread())
.to(
AutoDispose.autoDisposable(
AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)
)
)
.subscribe(
lifecycleScope.launch {
timelineCases.delete(id).fold(
{ deletedStatus ->
removeItem(position)
val sourceStatus = if (deletedStatus.isEmpty()) {
@ -416,11 +411,14 @@ abstract class SFragment : Fragment(), Injectable {
kind = ComposeActivity.ComposeKind.NEW
)
startActivity(startIntent(requireContext(), composeOptions))
},
{ error: Throwable? ->
Log.w("SFragment", "error deleting status", error)
Toast.makeText(context, R.string.error_generic, Toast.LENGTH_SHORT)
.show()
}
) { error: Throwable? ->
Log.w("SFragment", "error deleting status", error)
Toast.makeText(context, R.string.error_generic, Toast.LENGTH_SHORT).show()
}
)
}
}
.setNegativeButton(android.R.string.cancel, null)
.show()