improved item id calculation

fixed status filter label
This commit is contained in:
Mariotaku Lee 2017-03-31 18:59:44 +08:00
parent 5c3b62dbe2
commit 27b2bcf3c4
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
7 changed files with 50 additions and 34 deletions

View File

@ -1 +1 @@
4204ab37b28019cfa0f51195034d1d0b5f2d31df
9ae153916806db7a16fffd9b76ef03d7ff4077a8

View File

@ -60,6 +60,8 @@ public class UserTimelineFilter implements TimelineFilter, Parcelable {
return context.getString(R.string.label_statuses_retweets_replies);
} else if (includeReplies) {
return context.getString(R.string.label_statuses_replies);
} else if (includeRetweets) {
return context.getString(R.string.label_statuses_retweets);
}
return context.getString(R.string.label_statuses);
}

View File

@ -123,6 +123,9 @@ class ParcelableActivitiesAdapter(
}
override fun getItemId(position: Int): Long {
val countIndex = itemCounts.getItemCountIndex(position)
when (countIndex) {
ITEM_INDEX_ACTIVITY -> {
val dataPosition = position - activityStartIndex
if (data is ObjectCursor) {
val cursor = (data as ObjectCursor).cursor
@ -135,7 +138,12 @@ class ParcelableActivitiesAdapter(
return ParcelableActivity.calculateHashCode(accountKey, timestamp, maxPosition,
minPosition).toLong()
}
return getActivity(position, false).hashCode().toLong()
return (countIndex.toLong() shl 32) or getActivity(position, false).hashCode().toLong()
}
else -> {
return (countIndex.toLong() shl 32) or getItemViewType(position).toLong()
}
}
}
fun getTimestamp(adapterPosition: Int, raw: Boolean = false): Long {

View File

@ -213,17 +213,16 @@ abstract class ParcelableStatusesAdapter(
when (countIndex) {
ITEM_INDEX_PINNED_STATUS -> {
val status = pinnedStatuses!![position - getItemStartPosition(ITEM_INDEX_PINNED_STATUS)]
val mask = ITEM_INDEX_PINNED_STATUS.toLong() shl 32
return mask + status.hashCode()
return (countIndex.toLong() shl 32) or status.hashCode().toLong()
}
ITEM_INDEX_STATUS -> return getFieldValue(position, { cursor, indices ->
ITEM_INDEX_STATUS -> return (countIndex.toLong() shl 32) or getFieldValue(position, { cursor, indices ->
val accountKey = UserKey.valueOf(cursor.getString(indices[Statuses.ACCOUNT_KEY]))
val id = cursor.getString(indices[Statuses.STATUS_ID])
return@getFieldValue ParcelableStatus.calculateHashCode(accountKey, id).toLong()
return@getFieldValue ParcelableStatus.calculateHashCode(accountKey, id)
}, { status ->
return@getFieldValue status.hashCode().toLong()
}, -1L)
else -> return (countIndex.toLong() shl 32) + position
return@getFieldValue status.hashCode()
}, -1).toLong()
else -> return (countIndex.toLong() shl 32) or position.toLong()
}
}

View File

@ -90,8 +90,8 @@ class SelectableUsersAdapter(
override fun getItemViewType(position: Int): Int {
val countIndex = itemCounts.getItemCountIndex(position)
when (countIndex) {
0, 2 -> ILoadMoreSupportAdapter.ITEM_VIEW_TYPE_LOAD_INDICATOR
1 -> return ITEM_VIEW_TYPE_USER
ITEM_TYPE_START_INDICATOR, ITEM_TYPE_END_INDICATOR -> ILoadMoreSupportAdapter.ITEM_VIEW_TYPE_LOAD_INDICATOR
ITEM_TYPE_USER -> return ITEM_VIEW_TYPE_USER
}
throw UnsupportedOperationException("Unsupported countIndex $countIndex, position $position")
}
@ -99,8 +99,8 @@ class SelectableUsersAdapter(
override fun getItemId(position: Int): Long {
val countIndex = itemCounts.getItemCountIndex(position)
when (countIndex) {
0, 2 -> return Integer.MAX_VALUE.toLong() + countIndex
1 -> return getUser(position)!!.hashCode().toLong()
ITEM_TYPE_START_INDICATOR, ITEM_TYPE_END_INDICATOR -> return (countIndex.toLong() shl 32)
ITEM_TYPE_USER -> return (countIndex.toLong() shl 32) or getUser(position)!!.hashCode().toLong()
}
throw UnsupportedOperationException("Unsupported countIndex $countIndex, position $position")
}
@ -111,9 +111,9 @@ class SelectableUsersAdapter(
private fun updateItemCounts() {
val position = loadMoreIndicatorPosition
itemCounts[0] = if (position and ILoadMoreSupportAdapter.START != 0L) 1 else 0
itemCounts[1] = userCount
itemCounts[2] = if (position and ILoadMoreSupportAdapter.END != 0L) 1 else 0
itemCounts[ITEM_TYPE_START_INDICATOR] = if (position and ILoadMoreSupportAdapter.START != 0L) 1 else 0
itemCounts[ITEM_TYPE_USER] = userCount
itemCounts[ITEM_TYPE_END_INDICATOR] = if (position and ILoadMoreSupportAdapter.END != 0L) 1 else 0
}
fun getUser(position: Int): ParcelableUser? {
@ -227,4 +227,10 @@ class SelectableUsersAdapter(
fun clearSelection() {
checkedState.clear()
}
companion object {
const val ITEM_TYPE_START_INDICATOR = 0
const val ITEM_TYPE_USER = 1
const val ITEM_TYPE_END_INDICATOR = 2
}
}

View File

@ -1822,12 +1822,13 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
}
override fun getItemId(position: Int): Long {
when (getItemCountIndex(position)) {
val countIndex = getItemCountIndex(position)
when (countIndex) {
ITEM_IDX_CONVERSATION, ITEM_IDX_STATUS, ITEM_IDX_REPLY -> {
return getStatus(position).hashCode().toLong()
return (countIndex.toLong() shl 32) or getStatus(position).hashCode().toLong()
}
}
return getItemType(position).toLong()
return (countIndex.toLong() shl 32) or getItemType(position).toLong()
}
override fun getItemCount(): Int {

View File

@ -31,7 +31,6 @@ import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v4.app.FragmentActivity
import android.support.v4.app.LoaderManager
import android.support.v4.content.AsyncTaskLoader
import android.support.v4.content.FixedAsyncTaskLoader
import android.support.v4.content.Loader
import android.support.v7.app.AlertDialog
@ -582,13 +581,14 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
}
override fun getItemId(position: Int): Long {
when (itemCounts.getItemCountIndex(position)) {
val countIndex = itemCounts.getItemCountIndex(position)
when (countIndex) {
ITEM_INDEX_ITEM -> {
val user = getUser(position)!!
return user.hashCode().toLong()
return (countIndex.toLong() shl 32) or user.hashCode().toLong()
}
else -> {
return Integer.MAX_VALUE.toLong() + getItemViewType(position)
return (countIndex.toLong() shl 32) or getItemViewType(position).toLong()
}
}
}