migrated status pagination

This commit is contained in:
Mariotaku Lee 2017-04-22 00:32:03 +08:00
parent 2308a6c291
commit 8fc93f1d2e
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
34 changed files with 344 additions and 338 deletions

View File

@ -136,6 +136,8 @@ public class Status {
@JsonField(name = "application") @JsonField(name = "application")
Application application; Application application;
private long sortId = -1;
public String getId() { public String getId() {
return id; return id;
} }
@ -217,6 +219,21 @@ public class Status {
return application; return application;
} }
public long getSortId() {
if (sortId != -1) return sortId;
// Try use long id
try {
sortId = Long.parseLong(id);
} catch (NumberFormatException e) {
// Ignore
}
if (sortId == -1 && createdAt != null) {
// Try use timestamp
sortId = createdAt.getTime();
}
return sortId;
}
@Override @Override
public String toString() { public String toString() {
return "Status{" + return "Status{" +

View File

@ -160,12 +160,9 @@ public interface IntentConstants {
String EXTRA_LOCATION = "location"; String EXTRA_LOCATION = "location";
String EXTRA_URL = "url"; String EXTRA_URL = "url";
String EXTRA_PROFILE_URL = "profile_url"; String EXTRA_PROFILE_URL = "profile_url";
String EXTRA_NEXT_PAGE = "next_page";
String EXTRA_NEXT_PAGINATION = "next_pagination"; String EXTRA_NEXT_PAGINATION = "next_pagination";
String EXTRA_PREV_PAGINATION = "prev_pagination"; String EXTRA_PREV_PAGINATION = "prev_pagination";
String EXTRA_PAGINATION = "pagination"; String EXTRA_PAGINATION = "pagination";
String EXTRA_NEXT_CURSOR = "next_cursor";
String EXTRA_PREV_CURSOR = "prev_cursor";
String EXTRA_EXTRA_INTENT = "extra_intent"; String EXTRA_EXTRA_INTENT = "extra_intent";
String EXTRA_IS_MY_ACCOUNT = "is_my_account"; String EXTRA_IS_MY_ACCOUNT = "is_my_account";
String EXTRA_TAB_TYPE = "tab_type"; String EXTRA_TAB_TYPE = "tab_type";

View File

@ -42,6 +42,10 @@ public class CursorPagination implements Pagination, Parcelable {
return cursor; return cursor;
} }
public void setCursor(String cursor) {
this.cursor = cursor;
}
@Override @Override
public void applyTo(Paging paging) { public void applyTo(Paging paging) {
paging.cursor(cursor); paging.cursor(cursor);
@ -69,6 +73,14 @@ public class CursorPagination implements Pagination, Parcelable {
} }
}; };
@Nullable
public static CursorPagination valueOf(String cursor) {
if (cursor == null) return null;
final CursorPagination pagination = new CursorPagination();
pagination.cursor = cursor;
return pagination;
}
@Nullable @Nullable
public static CursorPagination valueOf(long cursor) { public static CursorPagination valueOf(long cursor) {
if (cursor == 0) return null; if (cursor == 0) return null;

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.model.pagination;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.Nullable;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
@ -35,6 +36,8 @@ public class SinceMaxPagination implements Pagination, Parcelable {
String sinceId; String sinceId;
String maxId; String maxId;
long sinceSortId;
long maxSortId;
public String getSinceId() { public String getSinceId() {
return sinceId; return sinceId;
@ -52,6 +55,22 @@ public class SinceMaxPagination implements Pagination, Parcelable {
this.maxId = maxId; this.maxId = maxId;
} }
public long getSinceSortId() {
return sinceSortId;
}
public void setSinceSortId(long sinceSortId) {
this.sinceSortId = sinceSortId;
}
public long getMaxSortId() {
return maxSortId;
}
public void setMaxSortId(long maxSortId) {
this.maxSortId = maxSortId;
}
@Override @Override
public void applyTo(Paging paging) { public void applyTo(Paging paging) {
if (sinceId != null) { if (sinceId != null) {
@ -72,6 +91,24 @@ public class SinceMaxPagination implements Pagination, Parcelable {
SinceMaxPaginationParcelablePlease.writeToParcel(this, dest, flags); SinceMaxPaginationParcelablePlease.writeToParcel(this, dest, flags);
} }
@Nullable
public static SinceMaxPagination sinceId(String sinceId, long sinceSortId) {
if (sinceId == null) return null;
SinceMaxPagination pagination = new SinceMaxPagination();
pagination.setSinceId(sinceId);
pagination.setSinceSortId(sinceSortId);
return pagination;
}
@Nullable
public static SinceMaxPagination maxId(String maxId, long maxSortId) {
if (maxId == null) return null;
SinceMaxPagination pagination = new SinceMaxPagination();
pagination.setMaxId(maxId);
pagination.setMaxSortId(maxSortId);
return pagination;
}
public static final Creator<SinceMaxPagination> CREATOR = new Creator<SinceMaxPagination>() { public static final Creator<SinceMaxPagination> CREATOR = new Creator<SinceMaxPagination>() {
public SinceMaxPagination createFromParcel(Parcel source) { public SinceMaxPagination createFromParcel(Parcel source) {
SinceMaxPagination target = new SinceMaxPagination(); SinceMaxPagination target = new SinceMaxPagination();

View File

@ -148,8 +148,9 @@ class UserListSelectorActivity : BaseActivity(),
override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableUserList>> { override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableUserList>> {
val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = args.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY) val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
val nextCursor = args.getLong(EXTRA_NEXT_CURSOR) return UserListOwnershipsLoader(this, accountKey, userKey, null, adapter.all).apply {
return UserListOwnershipsLoader(this, accountKey, userKey, null, adapter.all) pagination = args.getParcelable(EXTRA_PAGINATION)
}
} }
override fun onLoaderReset(loader: Loader<List<ParcelableUserList>>?) { override fun onLoaderReset(loader: Loader<List<ParcelableUserList>>?) {

View File

@ -0,0 +1,44 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.extension.model
import org.mariotaku.twidere.model.RefreshTaskParam
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
val RefreshTaskParam.hasMaxIds: Boolean
get() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
fun RefreshTaskParam.getMaxId(index: Int): String? {
return (pagination?.get(index) as? SinceMaxPagination)?.maxId
}
fun RefreshTaskParam.getSinceId(index: Int): String? {
return (pagination?.get(index) as? SinceMaxPagination)?.sinceId
}
fun RefreshTaskParam.getMaxSortId(index: Int): Long {
return (pagination?.get(index) as? SinceMaxPagination)?.maxSortId ?: -1
}
fun RefreshTaskParam.getSinceSortId(index: Int): Long {
return (pagination?.get(index) as? SinceMaxPagination)?.sinceSortId ?: -1
}

View File

@ -38,6 +38,7 @@ fun Status.toParcelable(accountKey: UserKey): ParcelableStatus {
val extras = ParcelableStatus.Extras() val extras = ParcelableStatus.Extras()
result.account_key = accountKey result.account_key = accountKey
result.id = id result.id = id
result.sort_id = sortId
result.timestamp = createdAt?.time ?: 0 result.timestamp = createdAt?.time ?: 0
extras.summary_text = spoilerText extras.summary_text = spoilerText

View File

@ -62,6 +62,7 @@ import org.mariotaku.twidere.loader.iface.IExtendedLoader
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.analyzer.Share import org.mariotaku.twidere.model.analyzer.Share
import org.mariotaku.twidere.model.event.StatusListChangedEvent import org.mariotaku.twidere.model.event.StatusListChangedEvent
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.model.util.ParcelableActivityUtils import org.mariotaku.twidere.model.util.ParcelableActivityUtils
import org.mariotaku.twidere.model.util.getActivityStatus import org.mariotaku.twidere.model.util.getActivityStatus
@ -305,10 +306,9 @@ abstract class AbsActivitiesFragment protected constructor() :
} }
} }
val accountKeys = arrayOf(activity.account_key) val accountKeys = arrayOf(activity.account_key)
val maxIds = arrayOf(activity.min_position) val pagination = arrayOf(SinceMaxPagination.maxId(activity.min_position,
val maxSortIds = longArrayOf(activity.min_sort_position) activity.min_sort_position))
getActivities(BaseRefreshTaskParam(accountKeys = accountKeys, maxIds = maxIds, getActivities(BaseRefreshTaskParam(accountKeys, pagination).also {
sinceIds = null, maxSortIds = maxSortIds, sinceSortIds = null).also {
it.extraId = activity._id it.extraId = activity._id
}) })
} }

View File

@ -57,6 +57,7 @@ import org.mariotaku.twidere.loader.iface.IExtendedLoader
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.analyzer.Share import org.mariotaku.twidere.model.analyzer.Share
import org.mariotaku.twidere.model.event.StatusListChangedEvent import org.mariotaku.twidere.model.event.StatusListChangedEvent
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.model.timeline.TimelineFilter import org.mariotaku.twidere.model.timeline.TimelineFilter
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
@ -351,10 +352,8 @@ abstract class AbsStatusesFragment : AbsContentListRecyclerViewFragment<Parcelab
DebugLog.v(msg = "Load activity gap $status") DebugLog.v(msg = "Load activity gap $status")
adapter.addGapLoadingId(ObjectId(status.account_key, status.id)) adapter.addGapLoadingId(ObjectId(status.account_key, status.id))
val accountKeys = arrayOf(status.account_key) val accountKeys = arrayOf(status.account_key)
val maxIds = arrayOf<String?>(status.id) val pagination = arrayOf(SinceMaxPagination.maxId(status.id, status.sort_id))
val maxSortIds = longArrayOf(status.sort_id) getStatuses(BaseRefreshTaskParam(accountKeys, pagination))
getStatuses(BaseRefreshTaskParam(accountKeys = accountKeys, maxIds = maxIds, sinceIds = null,
maxSortIds = maxSortIds, sinceSortIds = null))
} }
override fun onMediaClick(holder: IStatusViewHolder, view: View, current: ParcelableMedia, override fun onMediaClick(holder: IStatusViewHolder, view: View, current: ParcelableMedia,

View File

@ -44,6 +44,7 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_FROM_USER
import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.event.* import org.mariotaku.twidere.model.event.*
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.provider.TwidereDataStore.Activities import org.mariotaku.twidere.provider.TwidereDataStore.Activities
import org.mariotaku.twidere.provider.TwidereDataStore.Filters import org.mariotaku.twidere.provider.TwidereDataStore.Filters
import org.mariotaku.twidere.task.twitter.GetStatusesTask import org.mariotaku.twidere.task.twitter.GetStatusesTask
@ -145,28 +146,22 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
super.onLoadMoreContents(position) super.onLoadMoreContents(position)
if (position == 0L) return if (position == 0L) return
val contentUri = this.contentUri val contentUri = this.contentUri
getActivities(object : SimpleRefreshTaskParam() { getActivities(object : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { override val accountKeys by lazy {
this@CursorActivitiesFragment.accountKeys this@CursorActivitiesFragment.accountKeys
} }
override val maxIds: Array<String?>? override val pagination by lazy {
get() { val keys = accountKeys.toNulls()
val context = context ?: return null val maxIds = DataStoreUtils.getRefreshOldestActivityMaxPositions(context, contentUri,
return DataStoreUtils.getRefreshOldestActivityMaxPositions(context, contentUri, keys)
accountKeys.toNulls()) val maxSortIds = DataStoreUtils.getRefreshOldestActivityMaxSortPositions(context,
contentUri, keys)
return@lazy Array(keys.size) { idx ->
SinceMaxPagination.maxId(maxIds[idx], maxSortIds[idx])
} }
override val maxSortIds: LongArray?
get() {
val context = context ?: return null
return DataStoreUtils.getRefreshOldestActivityMaxSortPositions(context,
contentUri, accountKeys.toNulls())
} }
override val hasMaxIds: Boolean
get() = true
override val shouldAbort: Boolean override val shouldAbort: Boolean
get() = context == null get() = context == null
}) })
@ -176,28 +171,22 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
override fun triggerRefresh(): Boolean { override fun triggerRefresh(): Boolean {
super.triggerRefresh() super.triggerRefresh()
val contentUri = this.contentUri val contentUri = this.contentUri
getActivities(object : SimpleRefreshTaskParam() { getActivities(object : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { override val accountKeys by lazy {
this@CursorActivitiesFragment.accountKeys this@CursorActivitiesFragment.accountKeys
} }
override val sinceIds: Array<String?>? override val pagination by lazy {
get() { val keys = accountKeys.toNulls()
val context = context ?: return null val sinceIds = DataStoreUtils.getRefreshNewestActivityMaxPositions(context,
return DataStoreUtils.getRefreshNewestActivityMaxPositions(context, contentUri, contentUri, keys)
accountKeys.toNulls()) val sinceSortIds = DataStoreUtils.getRefreshNewestActivityMaxSortPositions(context,
contentUri, keys)
return@lazy Array(keys.size) { idx ->
SinceMaxPagination.sinceId(sinceIds[idx], sinceSortIds[idx])
} }
override val sinceSortIds: LongArray?
get() {
val context = context ?: return null
return DataStoreUtils.getRefreshNewestActivityMaxSortPositions(context,
contentUri, accountKeys.toNulls())
} }
override val hasSinceIds: Boolean
get() = true
override val shouldAbort: Boolean override val shouldAbort: Boolean
get() = context == null get() = context == null
}) })

View File

@ -45,9 +45,10 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_FROM_USER
import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader
import org.mariotaku.twidere.model.ParameterizedExpression import org.mariotaku.twidere.model.ParameterizedExpression
import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.ParcelableStatus
import org.mariotaku.twidere.model.SimpleRefreshTaskParam import org.mariotaku.twidere.model.RefreshTaskParam
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.event.* import org.mariotaku.twidere.model.event.*
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.provider.TwidereDataStore.Filters import org.mariotaku.twidere.provider.TwidereDataStore.Filters
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
import org.mariotaku.twidere.task.twitter.GetStatusesTask import org.mariotaku.twidere.task.twitter.GetStatusesTask
@ -181,44 +182,38 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
if (ILoadMoreSupportAdapter.START in position) return if (ILoadMoreSupportAdapter.START in position) return
super.onLoadMoreContents(position) super.onLoadMoreContents(position)
if (position == 0L) return if (position == 0L) return
getStatuses(object : SimpleRefreshTaskParam() { getStatuses(object : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { override val accountKeys by lazy {
this@CursorStatusesFragment.accountKeys this@CursorStatusesFragment.accountKeys
} }
override val maxIds: Array<String?>? override val pagination by lazy {
get() = getOldestStatusIds(accountKeys) val keys = accountKeys.toNulls()
val maxIds = DataStoreUtils.getOldestStatusIds(context, contentUri, keys)
override val maxSortIds: LongArray? val maxSortIds = DataStoreUtils.getOldestStatusSortIds(context, contentUri, keys)
get() { return@lazy Array(keys.size) { idx ->
val context = context ?: return null SinceMaxPagination.maxId(maxIds[idx], maxSortIds[idx])
return DataStoreUtils.getOldestStatusSortIds(context, contentUri, }
accountKeys.toNulls())
} }
override val hasMaxIds: Boolean
get() = true
override val shouldAbort: Boolean
get() = context == null
}) })
} }
override fun triggerRefresh(): Boolean { override fun triggerRefresh(): Boolean {
super.triggerRefresh() super.triggerRefresh()
getStatuses(object : SimpleRefreshTaskParam() { getStatuses(object : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { override val accountKeys: Array<UserKey> by lazy {
this@CursorStatusesFragment.accountKeys this@CursorStatusesFragment.accountKeys
} }
override val hasMaxIds: Boolean override val pagination by lazy {
get() = false val keys = accountKeys.toNulls()
val sinceIds = DataStoreUtils.getNewestStatusIds(context, contentUri, keys)
override val sinceIds: Array<String?>? val sinceSortIds = DataStoreUtils.getNewestStatusSortIds(context, contentUri, keys)
get() = getNewestStatusIds(accountKeys) return@lazy Array(keys.size) { idx ->
SinceMaxPagination.sinceId(sinceIds[idx], sinceSortIds[idx])
override val sinceSortIds: LongArray? }
get() = DataStoreUtils.getNewestStatusSortIds(context, contentUri, accountKeys.toNulls()) }
override val shouldAbort: Boolean override val shouldAbort: Boolean
get() = context == null get() = context == null
@ -231,11 +226,6 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
return buildStatusFilterWhereClause(preferences, table, null) return buildStatusFilterWhereClause(preferences, table, null)
} }
protected fun getNewestStatusIds(accountKeys: Array<UserKey>): Array<String?>? {
val context = context ?: return null
return DataStoreUtils.getNewestStatusIds(context, contentUri, accountKeys.toNulls())
}
override fun setUserVisibleHint(isVisibleToUser: Boolean) { override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser) super.setUserVisibleHint(isVisibleToUser)
val context = context val context = context
@ -246,12 +236,6 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
} }
} }
protected fun getOldestStatusIds(accountKeys: Array<UserKey>): Array<String?>? {
val context = context ?: return null
return DataStoreUtils.getOldestStatusIds(context, contentUri, accountKeys.toNulls())
}
protected open fun processWhere(where: Expression, whereArgs: Array<String>): ParameterizedExpression { protected open fun processWhere(where: Expression, whereArgs: Array<String>): ParameterizedExpression {
return ParameterizedExpression(where, whereArgs) return ParameterizedExpression(where, whereArgs)
} }

View File

@ -23,6 +23,7 @@ import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.TwidereConstants.NOTIFICATION_ID_HOME_TIMELINE import org.mariotaku.twidere.TwidereConstants.NOTIFICATION_ID_HOME_TIMELINE
import org.mariotaku.twidere.annotation.ReadPositionTag import org.mariotaku.twidere.annotation.ReadPositionTag
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
import org.mariotaku.twidere.extension.model.hasMaxIds
import org.mariotaku.twidere.model.ParameterizedExpression import org.mariotaku.twidere.model.ParameterizedExpression
import org.mariotaku.twidere.model.RefreshTaskParam import org.mariotaku.twidere.model.RefreshTaskParam
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
@ -95,3 +96,4 @@ class HomeTimelineFragment : CursorStatusesFragment() {
} }
} }

View File

@ -31,6 +31,7 @@ import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
import org.mariotaku.twidere.extension.getErrorMessage import org.mariotaku.twidere.extension.getErrorMessage
import org.mariotaku.twidere.extension.model.getMaxId
import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader
import org.mariotaku.twidere.model.BaseRefreshTaskParam import org.mariotaku.twidere.model.BaseRefreshTaskParam
import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.ParcelableStatus
@ -67,13 +68,12 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
get() = Utils.getAccountKeys(context, arguments) ?: emptyArray() get() = Utils.getAccountKeys(context, arguments) ?: emptyArray()
private var lastId: String? = null private var lastId: String? = null
private var page = 1 private var nextPagination: Pagination? = null
private var pageDelta: Int = 0
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
if (savedInstanceState != null) { if (savedInstanceState != null) {
page = savedInstanceState.getInt(EXTRA_PAGE) nextPagination = savedInstanceState.getParcelable(EXTRA_NEXT_PAGINATION)
} }
} }
@ -89,28 +89,27 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
outState.putInt(EXTRA_PAGE, page) outState.putParcelable(EXTRA_NEXT_PAGINATION, nextPagination)
}
override fun onCreateLoader(id: Int, args: Bundle): Loader<List<ParcelableStatus>?> {
val loader = super.onCreateLoader(id, args)
if (loader is AbsRequestStatusesLoader) {
loader.pagination = args.getParcelable(EXTRA_PAGINATION)
}
return loader
} }
override fun getStatuses(param: RefreshTaskParam): Boolean { override fun getStatuses(param: RefreshTaskParam): Boolean {
if (!loaderInitialized) return false if (!loaderInitialized) return false
val args = Bundle(arguments) val args = Bundle(arguments)
val maxIds = param.maxIds val maxId = param.getMaxId(0)
if (maxIds != null) { if (maxId != null) {
args.putString(EXTRA_MAX_ID, maxIds[0])
args.putBoolean(EXTRA_MAKE_GAP, false) args.putBoolean(EXTRA_MAKE_GAP, false)
} }
val sinceIds = param.sinceIds
if (sinceIds != null) {
args.putString(EXTRA_SINCE_ID, sinceIds[0])
}
args.putBoolean(EXTRA_LOADING_MORE, param.isLoadingMore) args.putBoolean(EXTRA_LOADING_MORE, param.isLoadingMore)
args.putBoolean(EXTRA_FROM_USER, true) args.putBoolean(EXTRA_FROM_USER, true)
if (param is StatusesRefreshTaskParam) { args.putParcelable(EXTRA_PAGINATION, param.pagination?.getOrNull(0))
if (param.page > 0) {
args.putInt(EXTRA_PAGE, param.page)
}
}
loaderManager.restartLoader(loaderId, args, this) loaderManager.restartLoader(loaderId, args, this)
return true return true
} }
@ -160,8 +159,8 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
if (statusCount <= 0) return if (statusCount <= 0) return
val status = adapter.getStatus(startIdx + statusCount - 1, true) val status = adapter.getStatus(startIdx + statusCount - 1, true)
val accountKeys = arrayOf(status.account_key) val accountKeys = arrayOf(status.account_key)
val maxIds = arrayOf<String?>(status.id) val pagination = arrayOf<Pagination?>(SinceMaxPagination.maxId(status.id, -1))
val param = StatusesRefreshTaskParam(accountKeys, maxIds, null, page + pageDelta) val param = BaseRefreshTaskParam(accountKeys, pagination)
param.isLoadingMore = true param.isLoadingMore = true
getStatuses(param) getStatuses(param)
} }
@ -172,20 +171,20 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
val statusStartIndex = adapter.statusStartIndex val statusStartIndex = adapter.statusStartIndex
if (statusStartIndex >= 0 && adapter.getStatusCount(true) > 0) { if (statusStartIndex >= 0 && adapter.getStatusCount(true) > 0) {
val firstStatus = adapter.getStatus(statusStartIndex, true) val firstStatus = adapter.getStatus(statusStartIndex, true)
val sinceIds = Array(accountKeys.size) { val pagination = Array(accountKeys.size) {
return@Array if (firstStatus.account_key == accountKeys[it]) firstStatus.id else null if (firstStatus.account_key == accountKeys[it]) {
} SinceMaxPagination.sinceId(firstStatus.id, -1)
getStatuses(BaseRefreshTaskParam(accountKeys, null, sinceIds))
} else { } else {
getStatuses(BaseRefreshTaskParam(accountKeys, null, null)) null
}
}
getStatuses(BaseRefreshTaskParam(accountKeys, pagination))
} else {
getStatuses(BaseRefreshTaskParam(accountKeys, null))
} }
return true return true
} }
override fun onHasMoreDataChanged(hasMoreData: Boolean) {
pageDelta = if (hasMoreData) 1 else 0
}
fun removeStatus(statusId: String) { fun removeStatus(statusId: String) {
val list = adapterData ?: return val list = adapterData ?: return
val dataToRemove = HashSet<ParcelableStatus>() val dataToRemove = HashSet<ParcelableStatus>()
@ -222,7 +221,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
adapter.notifyItemRangeChanged(rangeStart, rangeEnd) adapter.notifyItemRangeChanged(rangeStart, rangeEnd)
} }
private fun updateFavoritedStatus(status: ParcelableStatus) { private fun updateFavoritedStatus(status: ParcelableStatus) {
replaceStatusStates(status) replaceStatusStates(status)
} }
@ -281,21 +279,4 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
} }
protected class StatusesRefreshTaskParam(
accountKeys: Array<UserKey>,
maxIds: Array<String?>?,
sinceIds: Array<String?>?,
var page: Int = -1
) : BaseRefreshTaskParam(accountKeys, maxIds, sinceIds)
companion object {
fun Bundle.toPagination(): Pagination {
val maxId = getString(EXTRA_MAX_ID)
val sinceId = getString(EXTRA_SINCE_ID)
return SinceMaxPagination().apply {
this.maxId = maxId
this.sinceId = sinceId
}
}
}
} }

