removed unused codes
This commit is contained in:
parent
41302b9a89
commit
d5781f6814
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* Twidere - Twitter client for Android
|
|
||||||
*
|
|
||||||
* Copyright (C) 2012-2018 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.data.fetcher.users
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import org.mariotaku.microblog.library.MicroBlogException
|
|
||||||
import org.mariotaku.microblog.library.model.Paging
|
|
||||||
import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader
|
|
||||||
import org.mariotaku.twidere.model.AccountDetails
|
|
||||||
import org.mariotaku.twidere.model.ParcelableUser
|
|
||||||
import org.mariotaku.twidere.model.UserKey
|
|
||||||
import org.mariotaku.twidere.model.pagination.PaginatedList
|
|
||||||
|
|
||||||
abstract class UserRelatedUsersFetcher(
|
|
||||||
context: Context,
|
|
||||||
accountKey: UserKey?,
|
|
||||||
private val userKey: UserKey?,
|
|
||||||
private val screenName: String?,
|
|
||||||
data: List<ParcelableUser>?,
|
|
||||||
fromUser: Boolean
|
|
||||||
) : AbsRequestUsersLoader(context, accountKey, data, fromUser) {
|
|
||||||
|
|
||||||
@Throws(MicroBlogException::class)
|
|
||||||
override final fun getUsers(details: AccountDetails, paging: Paging): PaginatedList<ParcelableUser> {
|
|
||||||
return when {
|
|
||||||
userKey != null -> getUsersByKey(details, paging, userKey)
|
|
||||||
screenName != null -> getUsersByScreenName(details, paging, screenName)
|
|
||||||
else -> throw MicroBlogException("user_id or screen_name required")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(MicroBlogException::class)
|
|
||||||
protected abstract fun getUsersByKey(details: AccountDetails, paging: Paging, userKey: UserKey): PaginatedList<ParcelableUser>
|
|
||||||
|
|
||||||
@Throws(MicroBlogException::class)
|
|
||||||
protected abstract fun getUsersByScreenName(details: AccountDetails, paging: Paging, screenName: String): PaginatedList<ParcelableUser>
|
|
||||||
}
|
|
|
@ -38,7 +38,7 @@ import org.mariotaku.twidere.model.AccountDetails
|
||||||
import org.mariotaku.twidere.model.ParcelableStatus
|
import org.mariotaku.twidere.model.ParcelableStatus
|
||||||
import org.mariotaku.twidere.model.ParcelableUser
|
import org.mariotaku.twidere.model.ParcelableUser
|
||||||
import org.mariotaku.twidere.model.UserKey
|
import org.mariotaku.twidere.model.UserKey
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore
|
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||||
import org.mariotaku.twidere.util.DataStoreUtils
|
import org.mariotaku.twidere.util.DataStoreUtils
|
||||||
import org.mariotaku.twidere.util.updateStatusInfo
|
import org.mariotaku.twidere.util.updateStatusInfo
|
||||||
|
|
||||||
|
@ -62,19 +62,19 @@ class StatusActivitySummaryLiveData(val context: Context) : ComputableExceptionL
|
||||||
twitter.getActivitySummary(statusId, account)
|
twitter.getActivitySummary(statusId, account)
|
||||||
}
|
}
|
||||||
val countValues = ContentValues()
|
val countValues = ContentValues()
|
||||||
countValues.put(TwidereDataStore.Statuses.REPLY_COUNT, activitySummary.replyCount)
|
countValues.put(Statuses.REPLY_COUNT, activitySummary.replyCount)
|
||||||
countValues.put(TwidereDataStore.Statuses.FAVORITE_COUNT, activitySummary.favoriteCount)
|
countValues.put(Statuses.FAVORITE_COUNT, activitySummary.favoriteCount)
|
||||||
countValues.put(TwidereDataStore.Statuses.RETWEET_COUNT, activitySummary.retweetCount)
|
countValues.put(Statuses.RETWEET_COUNT, activitySummary.retweetCount)
|
||||||
|
|
||||||
val cr = context.contentResolver
|
val cr = context.contentResolver
|
||||||
val statusWhere = Expression.and(
|
val statusWhere = Expression.and(
|
||||||
Expression.equalsArgs(TwidereDataStore.Statuses.ACCOUNT_KEY),
|
Expression.equalsArgs(Statuses.ACCOUNT_KEY),
|
||||||
Expression.or(
|
Expression.or(
|
||||||
Expression.equalsArgs(TwidereDataStore.Statuses.ID),
|
Expression.equalsArgs(Statuses.ID),
|
||||||
Expression.equalsArgs(TwidereDataStore.Statuses.RETWEET_ID)))
|
Expression.equalsArgs(Statuses.RETWEET_ID)))
|
||||||
val statusWhereArgs = arrayOf(accountKey.toString(), statusId, statusId)
|
val statusWhereArgs = arrayOf(accountKey.toString(), statusId, statusId)
|
||||||
cr.update(TwidereDataStore.Statuses.HomeTimeline.CONTENT_URI, countValues, statusWhere.sql, statusWhereArgs)
|
cr.update(Statuses.HomeTimeline.CONTENT_URI, countValues, statusWhere.sql, statusWhereArgs)
|
||||||
cr.updateStatusInfo(DataStoreUtils.STATUSES_ACTIVITIES_URIS, TwidereDataStore.Statuses.COLUMNS,
|
cr.updateStatusInfo(DataStoreUtils.STATUSES_ACTIVITIES_URIS, Statuses.COLUMNS,
|
||||||
accountKey, statusId, ParcelableStatus::class.java) { item ->
|
accountKey, statusId, ParcelableStatus::class.java) { item ->
|
||||||
item.favorite_count = activitySummary.favoriteCount
|
item.favorite_count = activitySummary.favoriteCount
|
||||||
item.reply_count = activitySummary.replyCount
|
item.reply_count = activitySummary.replyCount
|
||||||
|
@ -104,6 +104,7 @@ class StatusActivitySummaryLiveData(val context: Context) : ComputableExceptionL
|
||||||
val relatedUsers = (getRetweetedBy(statusId, paging) + getFavoritedBy(statusId, paging))
|
val relatedUsers = (getRetweetedBy(statusId, paging) + getFavoritedBy(statusId, paging))
|
||||||
.filterNot { DataStoreUtils.isFilteringUser(context, it.key) }
|
.filterNot { DataStoreUtils.isFilteringUser(context, it.key) }
|
||||||
.map { it.toParcelable(account) }
|
.map { it.toParcelable(account) }
|
||||||
|
.distinctBy(ParcelableUser::key)
|
||||||
|
|
||||||
val result = StatusActivity(statusId, relatedUsers)
|
val result = StatusActivity(statusId, relatedUsers)
|
||||||
|
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.loader.users
|
|
||||||
|
|
||||||
import android.accounts.AccountManager
|
|
||||||
import android.content.Context
|
|
||||||
import org.mariotaku.kpreferences.get
|
|
||||||
import org.mariotaku.microblog.library.MicroBlogException
|
|
||||||
import org.mariotaku.microblog.library.model.Paging
|
|
||||||
import org.mariotaku.twidere.R
|
|
||||||
import org.mariotaku.twidere.constant.loadItemLimitKey
|
|
||||||
import org.mariotaku.twidere.dagger.DependencyHolder
|
|
||||||
import org.mariotaku.twidere.exception.AccountNotFoundException
|
|
||||||
import org.mariotaku.twidere.extension.getDetailsOrThrow
|
|
||||||
import org.mariotaku.twidere.extension.model.api.applyLoadLimit
|
|
||||||
import org.mariotaku.twidere.loader.iface.IPaginationLoader
|
|
||||||
import org.mariotaku.twidere.model.AccountDetails
|
|
||||||
import org.mariotaku.twidere.model.ListResponse
|
|
||||||
import org.mariotaku.twidere.model.ParcelableUser
|
|
||||||
import org.mariotaku.twidere.model.UserKey
|
|
||||||
import org.mariotaku.twidere.model.pagination.PaginatedList
|
|
||||||
import org.mariotaku.twidere.model.pagination.Pagination
|
|
||||||
import org.mariotaku.twidere.util.DebugLog
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
abstract class AbsRequestUsersLoader(
|
|
||||||
context: Context,
|
|
||||||
val accountKey: UserKey?,
|
|
||||||
data: List<ParcelableUser>?,
|
|
||||||
fromUser: Boolean
|
|
||||||
) : ParcelableUsersLoader(context, data, fromUser), IPaginationLoader {
|
|
||||||
|
|
||||||
protected val profileImageSize: String = context.getString(R.string.profile_image_size)
|
|
||||||
override var pagination: Pagination? = null
|
|
||||||
override var prevPagination: Pagination? = null
|
|
||||||
protected set
|
|
||||||
override var nextPagination: Pagination? = null
|
|
||||||
protected set
|
|
||||||
protected val loadItemLimit: Int
|
|
||||||
|
|
||||||
init {
|
|
||||||
val preferences = DependencyHolder.get(context).preferences
|
|
||||||
loadItemLimit = preferences[loadItemLimitKey]
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadInBackground(): List<ParcelableUser> {
|
|
||||||
val data = data
|
|
||||||
val details: AccountDetails
|
|
||||||
val users: List<ParcelableUser>
|
|
||||||
try {
|
|
||||||
val accountKey = accountKey ?: throw AccountNotFoundException()
|
|
||||||
details = AccountManager.get(context).getDetailsOrThrow(accountKey, true)
|
|
||||||
users = getUsersInternal(details)
|
|
||||||
} catch (e: MicroBlogException) {
|
|
||||||
DebugLog.w(tr = e)
|
|
||||||
return ListResponse.getListInstance(data, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
var pos = data.size
|
|
||||||
for (user in users) {
|
|
||||||
if (hasId(user.key)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
user.position = pos.toLong()
|
|
||||||
processUser(details, user)
|
|
||||||
pos++
|
|
||||||
}
|
|
||||||
data.addAll(users)
|
|
||||||
processUsersData(details, data)
|
|
||||||
return ListResponse.getListInstance(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun processUser(details: AccountDetails, user: ParcelableUser) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun processUsersData(details: AccountDetails, list: MutableList<ParcelableUser>) {
|
|
||||||
Collections.sort(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun processPaging(paging: Paging, details: AccountDetails, loadItemLimit: Int) {
|
|
||||||
paging.applyLoadLimit(details, loadItemLimit)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(MicroBlogException::class)
|
|
||||||
protected abstract fun getUsers(details: AccountDetails, paging: Paging):
|
|
||||||
PaginatedList<ParcelableUser>
|
|
||||||
|
|
||||||
@Throws(MicroBlogException::class)
|
|
||||||
private fun getUsersInternal(details: AccountDetails): List<ParcelableUser> {
|
|
||||||
val paging = Paging()
|
|
||||||
processPaging(paging, details, loadItemLimit)
|
|
||||||
pagination?.applyTo(paging)
|
|
||||||
val users = getUsers(details, paging)
|
|
||||||
prevPagination = users.previousPage
|
|
||||||
nextPagination = users.nextPage
|
|
||||||
return users
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.loader.users
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.support.v4.content.FixedAsyncTaskLoader
|
|
||||||
import org.mariotaku.twidere.loader.iface.IExtendedLoader
|
|
||||||
import org.mariotaku.twidere.model.ParcelableUser
|
|
||||||
import org.mariotaku.twidere.model.UserKey
|
|
||||||
import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
abstract class ParcelableUsersLoader(
|
|
||||||
context: Context,
|
|
||||||
data: List<ParcelableUser>?,
|
|
||||||
override var fromUser: Boolean
|
|
||||||
) : FixedAsyncTaskLoader<List<ParcelableUser>>(context), IExtendedLoader {
|
|
||||||
|
|
||||||
protected val data: MutableList<ParcelableUser> = Collections.synchronizedList(NoDuplicatesArrayList<ParcelableUser>())
|
|
||||||
|
|
||||||
init {
|
|
||||||
if (data != null) {
|
|
||||||
this.data.addAll(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStartLoading() {
|
|
||||||
forceLoad()
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun hasId(key: UserKey): Boolean {
|
|
||||||
return data.indices.any { data[it].key == key }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue