|
|
@ -20,6 +20,7 @@ import android.util.Log |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import androidx.lifecycle.Lifecycle |
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration |
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
@ -39,6 +40,10 @@ import com.keylesspalace.tusky.util.ThemeUtils |
|
|
|
import com.keylesspalace.tusky.util.hide |
|
|
|
import com.keylesspalace.tusky.util.hide |
|
|
|
import com.keylesspalace.tusky.util.show |
|
|
|
import com.keylesspalace.tusky.util.show |
|
|
|
import com.keylesspalace.tusky.view.EndlessOnScrollListener |
|
|
|
import com.keylesspalace.tusky.view.EndlessOnScrollListener |
|
|
|
|
|
|
|
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from |
|
|
|
|
|
|
|
import com.uber.autodispose.autoDisposable |
|
|
|
|
|
|
|
import io.reactivex.Single |
|
|
|
|
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers |
|
|
|
import kotlinx.android.synthetic.main.fragment_account_list.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_account_list.* |
|
|
|
import retrofit2.Call |
|
|
|
import retrofit2.Call |
|
|
|
import retrofit2.Callback |
|
|
|
import retrofit2.Callback |
|
|
@ -46,6 +51,7 @@ import retrofit2.Response |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
import javax.inject.Inject |
|
|
|
import javax.inject.Inject |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountListFragment : BaseFragment(), AccountActionListener, Injectable { |
|
|
|
class AccountListFragment : BaseFragment(), AccountActionListener, Injectable { |
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@Inject |
|
|
@ -248,7 +254,7 @@ class AccountListFragment : BaseFragment(), AccountActionListener, Injectable { |
|
|
|
Log.e(TAG, "Failed to $verb account id $accountId.") |
|
|
|
Log.e(TAG, "Failed to $verb account id $accountId.") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getFetchCallByListType(type: Type, fromId: String?): Call<List<Account>> { |
|
|
|
private fun getFetchCallByListType(type: Type, fromId: String?): Single<Response<List<Account>>> { |
|
|
|
return when (type) { |
|
|
|
return when (type) { |
|
|
|
Type.FOLLOWS -> api.accountFollowing(id, fromId) |
|
|
|
Type.FOLLOWS -> api.accountFollowing(id, fromId) |
|
|
|
Type.FOLLOWERS -> api.accountFollowers(id, fromId) |
|
|
|
Type.FOLLOWERS -> api.accountFollowers(id, fromId) |
|
|
@ -270,24 +276,22 @@ class AccountListFragment : BaseFragment(), AccountActionListener, Injectable { |
|
|
|
recyclerView.post { adapter.setBottomLoading(true) } |
|
|
|
recyclerView.post { adapter.setBottomLoading(true) } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val cb = object : Callback<List<Account>> { |
|
|
|
getFetchCallByListType(type, id) |
|
|
|
override fun onResponse(call: Call<List<Account>>, response: Response<List<Account>>) { |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
val accountList = response.body() |
|
|
|
.autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)) |
|
|
|
if (response.isSuccessful && accountList != null) { |
|
|
|
.subscribe({ response -> |
|
|
|
val linkHeader = response.headers().get("Link") |
|
|
|
val accountList = response.body() |
|
|
|
onFetchAccountsSuccess(accountList, linkHeader) |
|
|
|
|
|
|
|
} else { |
|
|
|
if (response.isSuccessful && accountList != null) { |
|
|
|
onFetchAccountsFailure(Exception(response.message())) |
|
|
|
val linkHeader = response.headers().get("Link") |
|
|
|
} |
|
|
|
onFetchAccountsSuccess(accountList, linkHeader) |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
onFetchAccountsFailure(Exception(response.message())) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, {throwable -> |
|
|
|
|
|
|
|
onFetchAccountsFailure(throwable) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
override fun onFailure(call: Call<List<Account>>, t: Throwable) { |
|
|
|
|
|
|
|
onFetchAccountsFailure(t as Exception) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val listCall = getFetchCallByListType(type, id) |
|
|
|
|
|
|
|
callList.add(listCall) |
|
|
|
|
|
|
|
listCall.enqueue(cb) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun onFetchAccountsSuccess(accounts: List<Account>, linkHeader: String?) { |
|
|
|
private fun onFetchAccountsSuccess(accounts: List<Account>, linkHeader: String?) { |
|
|
@ -319,13 +323,13 @@ class AccountListFragment : BaseFragment(), AccountActionListener, Injectable { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun onFetchAccountsFailure(exception: Exception) { |
|
|
|
private fun onFetchAccountsFailure(throwable: Throwable) { |
|
|
|
fetching = false |
|
|
|
fetching = false |
|
|
|
Log.e(TAG, "Fetch failure", exception) |
|
|
|
Log.e(TAG, "Fetch failure", throwable) |
|
|
|
|
|
|
|
|
|
|
|
if (adapter.itemCount == 0) { |
|
|
|
if (adapter.itemCount == 0) { |
|
|
|
messageView.show() |
|
|
|
messageView.show() |
|
|
|
if (exception is IOException) { |
|
|
|
if (throwable is IOException) { |
|
|
|
messageView.setup(R.drawable.elephant_offline, R.string.error_network) { |
|
|
|
messageView.setup(R.drawable.elephant_offline, R.string.error_network) { |
|
|
|
messageView.hide() |
|
|
|
messageView.hide() |
|
|
|
this.fetchAccounts(null) |
|
|
|
this.fetchAccounts(null) |
|
|
|