View File

@ -94,7 +94,6 @@ import org.mariotaku.twidere.extension.model.*
import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable
import org.mariotaku.twidere.extension.view.calculateSpaceItemHeight import org.mariotaku.twidere.extension.view.calculateSpaceItemHeight
import org.mariotaku.twidere.fragment.AbsStatusesFragment.Companion.handleActionClick import org.mariotaku.twidere.fragment.AbsStatusesFragment.Companion.handleActionClick
import org.mariotaku.twidere.fragment.ParcelableStatusesFragment.Companion.toPagination
import org.mariotaku.twidere.loader.ParcelableStatusLoader import org.mariotaku.twidere.loader.ParcelableStatusLoader
import org.mariotaku.twidere.loader.statuses.ConversationLoader import org.mariotaku.twidere.loader.statuses.ConversationLoader
import org.mariotaku.twidere.menu.FavoriteItemProvider import org.mariotaku.twidere.menu.FavoriteItemProvider
@ -103,6 +102,8 @@ import org.mariotaku.twidere.model.analyzer.Share
import org.mariotaku.twidere.model.analyzer.StatusView import org.mariotaku.twidere.model.analyzer.StatusView
import org.mariotaku.twidere.model.event.FavoriteTaskEvent import org.mariotaku.twidere.model.event.FavoriteTaskEvent
import org.mariotaku.twidere.model.event.StatusListChangedEvent import org.mariotaku.twidere.model.event.StatusListChangedEvent
import org.mariotaku.twidere.model.pagination.Pagination
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.model.util.* import org.mariotaku.twidere.model.util.*
import org.mariotaku.twidere.provider.TwidereDataStore.* import org.mariotaku.twidere.provider.TwidereDataStore.*
import org.mariotaku.twidere.task.AbsAccountRequestTask import org.mariotaku.twidere.task.AbsAccountRequestTask
@ -152,13 +153,8 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
adapter.isConversationsLoading = true adapter.isConversationsLoading = true
adapter.updateItemDecoration() adapter.updateItemDecoration()
val status: ParcelableStatus = args.getParcelable(EXTRA_STATUS) val status: ParcelableStatus = args.getParcelable(EXTRA_STATUS)
val maxId = args.getString(EXTRA_MAX_ID)
val sinceId = args.getString(EXTRA_SINCE_ID)
val maxSortId = args.getLong(EXTRA_MAX_SORT_ID)
val sinceSortId = args.getLong(EXTRA_SINCE_SORT_ID)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return ConversationLoader(activity, status, sinceSortId, maxSortId, adapter.getData(), return ConversationLoader(activity, status, adapter.getData(), true, loadingMore).apply {
true, loadingMore).apply {
pagination = args.toPagination() pagination = args.toPagination()
// Setting comparator to null lets statuses sort ascending // Setting comparator to null lets statuses sort ascending
comparator = null comparator = null
@ -171,7 +167,8 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
val conversationLoader = loader as ConversationLoader val conversationLoader = loader as ConversationLoader
var supportedPositions: Long = 0 var supportedPositions: Long = 0
if (data != null && !data.isEmpty()) { if (data != null && !data.isEmpty()) {
if (conversationLoader.sinceSortId < data[data.size - 1].sort_id) { val sinceSortId = (conversationLoader.pagination as? SinceMaxPagination)?.sinceSortId ?: -1
if (sinceSortId < data[data.size - 1].sort_id) {
supportedPositions = supportedPositions or ILoadMoreSupportAdapter.END supportedPositions = supportedPositions or ILoadMoreSupportAdapter.END
} }
if (data[0].in_reply_to_status_id != null) { if (data[0].in_reply_to_status_id != null) {
@ -2181,5 +2178,18 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
private val STATE_LOADED = 1 private val STATE_LOADED = 1
private val STATE_LOADING = 2 private val STATE_LOADING = 2
private val STATE_ERROR = 3 private val STATE_ERROR = 3
fun Bundle.toPagination(): Pagination {
val maxId = getString(EXTRA_MAX_ID)
val sinceId = getString(EXTRA_SINCE_ID)
val maxSortId = getLong(EXTRA_MAX_SORT_ID)
val sinceSortId = getLong(EXTRA_SINCE_SORT_ID)
return SinceMaxPagination().apply {
this.maxId = maxId
this.sinceId = sinceId
this.maxSortId = maxSortId
this.sinceSortId = sinceSortId
}
}
} }
} }

View File

@ -109,9 +109,7 @@ class GroupTimelineFragment : ParcelableStatusesFragment() {
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return GroupTimelineLoader(activity, accountKey, groupId, groupName, adapterData, return GroupTimelineLoader(activity, accountKey, groupId, groupName, adapterData,
savedStatusesFileArgs, tabPosition, fromUser, loadingMore).apply { savedStatusesFileArgs, tabPosition, fromUser, loadingMore)
pagination = args.toPagination()
}
} }
} }

