Remove rxjava from API calls used by AccountListFragment::fetchAccounts() (#3005)
* Remove rxjava from API calls used by AccountListFragment * Use "Throwable" type and name
This commit is contained in:
parent
f796f77f9a
commit
e20fda322e
2 changed files with 37 additions and 34 deletions
|
@ -20,6 +20,7 @@ import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.ConcatAdapter
|
import androidx.recyclerview.widget.ConcatAdapter
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
|
@ -53,10 +54,9 @@ import com.keylesspalace.tusky.util.show
|
||||||
import com.keylesspalace.tusky.util.viewBinding
|
import com.keylesspalace.tusky.util.viewBinding
|
||||||
import com.keylesspalace.tusky.view.EndlessOnScrollListener
|
import com.keylesspalace.tusky.view.EndlessOnScrollListener
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.core.Single
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.HashMap
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountActionListener, Injectable {
|
class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountActionListener, Injectable {
|
||||||
|
@ -255,7 +255,7 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
||||||
followRequestsAdapter.removeItem(position)
|
followRequestsAdapter.removeItem(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFetchCallByListType(fromId: String?): Single<Response<List<TimelineAccount>>> {
|
private suspend fun getFetchCallByListType(fromId: String?): Response<List<TimelineAccount>> {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
Type.FOLLOWS -> {
|
Type.FOLLOWS -> {
|
||||||
val accountId = requireId(type, id)
|
val accountId = requireId(type, id)
|
||||||
|
@ -293,24 +293,27 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
||||||
binding.recyclerView.post { adapter.setBottomLoading(true) }
|
binding.recyclerView.post { adapter.setBottomLoading(true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
getFetchCallByListType(fromId)
|
lifecycleScope.launch {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
try {
|
||||||
.autoDispose(from(this, Lifecycle.Event.ON_DESTROY))
|
val response = getFetchCallByListType(fromId)
|
||||||
.subscribe(
|
if (!response.isSuccessful) {
|
||||||
{ response ->
|
onFetchAccountsFailure(Exception(response.message()))
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
val accountList = response.body()
|
val accountList = response.body()
|
||||||
|
|
||||||
if (response.isSuccessful && accountList != null) {
|
if (accountList == null) {
|
||||||
|
onFetchAccountsFailure(Exception(response.message()))
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
val linkHeader = response.headers()["Link"]
|
val linkHeader = response.headers()["Link"]
|
||||||
onFetchAccountsSuccess(accountList, linkHeader)
|
onFetchAccountsSuccess(accountList, linkHeader)
|
||||||
} else {
|
} catch (throwable: Throwable) {
|
||||||
onFetchAccountsFailure(Exception(response.message()))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ throwable ->
|
|
||||||
onFetchAccountsFailure(throwable)
|
onFetchAccountsFailure(throwable)
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onFetchAccountsSuccess(accounts: List<TimelineAccount>, linkHeader: String?) {
|
private fun onFetchAccountsSuccess(accounts: List<TimelineAccount>, linkHeader: String?) {
|
||||||
|
|
|
@ -180,16 +180,16 @@ interface MastodonApi {
|
||||||
): NetworkResult<StatusContext>
|
): NetworkResult<StatusContext>
|
||||||
|
|
||||||
@GET("api/v1/statuses/{id}/reblogged_by")
|
@GET("api/v1/statuses/{id}/reblogged_by")
|
||||||
fun statusRebloggedBy(
|
suspend fun statusRebloggedBy(
|
||||||
@Path("id") statusId: String,
|
@Path("id") statusId: String,
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@GET("api/v1/statuses/{id}/favourited_by")
|
@GET("api/v1/statuses/{id}/favourited_by")
|
||||||
fun statusFavouritedBy(
|
suspend fun statusFavouritedBy(
|
||||||
@Path("id") statusId: String,
|
@Path("id") statusId: String,
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@DELETE("api/v1/statuses/{id}")
|
@DELETE("api/v1/statuses/{id}")
|
||||||
fun deleteStatus(
|
fun deleteStatus(
|
||||||
|
@ -331,16 +331,16 @@ interface MastodonApi {
|
||||||
): Response<List<Status>>
|
): Response<List<Status>>
|
||||||
|
|
||||||
@GET("api/v1/accounts/{id}/followers")
|
@GET("api/v1/accounts/{id}/followers")
|
||||||
fun accountFollowers(
|
suspend fun accountFollowers(
|
||||||
@Path("id") accountId: String,
|
@Path("id") accountId: String,
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@GET("api/v1/accounts/{id}/following")
|
@GET("api/v1/accounts/{id}/following")
|
||||||
fun accountFollowing(
|
suspend fun accountFollowing(
|
||||||
@Path("id") accountId: String,
|
@Path("id") accountId: String,
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("api/v1/accounts/{id}/follow")
|
@POST("api/v1/accounts/{id}/follow")
|
||||||
|
@ -394,14 +394,14 @@ interface MastodonApi {
|
||||||
): Single<Relationship>
|
): Single<Relationship>
|
||||||
|
|
||||||
@GET("api/v1/blocks")
|
@GET("api/v1/blocks")
|
||||||
fun blocks(
|
suspend fun blocks(
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@GET("api/v1/mutes")
|
@GET("api/v1/mutes")
|
||||||
fun mutes(
|
suspend fun mutes(
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@GET("api/v1/domain_blocks")
|
@GET("api/v1/domain_blocks")
|
||||||
fun domainBlocks(
|
fun domainBlocks(
|
||||||
|
@ -436,9 +436,9 @@ interface MastodonApi {
|
||||||
): Response<List<Status>>
|
): Response<List<Status>>
|
||||||
|
|
||||||
@GET("api/v1/follow_requests")
|
@GET("api/v1/follow_requests")
|
||||||
fun followRequests(
|
suspend fun followRequests(
|
||||||
@Query("max_id") maxId: String?
|
@Query("max_id") maxId: String?
|
||||||
): Single<Response<List<TimelineAccount>>>
|
): Response<List<TimelineAccount>>
|
||||||
|
|
||||||
@POST("api/v1/follow_requests/{id}/authorize")
|
@POST("api/v1/follow_requests/{id}/authorize")
|
||||||
fun authorizeFollowRequest(
|
fun authorizeFollowRequest(
|
||||||
|
|
Loading…
Reference in a new issue