fixed conversation order bug

This commit is contained in:
Mariotaku Lee 2017-09-19 13:15:12 +08:00
parent 9bcabb1eb6
commit a9b83d8977
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
6 changed files with 32 additions and 24 deletions

View File

@ -42,12 +42,12 @@ subprojects {
]
libVersions = [
Kotlin : "${kotlinVersion}",
SupportLib : '26.0.2',
SupportLib : '26.1.0',
SupportTest : '1.0.0',
MariotakuCommons : '0.9.19',
RestFu : '0.9.60',
ObjectCursor : '0.9.20',
PlayServices : '11.2.0',
PlayServices : '11.2.2',
MapsUtils : '0.5',
DropboxCoreSdk : '3.0.3',
GoogleDriveApi : 'v3-rev61-1.22.0',

View File

@ -38,6 +38,7 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
import org.mariotaku.twidere.constant.*
import org.mariotaku.twidere.extension.model.originalId
import org.mariotaku.twidere.extension.model.retweet_sort_id
import org.mariotaku.twidere.fragment.status.StatusFragment
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.util.StatusAdapterLinkClickHandler
@ -207,13 +208,12 @@ class StatusDetailsAdapter(
setTypeCount(ITEM_IDX_REPLY, 0)
replyStart = -1
} else {
var sortId = status.sort_id
if (status.is_retweet) {
sortId = data.find {
it.id == status.retweet_id
}?.sort_id ?: status.retweet_timestamp
val sortId = if (status.is_retweet) {
status.retweet_sort_id
} else {
status.sort_id
}
var conversationCount = 0
var replyCount = 0
var replyStart = -1

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.extension.model
import org.mariotaku.ktextension.addAllTo
import org.mariotaku.ktextension.toLongOr
import org.mariotaku.microblog.library.mastodon.annotation.StatusVisibility
import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM
import org.mariotaku.twidere.model.*
@ -103,6 +104,12 @@ val ParcelableStatus.quoted: ParcelableStatus?
return obj
}
val ParcelableStatus.retweet_sort_id: Long
get() {
if (!is_retweet) return -1
return retweet_id.toLongOr(timestamp)
}
fun ParcelableStatus.toSummaryLine(): ParcelableActivity.SummaryLine {
val result = ParcelableActivity.SummaryLine()
result.key = user_key
@ -133,13 +140,14 @@ fun ParcelableStatus.extractFanfouHashtags(): List<String> {
fun ParcelableStatus.makeOriginal() {
if (!is_retweet) return
id = retweet_id
is_retweet = false
retweeted_by_user_key = null
retweeted_by_user_name = null
retweeted_by_user_screen_name = null
retweeted_by_user_profile_image = null
retweet_timestamp = -1
retweet_id = null
is_retweet = false
sort_id = id.toLongOr(timestamp)
}
fun ParcelableStatus.addFilterFlag(@ParcelableStatus.FilterFlags flags: Long) {

View File

@ -142,8 +142,6 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
val loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false)
return ConversationLoader(activity, status, adapter.getData(), true, loadingMore).apply {
pagination = args.toPagination()
// Setting comparator to null lets statuses sort ascending
comparator = null
}
}

View File

@ -48,7 +48,6 @@ 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.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject
@ -62,7 +61,7 @@ abstract class AbsRequestStatusesLoader(
protected val loadingMore: Boolean
) : ParcelableStatusesLoader(context, adapterData, tabPosition, fromUser), IPaginationLoader {
// Statuses sorted descending by default
var comparator: Comparator<ParcelableStatus>? = ParcelableStatus.REVERSE_COMPARATOR
open val comparator: Comparator<ParcelableStatus>? = ParcelableStatus.REVERSE_COMPARATOR
var exception: MicroBlogException?
get() = exceptionRef.get()
@ -105,6 +104,7 @@ abstract class AbsRequestStatusesLoader(
@SuppressWarnings("unchecked")
override final fun loadInBackground(): ListResponse<ParcelableStatus> {
val context = context
val comparator = this.comparator
val accountKey = accountKey ?: return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
val details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
return ListResponse.getListInstance<ParcelableStatus>(MicroBlogException("No Account"))
@ -114,11 +114,11 @@ abstract class AbsRequestStatusesLoader(
if (cached != null) {
data.addAll(cached)
if (comparator != null) {
Collections.sort(data, comparator)
data.sortWith(comparator)
} else {
Collections.sort(data)
data.sort()
}
return ListResponse.getListInstance(CopyOnWriteArrayList(data))
return ListResponse.getListInstance(data)
}
}
if (!fromUser) return ListResponse.getListInstance(data)
@ -171,12 +171,12 @@ abstract class AbsRequestStatusesLoader(
data.forEach { it.is_filtered = shouldFilterStatus(it) }
if (comparator != null) {
data.sortWith(comparator!!)
data.sortWith(comparator)
} else {
data.sort()
}
saveCachedData(data)
return ListResponse.getListInstance(CopyOnWriteArrayList(data))
return ListResponse.getListInstance(data)
}
override final fun onStartLoading() {

View File

@ -59,11 +59,13 @@ class ConversationLoader(
loadingMore: Boolean
) : AbsRequestStatusesLoader(context, status.account_key, adapterData, null, -1, fromUser, loadingMore) {
private val status = ParcelUtils.clone(status).apply { makeOriginal() }
override val comparator: Comparator<ParcelableStatus>? = null
var canLoadAllReplies: Boolean = false
private set
private val status = ParcelUtils.clone(status).apply { makeOriginal() }
@Throws(MicroBlogException::class)
override fun getStatuses(account: AccountDetails, paging: Paging): PaginatedList<ParcelableStatus> {
when (account.type) {
@ -89,11 +91,11 @@ class ConversationLoader(
AccountType.TWITTER -> {
val isOfficial = account.isOfficial(context)
canLoadAllReplies = isOfficial
if (isOfficial) {
return microBlog.showConversation(status.id, paging).mapMicroBlogToPaginated {
it.toParcelable(account, profileImageSize)
}
}
// if (isOfficial) {
// return microBlog.showConversation(status.id, paging).mapMicroBlogToPaginated {
// it.toParcelable(account, profileImageSize)
// }
// }
return showConversationCompat(microBlog, account, status, true)
}
AccountType.STATUSNET -> {