View File

@ -24,7 +24,6 @@ import android.os.Bundle
import android.support.v4.content.Loader import android.support.v4.content.Loader
import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.fragment.AbsMediaStatusesFragment import org.mariotaku.twidere.fragment.AbsMediaStatusesFragment
import org.mariotaku.twidere.fragment.ParcelableStatusesFragment.Companion.toPagination
import org.mariotaku.twidere.loader.statuses.MediaStatusesSearchLoader import org.mariotaku.twidere.loader.statuses.MediaStatusesSearchLoader
import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.ParcelableStatus
import org.mariotaku.twidere.util.Utils import org.mariotaku.twidere.util.Utils
@ -43,9 +42,7 @@ class MediaStatusesSearchFragment : AbsMediaStatusesFragment() {
val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true) val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return MediaStatusesSearchLoader(activity, accountKey, query, adapter.getData(), null, tabPosition, return MediaStatusesSearchLoader(activity, accountKey, query, adapter.getData(), null, tabPosition,
fromUser, makeGap, loadingMore).apply { fromUser, makeGap, loadingMore)
pagination = args.toPagination()
}
} }
override fun getStatuses(maxId: String?, sinceId: String?): Int { override fun getStatuses(maxId: String?, sinceId: String?): Int {

View File

@ -58,8 +58,6 @@ class NetworkPublicTimelineFragment : ParcelableStatusesFragment() {
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return NetworkPublicTimelineLoader(context, accountKey, data, savedStatusesFileArgs, return NetworkPublicTimelineLoader(context, accountKey, data, savedStatusesFileArgs,
tabPosition, fromUser, loadingMore).apply { tabPosition, fromUser, loadingMore)
pagination = args.toPagination()
}
} }
} }

