Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableStatusesAdapter.kt

542 lines
21 KiB
Kotlin
Raw Normal View History

2016-06-29 15:47:52 +02:00
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 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.adapter
import android.content.Context
import android.database.CursorIndexOutOfBoundsException
2017-05-21 17:12:53 +02:00
import android.util.SparseBooleanArray
2016-06-29 15:47:52 +02:00
import android.view.LayoutInflater
import android.view.ViewGroup
2020-06-02 11:15:34 +02:00
import androidx.legacy.widget.Space
import androidx.recyclerview.widget.RecyclerView
2017-03-01 15:12:25 +01:00
import com.bumptech.glide.RequestManager
2017-01-07 07:16:02 +01:00
import org.mariotaku.kpreferences.get
2017-03-23 15:22:07 +01:00
import org.mariotaku.ktextension.*
2016-06-29 15:47:52 +02:00
import org.mariotaku.library.objectcursor.ObjectCursor
import org.mariotaku.twidere.R
import org.mariotaku.twidere.adapter.iface.IGapSupportedAdapter
2016-12-06 04:08:56 +01:00
import org.mariotaku.twidere.adapter.iface.IGapSupportedAdapter.Companion.ITEM_VIEW_TYPE_GAP
2016-08-19 16:25:27 +02:00
import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter
2016-06-29 15:47:52 +02:00
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
2016-12-06 04:08:56 +01:00
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.Companion.ITEM_VIEW_TYPE_LOAD_INDICATOR
2016-06-29 15:47:52 +02:00
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
import org.mariotaku.twidere.annotation.PreviewStyle
import org.mariotaku.twidere.constant.*
2017-01-07 07:16:02 +01:00
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_DISPLAY_SENSITIVE_CONTENTS
2017-05-16 04:20:46 +02:00
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
import org.mariotaku.twidere.model.ItemCounts
import org.mariotaku.twidere.model.ObjectId
import org.mariotaku.twidere.model.ParcelableStatus
import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.timeline.TimelineFilter
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
2016-06-29 15:47:52 +02:00
import org.mariotaku.twidere.util.StatusAdapterLinkClickHandler
import org.mariotaku.twidere.util.TwidereLinkify
import org.mariotaku.twidere.util.Utils
import org.mariotaku.twidere.view.holder.EmptyViewHolder
import org.mariotaku.twidere.view.holder.GapViewHolder
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder
import org.mariotaku.twidere.view.holder.TimelineFilterHeaderViewHolder
2016-06-29 15:47:52 +02:00
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder
2016-12-06 04:08:56 +01:00
import java.util.*
2016-06-29 15:47:52 +02:00
/**
* Created by mariotaku on 15/10/26.
*/
abstract class ParcelableStatusesAdapter(
2017-03-01 15:12:25 +01:00
context: Context,
2017-03-02 07:59:19 +01:00
requestManager: RequestManager
) : LoadMoreSupportAdapter<RecyclerView.ViewHolder>(context, requestManager),
IStatusesAdapter<List<ParcelableStatus>>, IItemCountsAdapter {
2016-08-18 15:02:49 +02:00
2017-01-07 07:16:02 +01:00
protected val inflater: LayoutInflater = LayoutInflater.from(context)
2016-08-18 15:02:49 +02:00
2016-08-19 16:25:27 +02:00
final override val twidereLinkify: TwidereLinkify
@PreviewStyle
2017-01-07 07:16:02 +01:00
final override val mediaPreviewStyle: Int = preferences[mediaPreviewStyleKey]
final override val nameFirst: Boolean = preferences[nameFirstKey]
final override val useStarsForLikes: Boolean = preferences[iWantMyStarsBackKey]
@TwidereLinkify.HighlightStyle
final override val linkHighlightingStyle: Int = preferences[linkHighlightOptionKey]
final override val lightFont: Boolean = preferences[lightFontKey]
final override val mediaPreviewEnabled: Boolean = Utils.isMediaPreviewEnabled(context, preferences)
final override val sensitiveContentEnabled: Boolean = preferences.getBoolean(KEY_DISPLAY_SENSITIVE_CONTENTS, false)
2017-01-07 07:16:02 +01:00
private val showCardActions: Boolean = !preferences[hideCardActionsKey]
2020-05-14 09:47:36 +02:00
private val showCardNumbers: Boolean = !preferences[hideCardNumbersKey]
2020-06-02 11:15:34 +02:00
private val showLinkPreview: Boolean = preferences[showLinkPreviewKey]
2016-06-29 15:47:52 +02:00
2016-12-06 04:08:56 +01:00
private val gapLoadingIds: MutableSet<ObjectId> = HashSet()
override var statusClickListener: IStatusViewHolder.StatusClickListener? = null
2016-06-29 15:47:52 +02:00
override val gapClickListener: IGapSupportedAdapter.GapClickListener?
get() = statusClickListener
override var showAccountsColor: Boolean = false
set(value) {
if (field == value) return
field = value
notifyDataSetChanged()
}
var isShowInReplyTo: Boolean = false
set(value) {
if (field == value) return
field = value
notifyDataSetChanged()
}
2016-08-18 15:02:49 +02:00
2016-08-19 16:25:27 +02:00
var pinnedStatuses: List<ParcelableStatus>? = null
set(value) {
field = value
value?.forEach { it.is_pinned_status = true }
2017-02-28 07:35:31 +01:00
updateItemCount()
2016-08-19 16:25:27 +02:00
notifyDataSetChanged()
}
var timelineFilter: TimelineFilter? = null
set(value) {
field = value
notifyDataSetChanged()
}
2016-06-29 15:47:52 +02:00
private var data: List<ParcelableStatus>? = null
2017-02-28 07:35:31 +01:00
private var displayPositions: IntArray? = null
private var displayDataCount: Int = 0
2016-06-29 15:47:52 +02:00
private var showingActionCardId = RecyclerView.NO_ID
2017-05-21 17:12:53 +02:00
private val showingFullTextStates = SparseBooleanArray()
2017-04-28 15:44:45 +02:00
private val reuseStatus = ParcelableStatus()
2017-05-18 17:20:42 +02:00
private var infoCache: Array<StatusInfo?>? = null
2016-06-29 15:47:52 +02:00
override val itemCounts = ItemCounts(5)
2016-08-19 16:25:27 +02:00
2017-02-28 07:35:31 +01:00
val statusStartIndex: Int
get() = getItemStartPosition(ITEM_INDEX_STATUS)
override var loadMoreIndicatorPosition: Long
get() = super.loadMoreIndicatorPosition
set(value) {
super.loadMoreIndicatorPosition = value
updateItemCount()
}
override var loadMoreSupportedPosition: Long
get() = super.loadMoreSupportedPosition
set(value) {
super.loadMoreSupportedPosition = value
updateItemCount()
}
2016-06-29 15:47:52 +02:00
init {
val handler = StatusAdapterLinkClickHandler<List<ParcelableStatus>>(context, preferences)
twidereLinkify = TwidereLinkify(handler)
handler.setAdapter(this)
isShowInReplyTo = true
setHasStableIds(true)
}
override fun isGapItem(position: Int): Boolean {
2017-06-01 11:37:51 +02:00
return getFieldValue(position, { info ->
return@getFieldValue info.gap
}, { status ->
return@getFieldValue status.is_gap
}, false)
2016-06-29 15:47:52 +02:00
}
override fun getStatus(position: Int, raw: Boolean): ParcelableStatus {
2017-05-02 12:01:23 +02:00
return getStatusInternal(position, getItemCountIndex(position, raw), raw, reuse = false)
2016-06-29 15:47:52 +02:00
}
override fun getStatusCount(raw: Boolean): Int {
if (raw) return data?.size ?: 0
return displayDataCount
}
2016-06-29 15:47:52 +02:00
2017-02-28 07:35:31 +01:00
override fun setData(data: List<ParcelableStatus>?): Boolean {
var changed = true
2020-06-09 02:21:48 +02:00
when (data) {
null -> {
displayPositions = null
displayDataCount = 0
}
is ObjectCursor -> {
displayPositions = null
displayDataCount = data.size
}
else -> {
var filteredCount = 0
displayPositions = IntArray(data.size).apply {
data.forEachIndexed { i, item ->
if (!item.is_gap && item.is_filtered) {
filteredCount++
} else {
this[i - filteredCount] = i
}
2017-02-28 07:35:31 +01:00
}
}
2020-06-09 02:21:48 +02:00
displayDataCount = data.size - filteredCount
changed = this.data != data
2017-02-28 07:35:31 +01:00
}
}
this.data = data
2017-07-16 08:09:46 +02:00
this.infoCache = if (data != null) arrayOfNulls(data.size) else null
2017-02-28 07:35:31 +01:00
gapLoadingIds.clear()
updateItemCount()
notifyDataSetChanged()
return changed
}
fun getData(): List<ParcelableStatus>? {
return data
}
2016-06-29 15:47:52 +02:00
override fun getItemId(position: Int): Long {
2017-02-28 07:35:31 +01:00
val countIndex = getItemCountIndex(position)
2017-05-18 17:20:42 +02:00
return (countIndex.toLong() shl 32) or when (countIndex) {
2017-02-28 07:35:31 +01:00
ITEM_INDEX_PINNED_STATUS -> {
val status = pinnedStatuses!![position - getItemStartPosition(ITEM_INDEX_PINNED_STATUS)]
2017-05-18 17:20:42 +02:00
return status.hashCode().toLong()
2017-02-28 07:35:31 +01:00
}
2017-05-18 17:20:42 +02:00
ITEM_INDEX_STATUS -> getFieldValue(position, { (_, accountKey, id) ->
return@getFieldValue ParcelableStatus.calculateHashCode(accountKey, id)
2017-02-28 07:35:31 +01:00
}, { status ->
return@getFieldValue status.hashCode()
}, -1).toLong()
2017-05-18 17:20:42 +02:00
else -> position.toLong()
2017-02-28 07:35:31 +01:00
}
2016-06-29 15:47:52 +02:00
}
override fun getStatusId(position: Int, raw: Boolean): String {
2017-05-18 17:20:42 +02:00
return getFieldValue(position, { info ->
return@getFieldValue info.id
}, { status ->
return@getFieldValue status.id
}, "")
}
2017-03-23 15:22:07 +01:00
fun getStatusSortId(position: Int, raw: Boolean): Long {
2017-05-18 17:20:42 +02:00
return getFieldValue(position, { info ->
return@getFieldValue info.sortId
}, { status ->
return@getFieldValue status.sort_id
2017-03-23 15:22:07 +01:00
}, -1L, raw)
2016-06-29 15:47:52 +02:00
}
override fun getStatusTimestamp(position: Int, raw: Boolean): Long {
2017-05-18 17:20:42 +02:00
return getFieldValue(position, { info ->
return@getFieldValue info.timestamp
}, { status ->
return@getFieldValue status.timestamp
}, -1L)
2016-06-29 15:47:52 +02:00
}
override fun getStatusPositionKey(position: Int, raw: Boolean): Long {
2017-05-18 17:20:42 +02:00
return getFieldValue(position, { info ->
if (info.positionKey > 0) return@getFieldValue info.positionKey
return@getFieldValue info.timestamp
}, { status ->
val positionKey = status.position_key
if (positionKey > 0) return@getFieldValue positionKey
return@getFieldValue status.timestamp
}, -1L)
2016-06-29 15:47:52 +02:00
}
override fun getAccountKey(position: Int, raw: Boolean): UserKey {
2017-02-28 07:35:31 +01:00
val def: UserKey? = null
2017-05-18 17:20:42 +02:00
return getFieldValue(position, { info ->
return@getFieldValue info.accountKey
2017-02-28 07:35:31 +01:00
}, { status ->
return@getFieldValue status.account_key
}, def, raw)!!
2016-06-29 15:47:52 +02:00
}
2020-05-14 09:47:36 +02:00
override fun isCardNumbersShown(position: Int): Boolean {
if (position == RecyclerView.NO_POSITION) return showCardNumbers
return showCardNumbers || showingActionCardId == getItemId(position)
}
2020-06-02 11:15:34 +02:00
override fun isLinkPreviewShown(position: Int): Boolean {
return showLinkPreview
}
2016-06-29 15:47:52 +02:00
override fun isCardActionsShown(position: Int): Boolean {
if (position == RecyclerView.NO_POSITION) return showCardActions
return showCardActions || showingActionCardId == getItemId(position)
}
override fun showCardActions(position: Int) {
if (showingActionCardId != RecyclerView.NO_ID) {
val pos = findPositionByItemId(showingActionCardId)
if (pos != RecyclerView.NO_POSITION) {
notifyItemChanged(pos)
}
}
showingActionCardId = getItemId(position)
if (position != RecyclerView.NO_POSITION) {
notifyItemChanged(position)
}
}
2017-05-21 17:12:53 +02:00
override fun isFullTextVisible(position: Int): Boolean {
return showingFullTextStates.get(position)
}
override fun setFullTextVisible(position: Int, visible: Boolean) {
showingFullTextStates.put(position, visible)
if (position != RecyclerView.NO_POSITION) {
notifyItemChanged(position)
}
}
2016-06-29 15:47:52 +02:00
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
when (viewType) {
2016-12-06 04:08:56 +01:00
ITEM_VIEW_TYPE_GAP -> {
val view = inflater.inflate(GapViewHolder.layoutResource, parent, false)
2016-06-29 15:47:52 +02:00
return GapViewHolder(this, view)
}
2016-12-06 04:08:56 +01:00
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
2017-01-31 14:10:20 +01:00
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
2016-06-29 15:47:52 +02:00
return LoadIndicatorViewHolder(view)
}
VIEW_TYPE_STATUS -> {
return onCreateStatusViewHolder(parent) as RecyclerView.ViewHolder
}
2017-02-28 07:35:31 +01:00
VIEW_TYPE_EMPTY -> {
2016-06-29 15:47:52 +02:00
return EmptyViewHolder(Space(context))
}
VIEW_TYPE_FILTER_HEADER -> {
val view = inflater.inflate(TimelineFilterHeaderViewHolder.layoutResource,
parent, false)
return TimelineFilterHeaderViewHolder(this, view)
}
2016-06-29 15:47:52 +02:00
}
2020-06-08 23:07:20 +02:00
throw IllegalStateException("Unknown view type $viewType")
2016-06-29 15:47:52 +02:00
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
2017-02-28 07:35:31 +01:00
when (holder.itemViewType) {
VIEW_TYPE_STATUS -> {
2017-04-28 15:44:45 +02:00
val countIndex: Int = getItemCountIndex(position)
val status = getStatusInternal(position, countIndex = countIndex, reuse = true)
(holder as IStatusViewHolder).display(status, displayInReplyTo = isShowInReplyTo,
2017-04-28 15:44:45 +02:00
displayPinned = countIndex == ITEM_INDEX_PINNED_STATUS)
2016-08-19 16:25:27 +02:00
}
VIEW_TYPE_FILTER_HEADER -> {
(holder as TimelineFilterHeaderViewHolder).display(timelineFilter!!)
}
2017-02-28 07:35:31 +01:00
ITEM_VIEW_TYPE_GAP -> {
2017-04-28 15:44:45 +02:00
val status = getStatusInternal(position, reuse = true)
2017-02-28 07:35:31 +01:00
val loading = gapLoadingIds.any { it.accountKey == status.account_key && it.id == status.id }
(holder as GapViewHolder).display(loading)
2016-06-29 15:47:52 +02:00
}
}
2016-12-06 04:08:56 +01:00
}
2016-06-29 15:47:52 +02:00
override fun getItemViewType(position: Int): Int {
if (position == 0 && ILoadMoreSupportAdapter.START in loadMoreIndicatorPosition) {
2016-12-06 04:08:56 +01:00
return ITEM_VIEW_TYPE_LOAD_INDICATOR
2016-06-29 15:47:52 +02:00
}
2020-06-08 23:09:07 +02:00
when (val countIndex = getItemCountIndex(position)) {
2017-02-28 07:35:31 +01:00
ITEM_INDEX_LOAD_START_INDICATOR, ITEM_INDEX_LOAD_END_INDICATOR -> {
2016-12-06 04:08:56 +01:00
return ITEM_VIEW_TYPE_LOAD_INDICATOR
2016-08-19 16:25:27 +02:00
}
2017-02-28 07:35:31 +01:00
ITEM_INDEX_PINNED_STATUS -> {
return VIEW_TYPE_STATUS
2016-08-19 16:25:27 +02:00
}
2017-05-16 04:20:46 +02:00
ITEM_INDEX_STATUS -> return if (isGapItem(position)) {
ITEM_VIEW_TYPE_GAP
} else {
VIEW_TYPE_STATUS
2016-08-19 16:25:27 +02:00
}
ITEM_INDEX_FILTER_HEADER -> {
return VIEW_TYPE_FILTER_HEADER
}
2017-05-16 04:20:46 +02:00
else -> throw UnsupportedCountIndexException(countIndex, position)
2016-06-29 15:47:52 +02:00
}
}
2017-02-28 07:35:31 +01:00
protected abstract fun onCreateStatusViewHolder(parent: ViewGroup): IStatusViewHolder
override fun addGapLoadingId(id: ObjectId) {
gapLoadingIds.add(id)
}
override fun removeGapLoadingId(id: ObjectId) {
gapLoadingIds.remove(id)
}
2016-06-29 15:47:52 +02:00
override fun getItemCount(): Int {
2017-01-31 14:10:20 +01:00
return itemCounts.itemCount
2016-06-29 15:47:52 +02:00
}
override fun findStatusById(accountKey: UserKey, statusId: String): ParcelableStatus? {
for (i in 0 until getStatusCount(true)) {
if (accountKey == getAccountKey(i, true) && statusId == getStatusId(i, true)) {
return getStatus(i, true)
2016-06-29 15:47:52 +02:00
}
}
return null
}
2017-09-15 09:32:20 +02:00
fun isStatus(position: Int, raw: Boolean = false): Boolean {
return position < getStatusCount(raw)
}
fun getRowId(adapterPosition: Int, raw: Boolean = false): Long {
return getFieldValue(adapterPosition, readInfoValueAction = {
it._id
}, readStatusValueAction = { status ->
status.hashCode().toLong()
}, defValue = -1L, raw = raw)
}
fun findPositionByPositionKey(positionKey: Long, raw: Boolean = false): Int {
2017-02-28 07:35:31 +01:00
// Assume statuses are descend sorted by id, so break at first status with id
// lesser equals than read position
if (positionKey <= 0) return RecyclerView.NO_POSITION
val range = rangeOfSize(statusStartIndex, getStatusCount(raw))
2020-06-08 23:07:20 +02:00
if (range.isEmpty() || range.first < 0) return RecyclerView.NO_POSITION
2017-03-23 15:22:07 +01:00
if (positionKey < getStatusPositionKey(range.last, raw)) {
2017-02-28 07:35:31 +01:00
return range.last
}
2017-03-23 15:22:07 +01:00
return range.indexOfFirst { positionKey >= getStatusPositionKey(it, raw) }
2017-02-28 07:35:31 +01:00
}
fun findPositionBySortId(sortId: Long, raw: Boolean = false): Int {
2017-02-28 07:35:31 +01:00
// Assume statuses are descend sorted by id, so break at first status with id
// lesser equals than read position
if (sortId <= 0) return RecyclerView.NO_POSITION
val range = rangeOfSize(statusStartIndex, getStatusCount(raw))
2020-06-08 23:07:20 +02:00
if (range.isEmpty() || range.first < 0) return RecyclerView.NO_POSITION
2017-03-23 15:22:07 +01:00
if (sortId < getStatusSortId(range.last, raw)) {
2017-02-28 07:35:31 +01:00
return range.last
}
2017-03-23 15:22:07 +01:00
return range.indexOfFirst { sortId >= getStatusSortId(it, raw) }
2017-02-28 07:35:31 +01:00
}
2016-06-29 15:47:52 +02:00
private fun getItemCountIndex(position: Int, raw: Boolean): Int {
if (!raw) return itemCounts.getItemCountIndex(position)
var sum = 0
for (i in 0 until itemCounts.size) {
sum += when (i) {
ITEM_INDEX_STATUS -> data?.size ?: 0
else -> itemCounts[i]
}
if (position < sum) {
return i
}
}
return -1
}
private inline fun <T> getFieldValue(position: Int,
2017-05-18 17:20:42 +02:00
readInfoValueAction: (StatusInfo) -> T,
readStatusValueAction: (status: ParcelableStatus) -> T,
defValue: T, raw: Boolean = false): T {
2017-05-18 17:20:42 +02:00
val data = this.data
if (data is ObjectCursor) {
val dataPosition = position - statusStartIndex
if (dataPosition < 0 || dataPosition >= getStatusCount(true)) {
throw CursorIndexOutOfBoundsException("index: $position, valid range is $0..${getStatusCount(true)}")
}
2017-05-18 17:20:42 +02:00
val info = infoCache?.get(dataPosition) ?: run {
2017-06-01 11:21:34 +02:00
val cursor = data.cursor
if (!cursor.safeMoveToPosition(dataPosition)) return defValue
val indices = data.indices
2017-05-18 17:20:42 +02:00
val _id = cursor.safeGetLong(indices[Statuses._ID])
2017-07-07 10:01:59 +02:00
val accountKey = UserKey.valueOf(cursor.safeGetString(indices[Statuses.ACCOUNT_KEY]))
val id = cursor.safeGetString(indices[Statuses.ID])
2017-05-18 17:20:42 +02:00
val timestamp = cursor.safeGetLong(indices[Statuses.TIMESTAMP])
val sortId = cursor.safeGetLong(indices[Statuses.SORT_ID])
val positionKey = cursor.safeGetLong(indices[Statuses.POSITION_KEY])
2020-04-01 10:10:03 +02:00
val gap = cursor.safeGetInt(indices[Statuses.IS_GAP]) == 1
2017-05-18 17:20:42 +02:00
val newInfo = StatusInfo(_id, accountKey, id, timestamp, sortId, positionKey, gap)
infoCache?.set(dataPosition, newInfo)
return@run newInfo
}
return readInfoValueAction(info)
}
2017-03-15 09:06:55 +01:00
return readStatusValueAction(getStatus(position, raw))
}
2017-04-28 15:44:45 +02:00
private fun getStatusInternal(position: Int, countIndex: Int = getItemCountIndex(position),
2017-05-02 12:01:23 +02:00
raw: Boolean = false, reuse: Boolean): ParcelableStatus {
2017-02-28 07:35:31 +01:00
when (countIndex) {
ITEM_INDEX_PINNED_STATUS -> {
return pinnedStatuses!![position - getItemStartPosition(ITEM_INDEX_PINNED_STATUS)]
}
ITEM_INDEX_STATUS -> {
val data = this.data!!
val dataPosition = position - statusStartIndex
2017-02-28 07:35:31 +01:00
val positions = displayPositions
2017-04-28 15:44:45 +02:00
val listPosition = if (positions != null && !raw) {
positions[dataPosition]
} else {
dataPosition
}
2020-06-08 23:19:10 +02:00
return if (reuse && data is ObjectCursor) {
2017-04-28 15:44:45 +02:00
reuseStatus.is_filtered = false
2020-06-08 23:19:10 +02:00
data.setInto(listPosition, reuseStatus)
2017-02-28 07:35:31 +01:00
} else {
2020-06-08 23:19:10 +02:00
data[listPosition]
2017-02-28 07:35:31 +01:00
}
}
}
val validStart = getItemStartPosition(ITEM_INDEX_PINNED_STATUS)
val validEnd = getItemStartPosition(ITEM_INDEX_STATUS) + getStatusCount(raw) - 1
throw IndexOutOfBoundsException("index: $position, valid range is $validStart..$validEnd")
2016-06-29 15:47:52 +02:00
}
2017-02-28 07:35:31 +01:00
private fun updateItemCount() {
itemCounts[ITEM_INDEX_LOAD_START_INDICATOR] = if (ILoadMoreSupportAdapter.START in loadMoreIndicatorPosition) 1 else 0
itemCounts[ITEM_INDEX_FILTER_HEADER] = if (timelineFilter != null) 1 else 0
2017-02-28 07:35:31 +01:00
itemCounts[ITEM_INDEX_PINNED_STATUS] = pinnedStatuses?.size ?: 0
itemCounts[ITEM_INDEX_STATUS] = getStatusCount(false)
itemCounts[ITEM_INDEX_LOAD_END_INDICATOR] = if (ILoadMoreSupportAdapter.END in loadMoreIndicatorPosition) 1 else 0
2016-06-29 15:47:52 +02:00
}
2017-05-18 17:20:42 +02:00
data class StatusInfo(
val _id: Long,
val accountKey: UserKey,
val id: String,
val timestamp: Long,
val sortId: Long,
val positionKey: Long,
val gap: Boolean
)
2017-02-28 07:35:31 +01:00
companion object {
const val VIEW_TYPE_STATUS = 2
const val VIEW_TYPE_EMPTY = 3
const val VIEW_TYPE_FILTER_HEADER = 4
2017-02-28 07:35:31 +01:00
const val ITEM_INDEX_LOAD_START_INDICATOR = 0
const val ITEM_INDEX_FILTER_HEADER = 1
const val ITEM_INDEX_PINNED_STATUS = 2
const val ITEM_INDEX_STATUS = 3
const val ITEM_INDEX_LOAD_END_INDICATOR = 4
}
2016-08-19 16:25:27 +02:00
2016-06-29 15:47:52 +02:00
}