From d5781f681458a04f1530ffd386e283c97436d951 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Fri, 5 Jan 2018 01:01:39 +0800 Subject: [PATCH] removed unused codes --- .../fetcher/users/UserRelatedUsersFetcher.kt | 54 -------- .../status/StatusActivitySummaryLiveData.kt | 19 +-- .../loader/users/AbsRequestUsersLoader.kt | 116 ------------------ .../loader/users/ParcelableUsersLoader.kt | 52 -------- 4 files changed, 10 insertions(+), 231 deletions(-) delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/data/fetcher/users/UserRelatedUsersFetcher.kt delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt delete mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/data/fetcher/users/UserRelatedUsersFetcher.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/data/fetcher/users/UserRelatedUsersFetcher.kt deleted file mode 100644 index 26441adf7..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/data/fetcher/users/UserRelatedUsersFetcher.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2018 Mariotaku Lee - * - * 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 . - */ - -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?, - fromUser: Boolean -) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { - - @Throws(MicroBlogException::class) - override final fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { - 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 - - @Throws(MicroBlogException::class) - protected abstract fun getUsersByScreenName(details: AccountDetails, paging: Paging, screenName: String): PaginatedList -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/data/status/StatusActivitySummaryLiveData.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/data/status/StatusActivitySummaryLiveData.kt index 15a3f1b6e..45c18369f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/data/status/StatusActivitySummaryLiveData.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/data/status/StatusActivitySummaryLiveData.kt @@ -38,7 +38,7 @@ 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.provider.TwidereDataStore +import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import org.mariotaku.twidere.util.DataStoreUtils import org.mariotaku.twidere.util.updateStatusInfo @@ -62,19 +62,19 @@ class StatusActivitySummaryLiveData(val context: Context) : ComputableExceptionL twitter.getActivitySummary(statusId, account) } val countValues = ContentValues() - countValues.put(TwidereDataStore.Statuses.REPLY_COUNT, activitySummary.replyCount) - countValues.put(TwidereDataStore.Statuses.FAVORITE_COUNT, activitySummary.favoriteCount) - countValues.put(TwidereDataStore.Statuses.RETWEET_COUNT, activitySummary.retweetCount) + countValues.put(Statuses.REPLY_COUNT, activitySummary.replyCount) + countValues.put(Statuses.FAVORITE_COUNT, activitySummary.favoriteCount) + countValues.put(Statuses.RETWEET_COUNT, activitySummary.retweetCount) val cr = context.contentResolver val statusWhere = Expression.and( - Expression.equalsArgs(TwidereDataStore.Statuses.ACCOUNT_KEY), + Expression.equalsArgs(Statuses.ACCOUNT_KEY), Expression.or( - Expression.equalsArgs(TwidereDataStore.Statuses.ID), - Expression.equalsArgs(TwidereDataStore.Statuses.RETWEET_ID))) + Expression.equalsArgs(Statuses.ID), + Expression.equalsArgs(Statuses.RETWEET_ID))) val statusWhereArgs = arrayOf(accountKey.toString(), statusId, statusId) - cr.update(TwidereDataStore.Statuses.HomeTimeline.CONTENT_URI, countValues, statusWhere.sql, statusWhereArgs) - cr.updateStatusInfo(DataStoreUtils.STATUSES_ACTIVITIES_URIS, TwidereDataStore.Statuses.COLUMNS, + cr.update(Statuses.HomeTimeline.CONTENT_URI, countValues, statusWhere.sql, statusWhereArgs) + cr.updateStatusInfo(DataStoreUtils.STATUSES_ACTIVITIES_URIS, Statuses.COLUMNS, accountKey, statusId, ParcelableStatus::class.java) { item -> item.favorite_count = activitySummary.favoriteCount item.reply_count = activitySummary.replyCount @@ -104,6 +104,7 @@ class StatusActivitySummaryLiveData(val context: Context) : ComputableExceptionL val relatedUsers = (getRetweetedBy(statusId, paging) + getFavoritedBy(statusId, paging)) .filterNot { DataStoreUtils.isFilteringUser(context, it.key) } .map { it.toParcelable(account) } + .distinctBy(ParcelableUser::key) val result = StatusActivity(statusId, relatedUsers) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt deleted file mode 100644 index 1fe1df4fb..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -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?, - 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 { - val data = data - val details: AccountDetails - val users: List - 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) { - 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 - - @Throws(MicroBlogException::class) - private fun getUsersInternal(details: AccountDetails): List { - val paging = Paging() - processPaging(paging, details, loadItemLimit) - pagination?.applyTo(paging) - val users = getUsers(details, paging) - prevPagination = users.previousPage - nextPagination = users.nextPage - return users - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt deleted file mode 100644 index ca4c168ac..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 Mariotaku Lee - * - * 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 . - */ - -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?, - override var fromUser: Boolean -) : FixedAsyncTaskLoader>(context), IExtendedLoader { - - protected val data: MutableList = Collections.synchronizedList(NoDuplicatesArrayList()) - - 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 } - } - -}