View File

@ -58,8 +58,6 @@ class PublicTimelineFragment : ParcelableStatusesFragment() {
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return PublicTimelineLoader(context, accountKey, data, savedStatusesFileArgs, tabPosition, return PublicTimelineLoader(context, accountKey, data, savedStatusesFileArgs, tabPosition,
fromUser, loadingMore).apply { fromUser, loadingMore)
pagination = args.toPagination()
}
} }
} }

View File

@ -74,9 +74,7 @@ open class StatusesSearchFragment : ParcelableStatusesFragment() {
val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true) val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return TweetSearchLoader(activity, accountKey, query, adapterData, savedStatusesFileArgs, tabPosition, fromUser, return TweetSearchLoader(activity, accountKey, query, adapterData, savedStatusesFileArgs, tabPosition, fromUser,
makeGap, loadingMore).apply { makeGap, loadingMore)
pagination = args.toPagination()
}
} }
override fun fitSystemWindows(insets: Rect) { override fun fitSystemWindows(insets: Rect) {

View File

@ -80,10 +80,8 @@ class UserFavoritesFragment : ParcelableStatusesFragment() {
val screenName = args.getString(EXTRA_SCREEN_NAME) val screenName = args.getString(EXTRA_SCREEN_NAME)
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return UserFavoritesLoader(context, accountKey, userKey, screenName, adapterData, savedStatusesFileArgs, return UserFavoritesLoader(context, accountKey, userKey, screenName, adapterData,
tabPosition, fromUser, loadingMore).apply { savedStatusesFileArgs, tabPosition, fromUser, loadingMore)
pagination = args.toPagination()
}
} }
override fun notifyFavoriteTask(event: FavoriteTaskEvent) { override fun notifyFavoriteTask(event: FavoriteTaskEvent) {

View File

@ -98,10 +98,8 @@ class UserListTimelineFragment : ParcelableStatusesFragment() {
val screenName = args.getString(EXTRA_SCREEN_NAME) val screenName = args.getString(EXTRA_SCREEN_NAME)
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return UserListTimelineLoader(activity, accountKey, listId, userKey, screenName, return UserListTimelineLoader(activity, accountKey, listId, userKey, screenName, listName,
listName, adapterData, savedStatusesFileArgs, tabPosition, fromUser, loadingMore).apply { adapterData, savedStatusesFileArgs, tabPosition, fromUser, loadingMore)
pagination = args.toPagination()
}
} }
} }

View File

@ -24,7 +24,6 @@ import android.os.Bundle
import android.support.v4.content.Loader import android.support.v4.content.Loader
import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.IntentConstants.*
import org.mariotaku.twidere.fragment.AbsMediaStatusesFragment import org.mariotaku.twidere.fragment.AbsMediaStatusesFragment
import org.mariotaku.twidere.fragment.ParcelableStatusesFragment.Companion.toPagination
import org.mariotaku.twidere.loader.statuses.MediaTimelineLoader import org.mariotaku.twidere.loader.statuses.MediaTimelineLoader
import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.ParcelableStatus
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
@ -41,10 +40,8 @@ class UserMediaTimelineFragment : AbsMediaStatusesFragment() {
val screenName = args.getString(EXTRA_SCREEN_NAME) val screenName = args.getString(EXTRA_SCREEN_NAME)
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return MediaTimelineLoader(context, accountKey, userKey, screenName, adapter.getData(), null, return MediaTimelineLoader(context, accountKey, userKey, screenName, adapter.getData(),
tabPosition, fromUser, loadingMore).apply { null, tabPosition, fromUser, loadingMore)
pagination = args.toPagination()
}
} }

View File

@ -50,10 +50,8 @@ class UserMentionsFragment : StatusesSearchFragment() {
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1) val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true) val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true)
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false) val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return UserMentionsLoader(activity, accountKey, screenName, adapterData, savedStatusesFileArgs, return UserMentionsLoader(activity, accountKey, screenName, adapterData,
tabPosition, fromUser, makeGap, loadingMore).apply { savedStatusesFileArgs, tabPosition, fromUser, makeGap, loadingMore)
pagination = args.toPagination()
}
} }
} }

View File

