mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-01 09:16:47 +01:00
migrating to cursor based status tabs
This commit is contained in:
parent
8159dce670
commit
405c419c2d
@ -742,6 +742,15 @@ public interface TwidereDataStore {
|
||||
|
||||
String[] TYPES = ParcelableStatusTableInfo.TYPES;
|
||||
|
||||
interface Favorites extends Statuses {
|
||||
|
||||
String CONTENT_PATH = "favorites_timeline";
|
||||
String TABLE_NAME = "favorites_timeline";
|
||||
|
||||
@NonNull
|
||||
Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, CONTENT_PATH);
|
||||
}
|
||||
|
||||
interface Public extends Statuses {
|
||||
|
||||
String CONTENT_PATH = "public_timeline";
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.exception
|
||||
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
|
||||
|
||||
class RequiredFieldNotFoundException(vararg val fields: String) : MicroBlogException("Field ${fields.joinToString(" and ")} required")
|
@ -23,6 +23,8 @@ import android.net.Uri
|
||||
|
||||
fun Uri.withAppendedPath(path: String): Uri = Uri.withAppendedPath(this, path)
|
||||
|
||||
fun Uri.withAppendedPath(path: Long): Uri = this.withAppendedPath(path.toString())
|
||||
|
||||
fun Uri.Builder.appendQueryParameterIgnoreNull(key: String, value: String?) {
|
||||
if (value == null) return
|
||||
appendQueryParameter(key, value)
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.extension.model
|
||||
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
|
||||
fun RefreshTaskParam.getMaxId(index: Int): String? {
|
||||
|
@ -61,6 +61,8 @@ import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.analyzer.Share
|
||||
import org.mariotaku.twidere.model.event.StatusListChangedEvent
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.BaseRefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
import org.mariotaku.twidere.util.*
|
||||
|
@ -54,10 +54,15 @@ import org.mariotaku.twidere.fragment.status.FavoriteConfirmDialogFragment
|
||||
import org.mariotaku.twidere.fragment.status.RetweetQuoteDialogFragment
|
||||
import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable
|
||||
import org.mariotaku.twidere.loader.iface.IExtendedLoader
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.ObjectId
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.analyzer.Share
|
||||
import org.mariotaku.twidere.model.event.StatusListChangedEvent
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.BaseRefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.timeline.TimelineFilter
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
|
@ -44,6 +44,7 @@ import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.event.*
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
|
||||
import org.mariotaku.twidere.task.statuses.GetStatusesTask
|
||||
|
@ -44,10 +44,10 @@ import org.mariotaku.twidere.extension.queryOne
|
||||
import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader
|
||||
import org.mariotaku.twidere.model.ParameterizedExpression
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.*
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.task.statuses.GetStatusesTask
|
||||
@ -55,10 +55,7 @@ import org.mariotaku.twidere.util.DataStoreUtils
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/3.
|
||||
*/
|
||||
abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
||||
abstract class CursorStatusesFragment: AbsStatusesFragment() {
|
||||
|
||||
override var refreshing: Boolean
|
||||
get() = swipeLayout.isRefreshing
|
||||
@ -120,11 +117,10 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
||||
val accountKeys = this.accountKeys
|
||||
val accountWhere = Expression.inArgs(Column(Statuses.ACCOUNT_KEY), accountKeys.size)
|
||||
val filterWhere = getFiltersWhere(table)
|
||||
val where: Expression
|
||||
if (filterWhere != null) {
|
||||
where = Expression.and(accountWhere, filterWhere)
|
||||
val where = if (filterWhere != null) {
|
||||
Expression.and(accountWhere, filterWhere)
|
||||
} else {
|
||||
where = accountWhere
|
||||
accountWhere
|
||||
}
|
||||
adapter.showAccountsColor = accountKeys.size > 1
|
||||
val projection = statusColumnsLite
|
||||
|
@ -25,8 +25,8 @@ import org.mariotaku.twidere.annotation.FilterScope
|
||||
import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
|
||||
import org.mariotaku.twidere.model.ParameterizedExpression
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.tab.extra.HomeTabExtras
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
|
@ -32,7 +32,7 @@ import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
|
||||
import org.mariotaku.twidere.extension.linkHandlerTitle
|
||||
import org.mariotaku.twidere.model.ParameterizedExpression
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.tab.extra.InteractionsTabExtras
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
|
@ -34,9 +34,7 @@ import org.mariotaku.twidere.extension.getErrorMessage
|
||||
import org.mariotaku.twidere.extension.model.getMaxId
|
||||
import org.mariotaku.twidere.loader.iface.IPaginationLoader
|
||||
import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader
|
||||
import org.mariotaku.twidere.model.BaseRefreshTaskParam
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.FavoriteTaskEvent
|
||||
import org.mariotaku.twidere.model.event.StatusDestroyedEvent
|
||||
@ -44,6 +42,8 @@ import org.mariotaku.twidere.model.event.StatusListChangedEvent
|
||||
import org.mariotaku.twidere.model.event.StatusRetweetedEvent
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.BaseRefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
|
||||
@ -61,9 +61,6 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() {
|
||||
super.refreshing = value
|
||||
}
|
||||
|
||||
protected open val savedStatusesFileArgs: Array<String>?
|
||||
get() = null
|
||||
|
||||
|
||||
override val accountKeys: Array<UserKey>
|
||||
get() = Utils.getAccountKeys(context, arguments) ?: emptyArray()
|
||||
|
@ -33,29 +33,11 @@ import org.mariotaku.twidere.fragment.ParcelableStatusesFragment
|
||||
import org.mariotaku.twidere.loader.statuses.GroupTimelineLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/2.
|
||||
*/
|
||||
class GroupTimelineFragment : ParcelableStatusesFragment() {
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val accountKey = Utils.getAccountKey(context, arguments)!!
|
||||
val groupId = arguments.getString(EXTRA_GROUP_ID)
|
||||
val groupName = arguments.getString(EXTRA_GROUP_NAME)
|
||||
val result = ArrayList<String>()
|
||||
result.add(AUTHORITY_GROUP_TIMELINE)
|
||||
result.add("account=$accountKey")
|
||||
if (groupId != null) {
|
||||
result.add("group_id=$groupId")
|
||||
} else if (groupName != null) {
|
||||
result.add("group_name=$groupName")
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
override val readPositionTagWithArguments: String?
|
||||
get() {
|
||||
@ -106,10 +88,9 @@ class GroupTimelineFragment : ParcelableStatusesFragment() {
|
||||
val accountKey = Utils.getAccountKey(context, args)
|
||||
val groupId = args.getString(EXTRA_GROUP_ID)
|
||||
val groupName = args.getString(EXTRA_GROUP_NAME)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return GroupTimelineLoader(activity, accountKey, groupId, groupName, adapterData,
|
||||
savedStatusesFileArgs, tabPosition, fromUser, loadingMore)
|
||||
fromUser, loadingMore)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ class MediaStatusesSearchFragment : AbsMediaStatusesFragment() {
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return MediaStatusesSearchLoader(activity, accountKey, query, adapter.getData(), null, tabPosition,
|
||||
fromUser, makeGap, loadingMore)
|
||||
return MediaStatusesSearchLoader(activity, accountKey, query, adapter.getData(), fromUser, makeGap,
|
||||
loadingMore)
|
||||
}
|
||||
|
||||
override fun getStatuses(maxId: String?, sinceId: String?): Int {
|
||||
|
@ -29,7 +29,7 @@ import org.mariotaku.twidere.constant.IntentConstants
|
||||
import org.mariotaku.twidere.extension.linkHandlerTitle
|
||||
import org.mariotaku.twidere.fragment.CursorStatusesFragment
|
||||
import org.mariotaku.twidere.model.ParameterizedExpression
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.tab.extra.HomeTabExtras
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
|
@ -29,8 +29,8 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_EXTRAS
|
||||
import org.mariotaku.twidere.extension.linkHandlerTitle
|
||||
import org.mariotaku.twidere.fragment.CursorStatusesFragment
|
||||
import org.mariotaku.twidere.model.ParameterizedExpression
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.tab.extra.HomeTabExtras
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.task.statuses.GetPublicTimelineTask
|
||||
|
@ -29,28 +29,12 @@ import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/2.
|
||||
*/
|
||||
open class StatusesSearchFragment : ParcelableStatusesFragment() {
|
||||
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val accountKey = Utils.getAccountKey(context, arguments)
|
||||
val query = arguments.getString(EXTRA_QUERY)
|
||||
val local = arguments.getBoolean(EXTRA_LOCAL)
|
||||
val result = ArrayList<String>()
|
||||
result.add(AUTHORITY_SEARCH_TWEETS)
|
||||
result.add("account=$accountKey")
|
||||
result.add("query=$query")
|
||||
if (local) {
|
||||
result.add("local")
|
||||
}
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
override val readPositionTagWithArguments: String?
|
||||
get() {
|
||||
val tabPosition = arguments.getInt(EXTRA_TAB_POSITION, -1)
|
||||
@ -74,11 +58,10 @@ open class StatusesSearchFragment : ParcelableStatusesFragment() {
|
||||
val accountKey = Utils.getAccountKey(context, args)
|
||||
val query = arguments.getString(EXTRA_QUERY)
|
||||
val local = arguments.getBoolean(EXTRA_LOCAL, false)
|
||||
val tabPosition = arguments.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return TweetSearchLoader(activity, accountKey, query, adapterData, savedStatusesFileArgs,
|
||||
tabPosition, fromUser, makeGap, local, loadingMore)
|
||||
return TweetSearchLoader(activity, accountKey, query, adapterData, fromUser,
|
||||
makeGap, local, loadingMore)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,62 +19,42 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment.statuses
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.Loader
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.TwidereConstants.EXTRA_USER_KEY
|
||||
import org.mariotaku.twidere.annotation.FilterScope
|
||||
import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.constant.iWantMyStarsBackKey
|
||||
import org.mariotaku.twidere.extension.linkHandlerTitle
|
||||
import org.mariotaku.twidere.fragment.ParcelableStatusesFragment
|
||||
import org.mariotaku.twidere.loader.statuses.UserFavoritesLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.extension.withAppendedPath
|
||||
import org.mariotaku.twidere.fragment.CursorStatusesFragment
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.FavoriteTaskEvent
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/2.
|
||||
*/
|
||||
class UserFavoritesFragment : ParcelableStatusesFragment() {
|
||||
class UserFavoritesFragment : CursorStatusesFragment() {
|
||||
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val accountKey = Utils.getAccountKey(context, arguments)
|
||||
val userKey = arguments.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
val screenName = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
val result = ArrayList<String>()
|
||||
result.add(AUTHORITY_USER_FAVORITES)
|
||||
result.add("account=$accountKey")
|
||||
if (userKey != null) {
|
||||
result.add("user_id=$userKey")
|
||||
} else if (screenName != null) {
|
||||
result.add("screen_name=$screenName")
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
return result.toTypedArray()
|
||||
}
|
||||
override val errorInfoKey = ErrorInfoStore.KEY_PUBLIC_TIMELINE
|
||||
|
||||
override val readPositionTagWithArguments: String?
|
||||
get() {
|
||||
val tabPosition = arguments.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val sb = StringBuilder("user_favorites_")
|
||||
if (tabPosition < 0) return null
|
||||
override val contentUri = Statuses.Favorites.CONTENT_URI.withAppendedPath(tabId)
|
||||
|
||||
val userKey = arguments.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
val screenName = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
if (userKey != null) {
|
||||
sb.append(userKey)
|
||||
} else if (screenName != null) {
|
||||
sb.append(screenName)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
override val notificationType = 0
|
||||
|
||||
override val isFilterEnabled = true
|
||||
|
||||
override val readPositionTag = ReadPositionTag.PUBLIC_TIMELINE
|
||||
|
||||
override val timelineSyncTag: String?
|
||||
get() = PublicTimelineFragment.getTimelineSyncTag(accountKeys)
|
||||
|
||||
override val filterScopes: Int
|
||||
get() = FilterScope.PUBLIC_TIMELINE
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
@ -85,31 +65,32 @@ class UserFavoritesFragment : ParcelableStatusesFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateStatusesLoader(context: Context, args: Bundle, fromUser: Boolean):
|
||||
Loader<List<ParcelableStatus>?> {
|
||||
refreshing = true
|
||||
val accountKey = Utils.getAccountKey(context, args)
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return UserFavoritesLoader(context, accountKey, userKey, screenName, adapterData,
|
||||
savedStatusesFileArgs, tabPosition, fromUser, loadingMore)
|
||||
override fun updateRefreshState() {
|
||||
val twitter = twitterWrapper
|
||||
refreshing = twitter.isStatusTimelineRefreshing(contentUri)
|
||||
}
|
||||
|
||||
override fun notifyFavoriteTask(event: FavoriteTaskEvent) {
|
||||
|
||||
override fun getStatuses(param: RefreshTaskParam): Boolean {
|
||||
// val task = GetUserFavoritesTask(context)
|
||||
// task.params = param
|
||||
// TaskStarter.execute(task)
|
||||
return true
|
||||
}
|
||||
|
||||
fun notifyFavoriteTask(event: FavoriteTaskEvent) {
|
||||
if (event.action == FavoriteTaskEvent.Action.DESTROY && event.isSucceeded) {
|
||||
event.status?.let { status ->
|
||||
val args = arguments!!
|
||||
val userKey = args.getParcelable<UserKey>(EXTRA_USER_KEY)
|
||||
if (status.account_key == userKey) {
|
||||
removeStatus(event.statusId)
|
||||
// removeStatus(event.statusId)
|
||||
triggerRefresh()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
super.notifyFavoriteTask(event)
|
||||
// super.notifyFavoriteTask(event)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.Loader
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants
|
||||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.extension.linkHandlerTitle
|
||||
import org.mariotaku.twidere.fragment.ParcelableStatusesFragment
|
||||
@ -31,38 +30,12 @@ import org.mariotaku.twidere.loader.statuses.UserListTimelineLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/2.
|
||||
*/
|
||||
class UserListTimelineFragment : ParcelableStatusesFragment() {
|
||||
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val accountKey = Utils.getAccountKey(context, arguments)
|
||||
val listId = arguments.getString(EXTRA_LIST_ID)
|
||||
val userKey = arguments.getParcelable<UserKey?>(EXTRA_USER_KEY)
|
||||
val screenName = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
val listName = arguments.getString(EXTRA_LIST_NAME)
|
||||
val result = ArrayList<String>()
|
||||
result.add(TwidereConstants.AUTHORITY_USER_LIST_TIMELINE)
|
||||
result.add("account=$accountKey")
|
||||
if (listId != null) {
|
||||
result.add("list_id=$listId")
|
||||
} else if (listName != null) {
|
||||
if (userKey != null) {
|
||||
result.add("user_id=$userKey")
|
||||
} else if (screenName != null) {
|
||||
result.add("screen_name=$screenName")
|
||||
}
|
||||
return null
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
override val readPositionTagWithArguments: String?
|
||||
get() {
|
||||
val tabPosition = arguments.getInt(EXTRA_TAB_POSITION, -1)
|
||||
@ -103,10 +76,9 @@ class UserListTimelineFragment : ParcelableStatusesFragment() {
|
||||
val userKey = args.getParcelable<UserKey?>(EXTRA_USER_KEY)
|
||||
val listName = args.getString(EXTRA_LIST_NAME)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return UserListTimelineLoader(activity, accountKey, listId, userKey, screenName, listName,
|
||||
adapterData, savedStatusesFileArgs, tabPosition, fromUser, loadingMore)
|
||||
adapterData, fromUser, loadingMore)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,9 +30,6 @@ import org.mariotaku.twidere.loader.statuses.MediaTimelineLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/11/5.
|
||||
*/
|
||||
class UserMediaTimelineFragment : AbsMediaStatusesFragment() {
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
@ -45,10 +42,9 @@ class UserMediaTimelineFragment : AbsMediaStatusesFragment() {
|
||||
val accountKey = args.getParcelable<UserKey?>(EXTRA_ACCOUNT_KEY)
|
||||
val userKey = args.getParcelable<UserKey?>(EXTRA_USER_KEY)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return MediaTimelineLoader(context, accountKey, userKey, screenName, adapter.getData(),
|
||||
null, tabPosition, fromUser, loadingMore)
|
||||
fromUser, loadingMore)
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,22 +28,9 @@ import org.mariotaku.twidere.extension.linkHandlerTitle
|
||||
import org.mariotaku.twidere.loader.statuses.UserMentionsLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import java.util.*
|
||||
|
||||
class UserMentionsFragment : StatusesSearchFragment() {
|
||||
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val accountKey = Utils.getAccountKey(context, arguments)
|
||||
val screenName = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
val result = ArrayList<String>()
|
||||
result.add(AUTHORITY_USER_MENTIONS)
|
||||
result.add("account=$accountKey")
|
||||
result.add("screen_name=$screenName")
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
linkHandlerTitle = getString(R.string.user_mentions)
|
||||
@ -54,11 +41,10 @@ class UserMentionsFragment : StatusesSearchFragment() {
|
||||
fromUser: Boolean): Loader<List<ParcelableStatus>?> {
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val accountKey = args.getParcelable<UserKey?>(EXTRA_ACCOUNT_KEY)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val makeGap = args.getBoolean(EXTRA_MAKE_GAP, true)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
return UserMentionsLoader(activity, accountKey, screenName, adapterData,
|
||||
savedStatusesFileArgs, tabPosition, fromUser, makeGap, false, loadingMore)
|
||||
fromUser, makeGap, false, loadingMore)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import org.mariotaku.twidere.model.timeline.TimelineFilter
|
||||
import org.mariotaku.twidere.model.timeline.UserTimelineFilter
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import org.mariotaku.twidere.view.holder.TimelineFilterHeaderViewHolder
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* User timeline
|
||||
@ -52,32 +51,6 @@ import java.util.*
|
||||
*/
|
||||
class UserTimelineFragment : ParcelableStatusesFragment() {
|
||||
|
||||
override val savedStatusesFileArgs: Array<String>?
|
||||
get() {
|
||||
val accountKey = Utils.getAccountKey(context, arguments)
|
||||
val userKey = arguments.getParcelable<UserKey?>(EXTRA_USER_KEY)
|
||||
val screenName = arguments.getString(EXTRA_SCREEN_NAME)
|
||||
val result = ArrayList<String>()
|
||||
result.add(AUTHORITY_USER_TIMELINE)
|
||||
result.add("account=$accountKey")
|
||||
if (userKey != null) {
|
||||
result.add("user_id=$userKey")
|
||||
} else if (screenName != null) {
|
||||
result.add("screen_name=$screenName")
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
(timelineFilter as? UserTimelineFilter)?.let {
|
||||
if (it.isIncludeReplies) {
|
||||
result.add("include_replies")
|
||||
}
|
||||
if (it.isIncludeRetweets) {
|
||||
result.add("include_retweets")
|
||||
}
|
||||
}
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
override val readPositionTagWithArguments: String?
|
||||
get() {
|
||||
if (arguments.getLong(EXTRA_TAB_ID, -1) < 0) return null
|
||||
@ -114,12 +87,10 @@ class UserTimelineFragment : ParcelableStatusesFragment() {
|
||||
val userKey = args.getParcelable<UserKey?>(EXTRA_USER_KEY)
|
||||
val screenName = args.getString(EXTRA_SCREEN_NAME)
|
||||
val profileUrl = args.getString(EXTRA_PROFILE_URL)
|
||||
val tabPosition = args.getInt(EXTRA_TAB_POSITION, -1)
|
||||
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
|
||||
val loadPinnedStatus = args.getBoolean(EXTRA_LOAD_PINNED_STATUS, false)
|
||||
return UserTimelineLoader(context, accountKey, userKey, screenName, profileUrl, data,
|
||||
savedStatusesFileArgs, tabPosition, fromUser, loadingMore, loadPinnedStatus,
|
||||
timelineFilter as? UserTimelineFilter)
|
||||
fromUser, loadingMore, loadPinnedStatus, timelineFilter as? UserTimelineFilter)
|
||||
}
|
||||
|
||||
override fun onStatusesLoaded(loader: Loader<List<ParcelableStatus>?>, data: List<ParcelableStatus>?) {
|
||||
|
@ -28,7 +28,6 @@ import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.constant.loadItemLimitKey
|
||||
import org.mariotaku.twidere.extension.model.api.applyLoadLimit
|
||||
import org.mariotaku.twidere.loader.iface.IPaginationLoader
|
||||
@ -44,9 +43,7 @@ import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.task.statuses.GetStatusesTask
|
||||
import org.mariotaku.twidere.util.DebugLog
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
import org.mariotaku.twidere.util.cache.JsonCache
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponent
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import javax.inject.Inject
|
||||
@ -55,11 +52,9 @@ abstract class AbsRequestStatusesLoader(
|
||||
context: Context,
|
||||
val accountKey: UserKey?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
private val savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
protected val loadingMore: Boolean
|
||||
) : ParcelableStatusesLoader(context, adapterData, tabPosition, fromUser), IPaginationLoader {
|
||||
) : ParcelableStatusesLoader(context, adapterData, fromUser), IPaginationLoader {
|
||||
// Statuses sorted descending by default
|
||||
open val comparator: Comparator<ParcelableStatus>? = ParcelableStatus.REVERSE_COMPARATOR
|
||||
|
||||
@ -79,8 +74,6 @@ abstract class AbsRequestStatusesLoader(
|
||||
|
||||
protected val profileImageSize: String = context.getString(R.string.profile_image_size)
|
||||
|
||||
@Inject
|
||||
lateinit var jsonCache: JsonCache
|
||||
@Inject
|
||||
lateinit var preferences: SharedPreferences
|
||||
@Inject
|
||||
@ -88,15 +81,6 @@ abstract class AbsRequestStatusesLoader(
|
||||
|
||||
private val exceptionRef = AtomicReference<MicroBlogException?>()
|
||||
|
||||
private val cachedData: List<ParcelableStatus>?
|
||||
get() {
|
||||
val key = serializationKey ?: return null
|
||||
return jsonCache.getList(key, ParcelableStatus::class.java)
|
||||
}
|
||||
|
||||
private val serializationKey: String?
|
||||
get() = savedStatusesArgs?.joinToString("_")
|
||||
|
||||
init {
|
||||
GeneralComponent.get(context).inject(this)
|
||||
}
|
||||
@ -109,19 +93,6 @@ abstract class AbsRequestStatusesLoader(
|
||||
val details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
|
||||
|
||||
if (isFirstLoad && tabPosition >= 0) {
|
||||
val cached = cachedData
|
||||
if (cached != null) {
|
||||
data.addAll(cached)
|
||||
if (comparator != null) {
|
||||
data.sortWith(comparator)
|
||||
} else {
|
||||
data.sort()
|
||||
}
|
||||
data.forEach { it.is_filtered = shouldFilterStatus(it) }
|
||||
return ListResponse.getListInstance(data)
|
||||
}
|
||||
}
|
||||
if (!fromUser) {
|
||||
data.forEach { it.is_filtered = shouldFilterStatus(it) }
|
||||
return ListResponse.getListInstance(data)
|
||||
@ -179,7 +150,6 @@ abstract class AbsRequestStatusesLoader(
|
||||
} else {
|
||||
data.sort()
|
||||
}
|
||||
saveCachedData(data)
|
||||
return ListResponse.getListInstance(data)
|
||||
}
|
||||
|
||||
@ -207,22 +177,6 @@ abstract class AbsRequestStatusesLoader(
|
||||
@Throws(MicroBlogException::class)
|
||||
protected abstract fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus>
|
||||
|
||||
private fun saveCachedData(data: List<ParcelableStatus>?) {
|
||||
val key = serializationKey
|
||||
if (key == null || data == null) return
|
||||
val databaseItemLimit = preferences[loadItemLimitKey]
|
||||
try {
|
||||
val statuses = data.subList(0, Math.min(databaseItemLimit, data.size))
|
||||
jsonCache.saveList(key, statuses, ParcelableStatus::class.java)
|
||||
} catch (e: Exception) {
|
||||
// Ignore
|
||||
if (e !is IOException) {
|
||||
DebugLog.w(LOGTAG, "Error saving cached data", e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
inline fun <R> List<Status>.mapMicroBlogToPaginated(transform: (Status) -> R): PaginatedList<R> {
|
||||
val result = mapTo(PaginatedArrayList(size), transform)
|
||||
|
@ -57,7 +57,7 @@ class ConversationLoader(
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, status.account_key, adapterData, null, -1, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, status.account_key, adapterData, fromUser, loadingMore) {
|
||||
|
||||
override val comparator: Comparator<ParcelableStatus>? = null
|
||||
|
||||
|
@ -42,12 +42,9 @@ class GroupTimelineLoader(
|
||||
private val groupId: String?,
|
||||
private val groupName: String?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, savedStatusesArgs, tabPosition,
|
||||
fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
|
@ -44,13 +44,10 @@ open class MediaStatusesSearchLoader(
|
||||
accountKey: UserKey?,
|
||||
private val query: String?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
override val isGapEnabled: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, savedStatusesArgs, tabPosition,
|
||||
fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
|
@ -49,11 +49,9 @@ class MediaTimelineLoader(
|
||||
private val userKey: UserKey?,
|
||||
private val screenName: String?,
|
||||
data: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, data, savedStatusesArgs, tabPosition, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, data, fromUser, loadingMore) {
|
||||
|
||||
private var user: User? = null
|
||||
|
||||
|
@ -42,11 +42,9 @@ class NetworkPublicTimelineLoader(
|
||||
context: Context,
|
||||
accountKey: UserKey?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, savedStatusesArgs, tabPosition, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
|
@ -29,7 +29,6 @@ import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList
|
||||
abstract class ParcelableStatusesLoader(
|
||||
context: Context,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
protected val tabPosition: Int,
|
||||
override var fromUser: Boolean
|
||||
) : FixedAsyncTaskLoader<List<ParcelableStatus>>(context), IExtendedLoader {
|
||||
|
||||
|
@ -41,11 +41,9 @@ class PublicTimelineLoader(
|
||||
context: Context,
|
||||
accountKey: UserKey?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, savedStatusesArgs, tabPosition, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
|
@ -48,14 +48,11 @@ open class TweetSearchLoader(
|
||||
accountKey: UserKey?,
|
||||
private val query: String?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
override val isGapEnabled: Boolean,
|
||||
val local: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, savedStatusesArgs, tabPosition,
|
||||
fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
|
@ -35,21 +35,17 @@ import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.pagination.PaginatedList
|
||||
import org.mariotaku.twidere.model.refresh.UserRelatedRefreshTaskParam
|
||||
import org.mariotaku.twidere.util.database.ContentFiltersUtils
|
||||
|
||||
class UserFavoritesLoader(
|
||||
context: Context,
|
||||
accountKey: UserKey?,
|
||||
private val userKey: UserKey?,
|
||||
private val screenName: String?,
|
||||
private val refreshParam: UserRelatedRefreshTaskParam?,
|
||||
data: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, data, savedStatusesArgs, tabPosition, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, refreshParam?.accountKeys?.singleOrNull(), data, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
@ -71,19 +67,15 @@ class UserFavoritesLoader(
|
||||
|
||||
private fun getMicroBlogStatuses(account: AccountDetails, paging: Paging): ResponseList<Status> {
|
||||
val microBlog = account.newMicroBlogInstance(context, MicroBlog::class.java)
|
||||
if (userKey != null) {
|
||||
return microBlog.getFavorites(userKey.id, paging)
|
||||
} else if (screenName != null) {
|
||||
return microBlog.getFavoritesByScreenName(screenName, paging)
|
||||
return when {
|
||||
refreshParam?.userKey != null -> microBlog.getFavorites(refreshParam.userKey.id, paging)
|
||||
refreshParam?.userScreenName != null -> microBlog.getFavoritesByScreenName(refreshParam.userScreenName, paging)
|
||||
else -> throw MicroBlogException("Null user")
|
||||
}
|
||||
throw MicroBlogException("Null user")
|
||||
}
|
||||
|
||||
private fun getMastodonStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
if (userKey != null && userKey != account.key) {
|
||||
throw MicroBlogException("Only current account favorites is supported")
|
||||
}
|
||||
if (screenName != null && !screenName.equals(account.user?.screen_name, ignoreCase = true)) {
|
||||
if (refreshParam?.userKey != account.key) {
|
||||
throw MicroBlogException("Only current account favorites is supported")
|
||||
}
|
||||
val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java)
|
||||
|
@ -43,11 +43,9 @@ class UserListTimelineLoader(
|
||||
private val screenName: String?,
|
||||
private val listName: String?,
|
||||
adapterData: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, savedStatusesArgs, tabPosition, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, adapterData, fromUser, loadingMore) {
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
|
||||
|
@ -31,14 +31,12 @@ class UserMentionsLoader(
|
||||
accountKey: UserKey?,
|
||||
screenName: String,
|
||||
data: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
makeGap: Boolean,
|
||||
local: Boolean,
|
||||
loadingMore: Boolean
|
||||
) : TweetSearchLoader(context, accountKey, screenName, data, savedStatusesArgs, tabPosition,
|
||||
fromUser, makeGap, local, loadingMore) {
|
||||
) : TweetSearchLoader(context, accountKey, screenName, data, fromUser, makeGap,
|
||||
local, loadingMore) {
|
||||
|
||||
override fun processQuery(details: AccountDetails, query: String): String {
|
||||
val screenName = query.substringAfter("@")
|
||||
|
@ -65,13 +65,11 @@ class UserTimelineLoader(
|
||||
private val screenName: String?,
|
||||
private val profileUrl: String?,
|
||||
data: List<ParcelableStatus>?,
|
||||
savedStatusesArgs: Array<String>?,
|
||||
tabPosition: Int,
|
||||
fromUser: Boolean,
|
||||
loadingMore: Boolean,
|
||||
val loadPinnedStatus: Boolean,
|
||||
val timelineFilter: UserTimelineFilter? = null
|
||||
) : AbsRequestStatusesLoader(context, accountKey, data, savedStatusesArgs, tabPosition, fromUser, loadingMore) {
|
||||
) : AbsRequestStatusesLoader(context, accountKey, data, fromUser, loadingMore) {
|
||||
|
||||
private val pinnedStatusesRef = AtomicReference<List<ParcelableStatus>>()
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
package org.mariotaku.twidere.model
|
||||
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
open class BaseRefreshTaskParam(
|
||||
override val accountKeys: Array<UserKey>,
|
||||
override val pagination: Array<out Pagination?>?
|
||||
) : RefreshTaskParam {
|
||||
|
||||
override var extraId: Long = -1L
|
||||
override var isLoadingMore: Boolean = false
|
||||
override var shouldAbort: Boolean = false
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.mariotaku.twidere.model
|
||||
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/14.
|
||||
*/
|
||||
interface RefreshTaskParam {
|
||||
val accountKeys: Array<UserKey>
|
||||
|
||||
val pagination: Array<out Pagination?>? get() = null
|
||||
|
||||
val extraId: Long get() = -1
|
||||
|
||||
val isLoadingMore: Boolean get() = false
|
||||
|
||||
val shouldAbort: Boolean get() = false
|
||||
|
||||
val isBackground: Boolean get() = false
|
||||
|
||||
val hasMaxIds: Boolean
|
||||
get() = pagination?.any { (it as? SinceMaxPagination)?.maxId != null } ?: false
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package org.mariotaku.twidere.model
|
||||
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/14.
|
||||
*/
|
||||
abstract class SimpleRefreshTaskParam : RefreshTaskParam {
|
||||
|
||||
override val pagination: Array<out Pagination?>? = null
|
||||
|
||||
override val extraId: Long = -1
|
||||
|
||||
override val isLoadingMore: Boolean = false
|
||||
|
||||
override val shouldAbort: Boolean = false
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.model.refresh
|
||||
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
open class BaseRefreshTaskParam(
|
||||
override val accountKeys: Array<UserKey>,
|
||||
override val pagination: Array<out Pagination?>?
|
||||
) : RefreshTaskParam {
|
||||
|
||||
override var extraId: Long = -1L
|
||||
override var tabId: Long = -1L
|
||||
override var isLoadingMore: Boolean = false
|
||||
override var shouldAbort: Boolean = false
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.model.refresh
|
||||
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/14.
|
||||
*/
|
||||
interface RefreshTaskParam {
|
||||
val accountKeys: Array<UserKey>
|
||||
|
||||
val pagination: Array<out Pagination?>? get() = null
|
||||
|
||||
val extraId: Long get() = -1
|
||||
|
||||
val tabId: Long get() = -1
|
||||
|
||||
val isLoadingMore: Boolean get() = false
|
||||
|
||||
val shouldAbort: Boolean get() = false
|
||||
|
||||
val isBackground: Boolean get() = false
|
||||
|
||||
val hasMaxIds: Boolean
|
||||
get() = pagination?.any { (it as? SinceMaxPagination)?.maxId != null } ?: false
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.model.refresh
|
||||
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/14.
|
||||
*/
|
||||
abstract class SimpleRefreshTaskParam : RefreshTaskParam {
|
||||
|
||||
override val pagination: Array<out Pagination?>? = null
|
||||
|
||||
override val extraId: Long = -1
|
||||
|
||||
override val isLoadingMore: Boolean = false
|
||||
|
||||
override val shouldAbort: Boolean = false
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.model.refresh
|
||||
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
|
||||
|
||||
class UserRelatedRefreshTaskParam(
|
||||
accountKey: UserKey,
|
||||
val userKey: UserKey?,
|
||||
val userScreenName: String?,
|
||||
pagination: Pagination? = null
|
||||
) : BaseRefreshTaskParam(arrayOf(accountKey), arrayOf(pagination))
|
@ -38,6 +38,7 @@ import org.mariotaku.twidere.extension.queryCount
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.notification.NotificationChannelSpec
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.*
|
||||
import org.mariotaku.twidere.task.twitter.GetActivitiesAboutMeTask
|
||||
|
@ -31,6 +31,7 @@ import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.fragment.HomeTimelineFragment
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
@ -38,7 +39,7 @@ import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
class GetHomeTimelineTask(context: Context) : GetStatusesTask(context) {
|
||||
class GetHomeTimelineTask(context: Context) : GetStatusesTask<RefreshTaskParam>(context) {
|
||||
|
||||
override val contentUri: Uri = Statuses.CONTENT_URI
|
||||
|
||||
@ -46,19 +47,19 @@ class GetHomeTimelineTask(context: Context) : GetStatusesTask(context) {
|
||||
|
||||
override val errorInfoKey: String = ErrorInfoStore.KEY_HOME_TIMELINE
|
||||
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return twitter.getHomeTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return statusNet.getHomeTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return fanfou.getHomeTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging): List<MastodonStatus> {
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging, params: RefreshTaskParam?): List<MastodonStatus> {
|
||||
return mastodon.getHomeTimeline(paging)
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.fragment.statuses.NetworkPublicTimelineFragment
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
@ -39,7 +40,7 @@ import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
class GetNetworkPublicTimelineTask(context: Context) : GetStatusesTask(context) {
|
||||
class GetNetworkPublicTimelineTask(context: Context) : GetStatusesTask<RefreshTaskParam>(context) {
|
||||
|
||||
override val contentUri: Uri = Statuses.NetworkPublic.CONTENT_URI
|
||||
|
||||
@ -47,19 +48,19 @@ class GetNetworkPublicTimelineTask(context: Context) : GetStatusesTask(context)
|
||||
|
||||
override val errorInfoKey: String = ErrorInfoStore.KEY_NETWORK_PUBLIC_TIMELINE
|
||||
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
throw MicroBlogException("Network public timeline unsupported")
|
||||
}
|
||||
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return statusNet.getNetworkPublicTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
throw MicroBlogException("Network public timeline unsupported")
|
||||
}
|
||||
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging): List<MastodonStatus> {
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging, params: RefreshTaskParam?): List<MastodonStatus> {
|
||||
return mastodon.getPublicTimeline(paging, false)
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ import org.mariotaku.twidere.annotation.FilterScope
|
||||
import org.mariotaku.twidere.annotation.ReadPositionTag
|
||||
import org.mariotaku.twidere.fragment.statuses.PublicTimelineFragment
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
@ -38,7 +39,7 @@ import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
class GetPublicTimelineTask(context: Context) : GetStatusesTask(context) {
|
||||
class GetPublicTimelineTask(context: Context) : GetStatusesTask<RefreshTaskParam>(context) {
|
||||
|
||||
override val contentUri: Uri = Statuses.Public.CONTENT_URI
|
||||
|
||||
@ -46,19 +47,19 @@ class GetPublicTimelineTask(context: Context) : GetStatusesTask(context) {
|
||||
|
||||
override val errorInfoKey: String = ErrorInfoStore.KEY_PUBLIC_TIMELINE
|
||||
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return twitter.getPublicTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return statusNet.getPublicTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging): List<Status> {
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging, params: RefreshTaskParam?): List<Status> {
|
||||
return fanfou.getPublicTimeline(paging)
|
||||
}
|
||||
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging): List<MastodonStatus> {
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging, params: RefreshTaskParam?): List<MastodonStatus> {
|
||||
return mastodon.getPublicTimeline(paging, true)
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,12 @@ import org.mariotaku.twidere.extension.model.*
|
||||
import org.mariotaku.twidere.extension.model.api.applyLoadLimit
|
||||
import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable
|
||||
import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.GetStatusesTaskEvent
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.task.GetTimelineResult
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns
|
||||
@ -66,9 +70,9 @@ import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
/**
|
||||
* Created by mariotaku on 16/1/2.
|
||||
*/
|
||||
abstract class GetStatusesTask(
|
||||
abstract class GetStatusesTask<P : RefreshTaskParam>(
|
||||
context: Context
|
||||
) : BaseAbstractTask<RefreshTaskParam, List<Pair<GetTimelineResult<ParcelableStatus>?, Exception?>>,
|
||||
) : BaseAbstractTask<P, List<Pair<GetTimelineResult<ParcelableStatus>?, Exception?>>,
|
||||
(Boolean) -> Unit>(context) {
|
||||
|
||||
private val profileImageSize = context.getString(R.string.profile_image_size)
|
||||
@ -80,7 +84,7 @@ abstract class GetStatusesTask(
|
||||
|
||||
protected abstract val errorInfoKey: String
|
||||
|
||||
override fun doLongOperation(param: RefreshTaskParam): List<Pair<GetTimelineResult<ParcelableStatus>?, Exception?>> {
|
||||
override fun doLongOperation(param: P): List<Pair<GetTimelineResult<ParcelableStatus>?, Exception?>> {
|
||||
if (param.shouldAbort) return emptyList()
|
||||
val accountKeys = param.accountKeys.takeIf { it.isNotEmpty() } ?: return emptyList()
|
||||
val loadItemLimit = preferences[loadItemLimitKey]
|
||||
@ -111,7 +115,7 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
}
|
||||
val timelineResult = getStatuses(account, paging)
|
||||
val storeResult = storeStatus(account, timelineResult.data, sinceId, maxId,
|
||||
val storeResult = storeStatus(account, timelineResult.data, param, sinceId, maxId,
|
||||
sinceSortId, maxSortId, loadItemLimit, false)
|
||||
// TODO cache related data and preload
|
||||
errorInfoStore.remove(errorInfoKey, accountKey.id)
|
||||
@ -158,7 +162,7 @@ abstract class GetStatusesTask(
|
||||
when (account.type) {
|
||||
AccountType.TWITTER -> {
|
||||
val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java)
|
||||
val timeline = getTwitterStatuses(account, twitter, paging)
|
||||
val timeline = getTwitterStatuses(account, twitter, paging, params)
|
||||
val statuses = timeline.map {
|
||||
it.toParcelable(account, profileImageSize)
|
||||
}
|
||||
@ -169,7 +173,7 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
AccountType.STATUSNET -> {
|
||||
val statusnet = account.newMicroBlogInstance(context, MicroBlog::class.java)
|
||||
val timeline = getStatusNetStatuses(account, statusnet, paging)
|
||||
val timeline = getStatusNetStatuses(account, statusnet, paging, params)
|
||||
val statuses = timeline.map {
|
||||
it.toParcelable(account, profileImageSize)
|
||||
}
|
||||
@ -180,7 +184,7 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
AccountType.FANFOU -> {
|
||||
val fanfou = account.newMicroBlogInstance(context, MicroBlog::class.java)
|
||||
val timeline = getFanfouStatuses(account, fanfou, paging)
|
||||
val timeline = getFanfouStatuses(account, fanfou, paging, params)
|
||||
val statuses = timeline.map {
|
||||
it.toParcelable(account, profileImageSize)
|
||||
}
|
||||
@ -191,7 +195,7 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
AccountType.MASTODON -> {
|
||||
val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java)
|
||||
val timeline = getMastodonStatuses(account, mastodon, paging)
|
||||
val timeline = getMastodonStatuses(account, mastodon, paging, params)
|
||||
return GetTimelineResult(account, timeline.map {
|
||||
it.toParcelable(account)
|
||||
}, timeline.flatMap { status ->
|
||||
@ -206,10 +210,10 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging): List<Status>
|
||||
protected abstract fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging): List<Status>
|
||||
protected abstract fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging): List<Status>
|
||||
protected abstract fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging): List<MastodonStatus>
|
||||
protected abstract fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging, params: P?): List<Status>
|
||||
protected abstract fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging, params: P?): List<Status>
|
||||
protected abstract fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging, params: P?): List<Status>
|
||||
protected abstract fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging, params: P?): List<MastodonStatus>
|
||||
|
||||
protected abstract fun syncFetchReadPosition(manager: TimelineSyncManager, accountKeys: Array<UserKey>)
|
||||
|
||||
@ -226,7 +230,7 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
|
||||
private fun storeStatus(account: AccountDetails, statuses: List<ParcelableStatus>,
|
||||
sinceId: String?, maxId: String?, sinceSortId: Long, maxSortId: Long,
|
||||
param: P, sinceId: String?, maxId: String?, sinceSortId: Long, maxSortId: Long,
|
||||
loadItemLimit: Int, notify: Boolean): Int {
|
||||
val accountKey = account.key
|
||||
val uri = contentUri
|
||||
@ -248,6 +252,7 @@ abstract class GetStatusesTask(
|
||||
statuses.forEachIndexed { i, status ->
|
||||
status.position_key = getPositionKey(status.timestamp, status.sort_id, lastSortId,
|
||||
sortDiff, i, statuses.size)
|
||||
status.tab_id = param.tabId
|
||||
mediaPreloader.preloadStatus(status)
|
||||
values[i] = creator.create(status)
|
||||
if (minIdx == -1 || status < statuses[minIdx]) {
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.task.statuses
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.mastodon.Mastodon
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.Status
|
||||
import org.mariotaku.twidere.alias.MastodonStatus
|
||||
import org.mariotaku.twidere.annotation.FilterScope
|
||||
import org.mariotaku.twidere.exception.RequiredFieldNotFoundException
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.refresh.UserRelatedRefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.util.ErrorInfoStore
|
||||
import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/2/11.
|
||||
*/
|
||||
class GetUserFavoritesTask(context: Context) : GetStatusesTask<UserRelatedRefreshTaskParam>(context) {
|
||||
|
||||
override val contentUri: Uri = Statuses.Favorites.CONTENT_URI
|
||||
|
||||
override val filterScopes: Int = FilterScope.FAVORITES
|
||||
|
||||
override val errorInfoKey: String = ErrorInfoStore.KEY_FAVORITES_TIMELINE
|
||||
|
||||
override fun getTwitterStatuses(account: AccountDetails, twitter: MicroBlog, paging: Paging, params: UserRelatedRefreshTaskParam?): List<Status> {
|
||||
return getMicroBlogUserFavorites(params, twitter, paging)
|
||||
}
|
||||
|
||||
override fun getStatusNetStatuses(account: AccountDetails, statusNet: MicroBlog, paging: Paging, params: UserRelatedRefreshTaskParam?): List<Status> {
|
||||
return getMicroBlogUserFavorites(params, statusNet, paging)
|
||||
}
|
||||
|
||||
override fun getFanfouStatuses(account: AccountDetails, fanfou: MicroBlog, paging: Paging, params: UserRelatedRefreshTaskParam?): List<Status> {
|
||||
return getMicroBlogUserFavorites(params, fanfou, paging)
|
||||
}
|
||||
|
||||
override fun getMastodonStatuses(account: AccountDetails, mastodon: Mastodon, paging: Paging, params: UserRelatedRefreshTaskParam?): List<MastodonStatus> {
|
||||
if (params?.userKey != account.key) {
|
||||
throw MicroBlogException("Only current account favorites is supported")
|
||||
}
|
||||
return mastodon.getFavourites(paging)
|
||||
}
|
||||
|
||||
override fun syncFetchReadPosition(manager: TimelineSyncManager, accountKeys: Array<UserKey>) {
|
||||
}
|
||||
|
||||
private fun getMicroBlogUserFavorites(params: UserRelatedRefreshTaskParam?, microBlog: MicroBlog, paging: Paging): List<Status> {
|
||||
return when {
|
||||
params?.userKey != null -> microBlog.getFavorites(params.userKey.id, paging)
|
||||
params?.userScreenName != null -> microBlog.getFavoritesByScreenName(params.userScreenName, paging)
|
||||
else -> throw RequiredFieldNotFoundException("user_id", "screen_name")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,7 +20,7 @@ import org.mariotaku.twidere.extension.model.getMaxSortId
|
||||
import org.mariotaku.twidere.extension.model.getSinceId
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableActivity
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.GetActivitiesTaskEvent
|
||||
import org.mariotaku.twidere.model.task.GetTimelineResult
|
||||
|
@ -48,6 +48,7 @@ import org.mariotaku.twidere.model.message.conversation.TwitterOfficialConversat
|
||||
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.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.AccountUtils.getAccountDetails
|
||||
import org.mariotaku.twidere.model.util.ParcelableMessageUtils
|
||||
|
@ -47,6 +47,7 @@ import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.event.*
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.*
|
||||
|
@ -85,6 +85,7 @@ class ErrorInfoStore(application: Context) {
|
||||
val KEY_INTERACTIONS = "interactions"
|
||||
val KEY_HOME_TIMELINE = "home_timeline"
|
||||
val KEY_PUBLIC_TIMELINE = "public_timeline"
|
||||
val KEY_FAVORITES_TIMELINE = "favorites_timeline"
|
||||
val KEY_NETWORK_PUBLIC_TIMELINE = "network_public_timeline"
|
||||
val KEY_ACTIVITIES_BY_FRIENDS = "activities_by_friends"
|
||||
|
||||
|
@ -15,16 +15,16 @@ import org.mariotaku.twidere.constant.IntentConstants.INTENT_PACKAGE_PREFIX
|
||||
import org.mariotaku.twidere.constant.dataSyncProviderInfoKey
|
||||
import org.mariotaku.twidere.constant.stopAutoRefreshWhenBatteryLowKey
|
||||
import org.mariotaku.twidere.model.AccountPreferences
|
||||
import org.mariotaku.twidere.model.RefreshTaskParam
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.pagination.Pagination
|
||||
import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
||||
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||
import org.mariotaku.twidere.task.filter.RefreshFiltersSubscriptionsTask
|
||||
import org.mariotaku.twidere.task.filter.RefreshLaunchPresentationsTask
|
||||
import org.mariotaku.twidere.task.twitter.GetActivitiesAboutMeTask
|
||||
import org.mariotaku.twidere.task.statuses.GetHomeTimelineTask
|
||||
import org.mariotaku.twidere.task.twitter.GetActivitiesAboutMeTask
|
||||
import org.mariotaku.twidere.task.twitter.message.GetMessagesTask
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user