improved user cursor pagination

This commit is contained in:
Mariotaku Lee 2017-04-21 17:40:33 +08:00
parent 2175f0120e
commit de0df1a825
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 17 additions and 13 deletions

View File

@ -44,6 +44,7 @@ import org.mariotaku.twidere.constant.newDocumentApiKey
import org.mariotaku.twidere.loader.iface.IExtendedLoader
import org.mariotaku.twidere.loader.iface.IPaginationLoader
import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader
import org.mariotaku.twidere.model.ListResponse
import org.mariotaku.twidere.model.ParcelableUser
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.event.FriendshipTaskEvent
@ -140,7 +141,7 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
if (loader is IExtendedLoader) {
loader.fromUser = false
}
if (loader is IPaginationLoader) {
if (loader is IPaginationLoader && data?.loadSuccess() ?: false) {
nextPagination = loader.nextPagination
prevPagination = loader.prevPagination
}
@ -267,6 +268,10 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment<Parc
return adapter.findPosition(accountKey, userKey)
}
private fun List<ParcelableUser>.loadSuccess(): Boolean {
return this !is ListResponse<*> || !this.hasException()
}
protected inner class UsersBusCallback {
@Subscribe

View File

@ -20,6 +20,7 @@
package org.mariotaku.twidere.loader.users
import android.accounts.AccountManager
import android.content.ActivityNotFoundException
import android.content.Context
import org.mariotaku.kpreferences.get
import org.mariotaku.microblog.library.MicroBlogException
@ -60,19 +61,17 @@ abstract class AbsRequestUsersLoader(
}
override fun loadInBackground(): List<ParcelableUser> {
if (accountKey == null) {
return ListResponse.getListInstance(MicroBlogException("No Account"))
}
val am = AccountManager.get(context)
val details = AccountUtils.getAccountDetails(am, accountKey, true) ?:
return ListResponse.getListInstance(MicroBlogException("No Account"))
val data = data
val details: AccountDetails
val users: List<ParcelableUser>
try {
val am = AccountManager.get(context)
details = accountKey?.let { AccountUtils.getAccountDetails(am, it, true) } ?:
throw ActivityNotFoundException()
users = getUsers(details)
} catch (e: MicroBlogException) {
DebugLog.w(tr = e)
return ListResponse.getListInstance(data)
return ListResponse.getListInstance(data, e)
}
var pos = data.size
@ -94,7 +93,7 @@ abstract class AbsRequestUsersLoader(
}
@Throws(MicroBlogException::class)
final fun getUsers(details: AccountDetails): List<ParcelableUser> {
private fun getUsers(details: AccountDetails): List<ParcelableUser> {
val paging = Paging()
paging.applyItemLimit(details, loadItemLimit)
pagination?.applyTo(paging)

View File

@ -61,7 +61,7 @@ class UserFollowersLoader(
}
AccountType.FANFOU -> {
val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java)
return microBlog.getUsersFollowers(userKey.id, paging).mapToPaginated {
return microBlog.getUsersFollowers(userKey.id, paging).mapToPaginated(pagination) {
it.toParcelable(details.key, details.type, profileImageSize = profileImageSize)
}
}
@ -88,7 +88,7 @@ class UserFollowersLoader(
}
AccountType.FANFOU -> {
val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java)
return microBlog.getUsersFollowers(screenName, paging).mapToPaginated {
return microBlog.getUsersFollowers(screenName, paging).mapToPaginated(pagination) {
it.toParcelable(details.key, details.type, profileImageSize = profileImageSize)
}
}

View File

@ -61,7 +61,7 @@ class UserFriendsLoader(
}
AccountType.FANFOU -> {
val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java)
return microBlog.getUsersFriends(userKey.id, paging).mapToPaginated {
return microBlog.getUsersFriends(userKey.id, paging).mapToPaginated(pagination) {
it.toParcelable(details.key, details.type, profileImageSize = profileImageSize)
}
}
@ -88,7 +88,7 @@ class UserFriendsLoader(
}
AccountType.FANFOU -> {
val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java)
return microBlog.getUsersFriends(screenName, paging).mapToPaginated {
return microBlog.getUsersFriends(screenName, paging).mapToPaginated(pagination) {
it.toParcelable(details.key, details.type, profileImageSize = profileImageSize)
}
}