@ -113,9 +113,7 @@ class UserTimelineFragment : ParcelableStatusesFragment() {
val pinnedIds = if (adapter.hasPinnedStatuses) null else pinnedStatusIds val pinnedIds = if (adapter.hasPinnedStatuses) null else pinnedStatusIds
return UserTimelineLoader(context, accountKey, userKey, screenName, profileUrl, data, return UserTimelineLoader(context, accountKey, userKey, screenName, profileUrl, data,
savedStatusesFileArgs, tabPosition, fromUser, loadingMore, pinnedIds, savedStatusesFileArgs, tabPosition, fromUser, loadingMore, pinnedIds,
timelineFilter as? UserTimelineFilter).apply { timelineFilter as? UserTimelineFilter)
pagination = args.toPagination()
}
} }
override fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) { override fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) {

View File

@ -43,8 +43,6 @@ import java.util.*
class ConversationLoader( class ConversationLoader(
context: Context, context: Context,
status: ParcelableStatus, status: ParcelableStatus,
val sinceSortId: Long,
val maxSortId: Long,
adapterData: List<ParcelableStatus>?, adapterData: List<ParcelableStatus>?,
fromUser: Boolean, fromUser: Boolean,
loadingMore: Boolean loadingMore: Boolean
@ -100,6 +98,8 @@ class ConversationLoader(
val pagination = this.pagination as? SinceMaxPagination val pagination = this.pagination as? SinceMaxPagination
val maxId = pagination?.maxId val maxId = pagination?.maxId
val sinceId = pagination?.sinceId val sinceId = pagination?.sinceId
val maxSortId = pagination?.maxSortId ?: -1
val sinceSortId = pagination?.sinceSortId ?: -1
val noSinceMaxId = maxId == null && sinceId == null val noSinceMaxId = maxId == null && sinceId == null
// Load conversations // Load conversations
if (maxId != null && maxSortId < status.sort_id || noSinceMaxId) { if (maxId != null && maxSortId < status.sort_id || noSinceMaxId) {

View File

@ -1,16 +1,15 @@
package org.mariotaku.twidere.model package org.mariotaku.twidere.model
import org.mariotaku.twidere.model.pagination.Pagination
/** /**
* Created by mariotaku on 16/2/11. * Created by mariotaku on 16/2/11.
*/ */
open class BaseRefreshTaskParam( open class BaseRefreshTaskParam(
override val accountKeys: Array<UserKey>, override val accountKeys: Array<UserKey>,
override val maxIds: Array<String?>?, override val pagination: Array<out Pagination?>?
override val sinceIds: Array<String?>?,
override val cursors: Array<String?>? = null,
override val maxSortIds: LongArray? = null,
override val sinceSortIds: LongArray? = null
) : RefreshTaskParam { ) : RefreshTaskParam {
override var extraId: Long = -1L override var extraId: Long = -1L
override var isLoadingMore: Boolean = false override var isLoadingMore: Boolean = false
override var shouldAbort: Boolean = false override var shouldAbort: Boolean = false

View File

@ -1,34 +1,19 @@
package org.mariotaku.twidere.model package org.mariotaku.twidere.model
import org.mariotaku.twidere.model.pagination.Pagination
/** /**
* Created by mariotaku on 16/2/14. * Created by mariotaku on 16/2/14.
*/ */
interface RefreshTaskParam { interface RefreshTaskParam {
val accountKeys: Array<UserKey> val accountKeys: Array<UserKey>
val maxIds: Array<String?>? val pagination: Array<out Pagination?>? get() = null
val sinceIds: Array<String?>? val extraId: Long get() = -1
val cursors: Array<String?>? val isLoadingMore: Boolean get() = false
val maxSortIds: LongArray? val shouldAbort: Boolean get() = false
val sinceSortIds: LongArray?
val hasMaxIds: Boolean
get() = maxIds != null
val hasSinceIds: Boolean
get() = sinceIds != null
val hasCursors: Boolean
get() = cursors != null
val extraId: Long
val isLoadingMore: Boolean
val shouldAbort: Boolean
} }

View File

@ -1,33 +1,17 @@
package org.mariotaku.twidere.model package org.mariotaku.twidere.model
import org.mariotaku.twidere.model.pagination.Pagination
/** /**
* Created by mariotaku on 16/2/14. * Created by mariotaku on 16/2/14.
*/ */
abstract class SimpleRefreshTaskParam : RefreshTaskParam { abstract class SimpleRefreshTaskParam : RefreshTaskParam {
internal var cached: Array<UserKey>? = null override val pagination: Array<out Pagination?>? = null
override val maxIds: Array<String?>? override val extraId: Long = -1
get() = null
override val sinceIds: Array<String?>? override val isLoadingMore: Boolean = false
get() = null
override val cursors: Array<String?>? override val shouldAbort: Boolean = false
get() = null
override val sinceSortIds: LongArray?
get() = null
override val maxSortIds: LongArray?
get() = null
override val extraId: Long
get() = -1
override val isLoadingMore: Boolean
get() = false
override val shouldAbort: Boolean
get() = false
} }

View File

@ -17,6 +17,7 @@ import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
import org.mariotaku.ktextension.removeOnAccountsUpdatedListenerSafe import org.mariotaku.ktextension.removeOnAccountsUpdatedListenerSafe
import org.mariotaku.ktextension.toLongOr import org.mariotaku.ktextension.toLongOr
import org.mariotaku.ktextension.toNulls
import org.mariotaku.library.objectcursor.ObjectCursor import org.mariotaku.library.objectcursor.ObjectCursor
import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.twitter.TwitterUserStream import org.mariotaku.microblog.library.twitter.TwitterUserStream
@ -33,6 +34,7 @@ import org.mariotaku.twidere.constant.streamingPowerSavingKey
import org.mariotaku.twidere.extension.model.* import org.mariotaku.twidere.extension.model.*
import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.model.util.ParcelableActivityUtils import org.mariotaku.twidere.model.util.ParcelableActivityUtils
import org.mariotaku.twidere.model.util.UserKeyUtils import org.mariotaku.twidere.model.util.UserKeyUtils
@ -420,18 +422,19 @@ class StreamingService : BaseService() {
@UiThread @UiThread
private fun getInteractions() { private fun getInteractions() {
val task = GetActivitiesAboutMeTask(context) val task = GetActivitiesAboutMeTask(context)
task.params = object : SimpleRefreshTaskParam() { task.params = object : RefreshTaskParam {
override val accountKeys: Array<UserKey> = arrayOf(account.key) override val accountKeys: Array<UserKey> = arrayOf(account.key)
override val sinceIds: Array<String?>? override val pagination by lazy {
get() = DataStoreUtils.getNewestActivityMaxPositions(context, val keys = accountKeys.toNulls()
Activities.AboutMe.CONTENT_URI, arrayOf(account.key), null, null) val sinceIds = DataStoreUtils.getRefreshNewestActivityMaxPositions(context,
Activities.AboutMe.CONTENT_URI, keys)
override val sinceSortIds: LongArray? val sinceSortIds = DataStoreUtils.getRefreshNewestActivityMaxSortPositions(context,
get() = DataStoreUtils.getNewestActivityMaxSortPositions(context, Activities.AboutMe.CONTENT_URI, keys)
Activities.AboutMe.CONTENT_URI, arrayOf(account.key), null, null) return@lazy Array(keys.size) { idx ->
SinceMaxPagination.sinceId(sinceIds[idx], sinceSortIds[idx])
override val hasSinceIds: Boolean = true }
}
} }
TaskStarter.execute(task) TaskStarter.execute(task)
@ -442,8 +445,6 @@ class StreamingService : BaseService() {
val task = GetMessagesTask(context) val task = GetMessagesTask(context)
task.params = object : GetMessagesTask.RefreshMessagesTaskParam(context) { task.params = object : GetMessagesTask.RefreshMessagesTaskParam(context) {
override val accountKeys: Array<UserKey> = arrayOf(account.key) override val accountKeys: Array<UserKey> = arrayOf(account.key)
override val hasSinceIds: Boolean = true
} }
TaskStarter.execute(task) TaskStarter.execute(task)
} }

View File

@ -17,9 +17,13 @@ import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.LOGTAG import org.mariotaku.twidere.TwidereConstants.LOGTAG
import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY_CHANGE import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY_CHANGE
import org.mariotaku.twidere.constant.loadItemLimitKey import org.mariotaku.twidere.constant.loadItemLimitKey
import org.mariotaku.twidere.extension.model.getMaxId
import org.mariotaku.twidere.extension.model.getMaxSortId
import org.mariotaku.twidere.extension.model.getSinceId
import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.newMicroBlogInstance
import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.RefreshTaskParam import org.mariotaku.twidere.model.RefreshTaskParam
import org.mariotaku.twidere.model.TwitterListResponse
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.event.GetActivitiesTaskEvent import org.mariotaku.twidere.model.event.GetActivitiesTaskEvent
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
@ -27,7 +31,6 @@ import org.mariotaku.twidere.model.util.ParcelableActivityUtils
import org.mariotaku.twidere.provider.TwidereDataStore.Activities import org.mariotaku.twidere.provider.TwidereDataStore.Activities
import org.mariotaku.twidere.task.BaseAbstractTask import org.mariotaku.twidere.task.BaseAbstractTask
import org.mariotaku.twidere.util.* import org.mariotaku.twidere.util.*
import org.mariotaku.twidere.model.TwitterListResponse
import org.mariotaku.twidere.util.content.ContentResolverUtils import org.mariotaku.twidere.util.content.ContentResolverUtils
import java.util.* import java.util.*
@ -47,9 +50,6 @@ abstract class GetActivitiesTask(
override fun doLongOperation(param: RefreshTaskParam): List<TwitterListResponse<Activity>> { override fun doLongOperation(param: RefreshTaskParam): List<TwitterListResponse<Activity>> {
if (param.shouldAbort) return emptyList() if (param.shouldAbort) return emptyList()
val accountKeys = param.accountKeys val accountKeys = param.accountKeys
val maxIds = param.maxIds
val maxSortIds = param.maxSortIds
val sinceIds = param.sinceIds
val cr = context.contentResolver val cr = context.contentResolver
val result = ArrayList<TwitterListResponse<Activity>>() val result = ArrayList<TwitterListResponse<Activity>>()
val loadItemLimit = preferences[loadItemLimitKey] val loadItemLimit = preferences[loadItemLimitKey]
@ -61,28 +61,19 @@ abstract class GetActivitiesTask(
val microBlog = credentials.newMicroBlogInstance(context = context, cls = MicroBlog::class.java) val microBlog = credentials.newMicroBlogInstance(context = context, cls = MicroBlog::class.java)
val paging = Paging() val paging = Paging()
paging.count(loadItemLimit) paging.count(loadItemLimit)
var maxId: String? = null val maxId = param.getMaxId(i)
var maxSortId: Long = -1 val maxSortId = param.getMaxSortId(i)
if (maxIds != null) {
maxId = maxIds[i]
if (maxSortIds != null) {
maxSortId = maxSortIds[i]
}
if (maxId != null) { if (maxId != null) {
paging.maxId(maxId) paging.maxId(maxId)
} }
} val sinceId = param.getSinceId(i)
var sinceId: String? = null
if (sinceIds != null) {
sinceId = sinceIds[i]
if (sinceId != null) { if (sinceId != null) {
paging.sinceId(sinceId) paging.sinceId(sinceId)
if (maxIds == null || maxId == null) { if (maxId == null) {
paging.setLatestResults(true) paging.setLatestResults(true)
saveReadPosition[i] = true saveReadPosition[i] = true
} }
} }
}
// We should delete old activities has intersection with new items // We should delete old activities has intersection with new items
try { try {
val activities = getActivities(microBlog, credentials, paging) val activities = getActivities(microBlog, credentials, paging)

View File

@ -19,8 +19,8 @@ import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.LOGTAG import org.mariotaku.twidere.TwidereConstants.LOGTAG
import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY_CHANGE import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY_CHANGE
import org.mariotaku.twidere.constant.loadItemLimitKey import org.mariotaku.twidere.constant.loadItemLimitKey
import org.mariotaku.twidere.extension.model.*
import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.event.GetStatusesTaskEvent import org.mariotaku.twidere.model.event.GetStatusesTaskEvent
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
@ -52,10 +52,6 @@ abstract class GetStatusesTask(
override fun doLongOperation(param: RefreshTaskParam): List<StatusListResponse> { override fun doLongOperation(param: RefreshTaskParam): List<StatusListResponse> {
if (param.shouldAbort) return emptyList() if (param.shouldAbort) return emptyList()
val accountKeys = param.accountKeys val accountKeys = param.accountKeys
val maxIds = param.maxIds
val sinceIds = param.sinceIds
val maxSortIds = param.maxSortIds
val sinceSortIds = param.sinceSortIds
val result = ArrayList<StatusListResponse>() val result = ArrayList<StatusListResponse>()
val loadItemLimit = preferences[loadItemLimitKey] val loadItemLimit = preferences[loadItemLimitKey]
var saveReadPosition = false var saveReadPosition = false
@ -67,22 +63,14 @@ abstract class GetStatusesTask(
try { try {
val paging = Paging() val paging = Paging()
paging.count(loadItemLimit) paging.count(loadItemLimit)
val maxId: String? val maxId = param.getMaxId(i)
val sinceId: String? val sinceId = param.getSinceId(i)
var maxSortId: Long = -1 val maxSortId = param.getMaxSortId(i)
var sinceSortId: Long = -1 val sinceSortId = param.getSinceSortId(i)
if (maxIds != null && maxIds[i] != null) { if (maxId != null) {
maxId = maxIds[i]
paging.maxId(maxId) paging.maxId(maxId)
if (maxSortIds != null) {
maxSortId = maxSortIds[i]
} }
} else { if (sinceId != null) {
maxSortId = -1
maxId = null
}
if (sinceIds != null && sinceIds[i] != null) {
sinceId = sinceIds[i]
val sinceIdLong = sinceId.toLongOr(-1L) val sinceIdLong = sinceId.toLongOr(-1L)
//TODO handle non-twitter case //TODO handle non-twitter case
if (sinceIdLong != -1L) { if (sinceIdLong != -1L) {
@ -90,15 +78,11 @@ abstract class GetStatusesTask(
} else { } else {
paging.sinceId(sinceId) paging.sinceId(sinceId)
} }
if (sinceSortIds != null) {
sinceSortId = sinceSortIds[i] if (maxId == null) {
}
if (maxIds == null) {
paging.setLatestResults(true) paging.setLatestResults(true)
} }
saveReadPosition = true saveReadPosition = true
} else {
sinceId = null
} }
val statuses = getStatuses(microBlog, paging) val statuses = getStatuses(microBlog, paging)
val storeResult = storeStatus(accountKey, details, statuses, sinceId, maxId, val storeResult = storeStatus(accountKey, details, statuses, sinceId, maxId,

View File

@ -39,16 +39,17 @@ import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_SHOW_NOTIFICATION
import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.model.* import org.mariotaku.twidere.extension.model.*
import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable
import org.mariotaku.twidere.extension.model.api.toParcelable
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.ParcelableMessageConversation.ConversationType import org.mariotaku.twidere.model.ParcelableMessageConversation.ConversationType
import org.mariotaku.twidere.model.event.GetMessagesTaskEvent import org.mariotaku.twidere.model.event.GetMessagesTaskEvent
import org.mariotaku.twidere.model.message.conversation.DefaultConversationExtras import org.mariotaku.twidere.model.message.conversation.DefaultConversationExtras
import org.mariotaku.twidere.model.message.conversation.TwitterOfficialConversationExtras import org.mariotaku.twidere.model.message.conversation.TwitterOfficialConversationExtras
import org.mariotaku.twidere.model.pagination.CursorPagination
import org.mariotaku.twidere.model.pagination.Pagination
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.model.util.AccountUtils.getAccountDetails import org.mariotaku.twidere.model.util.AccountUtils.getAccountDetails
import org.mariotaku.twidere.model.util.ParcelableMessageUtils import org.mariotaku.twidere.model.util.ParcelableMessageUtils
import org.mariotaku.twidere.model.util.ParcelableUserUtils
import org.mariotaku.twidere.provider.TwidereDataStore.Messages import org.mariotaku.twidere.provider.TwidereDataStore.Messages
import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations
import org.mariotaku.twidere.task.BaseAbstractTask import org.mariotaku.twidere.task.BaseAbstractTask
@ -130,9 +131,10 @@ class GetMessagesTask(
private fun getDefaultMessages(microBlog: MicroBlog, details: AccountDetails, private fun getDefaultMessages(microBlog: MicroBlog, details: AccountDetails,
param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData {
val accountKey = details.key val accountKey = details.key
val accountsCount = param.accountKeys.size
val sinceIds = if (param.hasSinceIds) param.sinceIds else null val receivedPagination = param.pagination?.get(index) as? SinceMaxPagination
val maxIds = if (param.hasMaxIds) param.maxIds else null val sincePagination = param.pagination?.get(accountsCount + index) as? SinceMaxPagination
val firstFetch by lazy { val firstFetch by lazy {
val firstFetchPref = preferences.getBoolean(KEY_FIRST_FETCH, true) val firstFetchPref = preferences.getBoolean(KEY_FIRST_FETCH, true)
@ -142,12 +144,14 @@ class GetMessagesTask(
return@lazy noConversationsBefore && firstFetchPref return@lazy noConversationsBefore && firstFetchPref
} }
val updateLastRead = maxIds != null || firstFetch val updateLastRead = param.pagination?.all {
(it as? SinceMaxPagination)?.maxId != null
} ?: false || firstFetch
val received = microBlog.getDirectMessages(Paging().apply { val received = microBlog.getDirectMessages(Paging().apply {
count(100) count(100)
val maxId = maxIds?.get(index) val maxId = receivedPagination?.maxId
val sinceId = sinceIds?.get(index) val sinceId = receivedPagination?.sinceId
if (maxId != null) { if (maxId != null) {
maxId(maxId) maxId(maxId)
} }
@ -157,9 +161,8 @@ class GetMessagesTask(
}) })
val sent = microBlog.getSentDirectMessages(Paging().apply { val sent = microBlog.getSentDirectMessages(Paging().apply {
count(100) count(100)
val accountsCount = param.accountKeys.size val maxId = sincePagination?.maxId
val maxId = maxIds?.get(accountsCount + index) val sinceId = sincePagination?.sinceId
val sinceId = sinceIds?.get(accountsCount + index)
if (maxId != null) { if (maxId != null) {
maxId(maxId) maxId(maxId)
} }
@ -201,7 +204,8 @@ class GetMessagesTask(
private fun getTwitterOfficialConversation(microBlog: MicroBlog, details: AccountDetails, private fun getTwitterOfficialConversation(microBlog: MicroBlog, details: AccountDetails,
conversationId: String, param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { conversationId: String, param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData {
val maxId = param.maxIds?.get(index) ?: return DatabaseUpdateData(emptyList(), emptyList()) val maxId = (param.pagination?.get(index) as? SinceMaxPagination)?.maxId
?: return DatabaseUpdateData(emptyList(), emptyList())
val paging = Paging().apply { val paging = Paging().apply {
maxId(maxId) maxId(maxId)
} }
@ -212,8 +216,8 @@ class GetMessagesTask(
private fun getTwitterOfficialUserInbox(microBlog: MicroBlog, details: AccountDetails, private fun getTwitterOfficialUserInbox(microBlog: MicroBlog, details: AccountDetails,
param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData {
val maxId = if (param.hasMaxIds) param.maxIds?.get(index) else null val maxId = (param.pagination?.get(index) as? SinceMaxPagination)?.maxId
val cursor = if (param.hasCursors) param.cursors?.get(index) else null val cursor = (param.pagination?.get(index) as? CursorPagination)?.cursor
val response = if (cursor != null) { val response = if (cursor != null) {
microBlog.getUserUpdates(cursor).userEvents microBlog.getUserUpdates(cursor).userEvents
} else { } else {
@ -231,7 +235,7 @@ class GetMessagesTask(
param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData { param: RefreshMessagesTaskParam, index: Int): DatabaseUpdateData {
val accountKey = details.key val accountKey = details.key
val accountType = details.type val accountType = details.type
val cursor = param.cursors?.get(index) val cursor = (param.pagination?.get(index) as? CursorPagination)?.cursor
val page = cursor?.substringAfter("page:").toIntOr(-1) val page = cursor?.substringAfter("page:").toIntOr(-1)
val result = microBlog.getConversationList(Paging().apply { val result = microBlog.getConversationList(Paging().apply {
count(60) count(60)
@ -272,36 +276,33 @@ class GetMessagesTask(
override val showNotification: Boolean = true override val showNotification: Boolean = true
override val sinceIds: Array<String?>? override val pagination by lazy {
get() { val result = arrayOfNulls<Pagination>(accounts.size * 2)
val incomingIds = DataStoreUtils.getNewestMessageIds(context, Messages.CONTENT_URI, val incomingIds = DataStoreUtils.getNewestMessageIds(context, Messages.CONTENT_URI,
defaultKeys, false) defaultKeys, false)
val outgoingIds = DataStoreUtils.getNewestMessageIds(context, Messages.CONTENT_URI, val outgoingIds = DataStoreUtils.getNewestMessageIds(context, Messages.CONTENT_URI,
defaultKeys, true) defaultKeys, true)
return incomingIds + outgoingIds val cursors = DataStoreUtils.getNewestConversations(context, Conversations.CONTENT_URI,
twitterOfficialKeys).mapToArray { it?.request_cursor }
accounts.forEachIndexed { index, details ->
if (details == null) return@forEachIndexed
if (details.isOfficial(context)) {
result[index] = CursorPagination.valueOf(cursors[index])
} else {
result[index] = SinceMaxPagination.sinceId(incomingIds[index], -1)
result[accounts.size + index] = SinceMaxPagination.sinceId(outgoingIds[index], -1)
}
}
return@lazy result
} }
override val cursors: Array<String?>?
get() {
val cursors = arrayOfNulls<String>(defaultKeys.size)
val newestConversations = DataStoreUtils.getNewestConversations(context,
Conversations.CONTENT_URI, twitterOfficialKeys)
newestConversations.forEachIndexed { i, conversation ->
cursors[i] = conversation?.request_cursor
}
return cursors
}
override val hasSinceIds: Boolean = true
override val hasMaxIds: Boolean = false
override val hasCursors: Boolean = true
} }
abstract class LoadMoreEntriesTaskParam( abstract class LoadMoreEntriesTaskParam(
context: Context context: Context
) : RefreshMessagesTaskParam(context) { ) : RefreshMessagesTaskParam(context) {
override val maxIds: Array<String?>? by lazy { override val pagination: Array<out Pagination?>? by lazy {
val incomingIds = DataStoreUtils.getOldestMessageIds(context, Messages.CONTENT_URI, val incomingIds = DataStoreUtils.getOldestMessageIds(context, Messages.CONTENT_URI,
defaultKeys, false) defaultKeys, false)
val outgoingIds = DataStoreUtils.getOldestMessageIds(context, Messages.CONTENT_URI, val outgoingIds = DataStoreUtils.getOldestMessageIds(context, Messages.CONTENT_URI,
@ -312,11 +313,10 @@ class GetMessagesTask(
val extras = conversation?.conversation_extras as? TwitterOfficialConversationExtras ?: return@forEachIndexed val extras = conversation?.conversation_extras as? TwitterOfficialConversationExtras ?: return@forEachIndexed
incomingIds[i] = extras.maxEntryId incomingIds[i] = extras.maxEntryId
} }
return@lazy incomingIds + outgoingIds return@lazy (incomingIds + outgoingIds).mapToArray { maxId ->
SinceMaxPagination.maxId(maxId, -1)
}
} }
override val hasSinceIds: Boolean = false
override val hasMaxIds: Boolean = true
} }
class LoadMoreMessageTaskParam( class LoadMoreMessageTaskParam(
@ -325,14 +325,13 @@ class GetMessagesTask(
override val conversationId: String, override val conversationId: String,
maxId: String maxId: String
) : RefreshMessagesTaskParam(context) { ) : RefreshMessagesTaskParam(context) {
override val accountKeys: Array<UserKey> = arrayOf(accountKey) override val accountKeys = arrayOf(accountKey)
override val maxIds: Array<String?>? = arrayOf(maxId) override val pagination = arrayOf(SinceMaxPagination.maxId(maxId, -1))
override val hasMaxIds: Boolean = true
} }
abstract class RefreshMessagesTaskParam( abstract class RefreshMessagesTaskParam(
val context: Context val context: Context
) : SimpleRefreshTaskParam() { ) : RefreshTaskParam {
/** /**
* If `conversationId` has value, load messages in conversationId * If `conversationId` has value, load messages in conversationId

View File

@ -46,6 +46,7 @@ import org.mariotaku.twidere.extension.model.api.microblog.toParcelable
import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.newMicroBlogInstance
import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.event.* import org.mariotaku.twidere.model.event.*
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils
import org.mariotaku.twidere.provider.TwidereDataStore.* import org.mariotaku.twidere.provider.TwidereDataStore.*
@ -272,28 +273,33 @@ class AsyncTwitterWrapper(
} }
fun refreshAll(action: () -> Array<UserKey>): Boolean { fun refreshAll(action: () -> Array<UserKey>): Boolean {
getHomeTimelineAsync(object : SimpleRefreshTaskParam() { getHomeTimelineAsync(object : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { action() } override val accountKeys by lazy { action() }
override val sinceIds: Array<String?>? by lazy { override val pagination by lazy {
DataStoreUtils.getNewestStatusIds(context, Statuses.CONTENT_URI, return@lazy DataStoreUtils.getNewestStatusIds(context, Statuses.CONTENT_URI,
accountKeys.toNulls()) accountKeys.toNulls()).mapToArray {
return@mapToArray SinceMaxPagination.sinceId(it, -1)
}
} }
}) })
if (preferences[homeRefreshMentionsKey]) { if (preferences[homeRefreshMentionsKey]) {
getActivitiesAboutMeAsync(object : SimpleRefreshTaskParam() { getActivitiesAboutMeAsync(object : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { action() }
override val sinceIds: Array<String?>? by lazy { override val accountKeys by lazy { action() }
DataStoreUtils.getRefreshNewestActivityMaxPositions(context,
Activities.AboutMe.CONTENT_URI, accountKeys.toNulls()) override val pagination by lazy {
return@lazy DataStoreUtils.getRefreshNewestActivityMaxPositions(context,
Activities.AboutMe.CONTENT_URI, accountKeys.toNulls()).mapToArray {
return@mapToArray SinceMaxPagination.sinceId(it, -1)
}
} }
}) })
} }
if (preferences[homeRefreshDirectMessagesKey]) { if (preferences[homeRefreshDirectMessagesKey]) {
getMessagesAsync(object : GetMessagesTask.RefreshMessagesTaskParam(context) { getMessagesAsync(object : GetMessagesTask.RefreshMessagesTaskParam(context) {
override val accountKeys: Array<UserKey> by lazy { action() } override val accountKeys by lazy { action() }
}) })
} }
if (preferences[homeRefreshSavedSearchesKey]) { if (preferences[homeRefreshSavedSearchesKey]) {

View File

@ -15,8 +15,10 @@ import org.mariotaku.twidere.constant.IntentConstants.INTENT_PACKAGE_PREFIX
import org.mariotaku.twidere.constant.dataSyncProviderInfoKey import org.mariotaku.twidere.constant.dataSyncProviderInfoKey
import org.mariotaku.twidere.constant.stopAutoRefreshWhenBatteryLowKey import org.mariotaku.twidere.constant.stopAutoRefreshWhenBatteryLowKey
import org.mariotaku.twidere.model.AccountPreferences import org.mariotaku.twidere.model.AccountPreferences
import org.mariotaku.twidere.model.SimpleRefreshTaskParam import org.mariotaku.twidere.model.RefreshTaskParam
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.pagination.Pagination
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
import org.mariotaku.twidere.provider.TwidereDataStore.Activities import org.mariotaku.twidere.provider.TwidereDataStore.Activities
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
import org.mariotaku.twidere.task.filter.RefreshFiltersSubscriptionsTask import org.mariotaku.twidere.task.filter.RefreshFiltersSubscriptionsTask
@ -105,7 +107,8 @@ class TaskServiceRunner(
val preferences: SharedPreferences, val preferences: SharedPreferences,
val refreshable: (AccountPreferences) -> Boolean, val refreshable: (AccountPreferences) -> Boolean,
val getSinceIds: (Array<UserKey>) -> Array<String?>? val getSinceIds: (Array<UserKey>) -> Array<String?>?
) : SimpleRefreshTaskParam() { ) : RefreshTaskParam {
override val accountKeys: Array<UserKey> by lazy { override val accountKeys: Array<UserKey> by lazy {
return@lazy AccountPreferences.getAccountPreferences(context, preferences, return@lazy AccountPreferences.getAccountPreferences(context, preferences,
DataStoreUtils.getAccountKeys(context)).filter { DataStoreUtils.getAccountKeys(context)).filter {
@ -113,8 +116,10 @@ class TaskServiceRunner(
}.mapToArray(AccountPreferences::accountKey) }.mapToArray(AccountPreferences::accountKey)
} }
override val sinceIds: Array<String?>? override val pagination: Array<Pagination?>?
get() = getSinceIds(accountKeys) get() = getSinceIds(accountKeys)?.mapToArray { sinceId ->
SinceMaxPagination().also { it.sinceId = sinceId }
}
} }