fixed adapter return statement
This commit is contained in:
parent
a65243ad38
commit
ef1c334200
|
@ -1 +1 @@
|
|||
7145b54190aa590162fb78938d8278574431620f
|
||||
816ae2ac6d6d6a87e486ece0709de3093583e647
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.mariotaku.twidere.annotation.PreviewStyle
|
|||
import org.mariotaku.twidere.constant.linkHighlightOptionKey
|
||||
import org.mariotaku.twidere.constant.mediaPreviewStyleKey
|
||||
import org.mariotaku.twidere.constant.nameFirstKey
|
||||
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
|
||||
import org.mariotaku.twidere.extension.model.timestamp
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.ParcelableMessage.MessageType
|
||||
|
@ -141,23 +142,22 @@ class MessagesConversationAdapter(
|
|||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
when (itemCounts.getItemCountIndex(position)) {
|
||||
ITEM_START_MESSAGE -> {
|
||||
when (getMessage(position, reuse = true).message_type) {
|
||||
MessageType.STICKER -> {
|
||||
return ITEM_TYPE_STICKER_MESSAGE
|
||||
}
|
||||
MessageType.CONVERSATION_CREATE, MessageType.JOIN_CONVERSATION,
|
||||
MessageType.PARTICIPANTS_LEAVE, MessageType.PARTICIPANTS_JOIN,
|
||||
MessageType.CONVERSATION_NAME_UPDATE, MessageType.CONVERSATION_AVATAR_UPDATE -> {
|
||||
return ITEM_TYPE_NOTICE_MESSAGE
|
||||
}
|
||||
else -> return ITEM_TYPE_TEXT_MESSAGE
|
||||
val countIndex = itemCounts.getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
ITEM_START_MESSAGE -> when (getMessage(position, reuse = true).message_type) {
|
||||
MessageType.STICKER -> {
|
||||
return ITEM_TYPE_STICKER_MESSAGE
|
||||
}
|
||||
MessageType.CONVERSATION_CREATE, MessageType.JOIN_CONVERSATION,
|
||||
MessageType.PARTICIPANTS_LEAVE, MessageType.PARTICIPANTS_JOIN,
|
||||
MessageType.CONVERSATION_NAME_UPDATE, MessageType.CONVERSATION_AVATAR_UPDATE -> {
|
||||
return ITEM_TYPE_NOTICE_MESSAGE
|
||||
}
|
||||
else -> return ITEM_TYPE_TEXT_MESSAGE
|
||||
}
|
||||
ITEM_START_LOAD_OLDER -> return ITEM_LOAD_OLDER_INDICATOR
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun getMessage(position: Int, reuse: Boolean = false): ParcelableMessage {
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.mariotaku.library.objectcursor.ObjectCursor
|
|||
import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.constant.nameFirstKey
|
||||
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
|
||||
import org.mariotaku.twidere.model.ItemCounts
|
||||
import org.mariotaku.twidere.model.ParcelableMessageConversation
|
||||
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder
|
||||
|
@ -76,11 +77,12 @@ class MessagesEntriesAdapter(
|
|||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
when (itemCounts.getItemCountIndex(position)) {
|
||||
val countIndex = itemCounts.getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
0 -> return ITEM_TYPE_MESSAGE_ENTRY
|
||||
1 -> return ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
private fun updateItemCounts() {
|
||||
|
|
|
@ -43,10 +43,11 @@ import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter
|
|||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.annotation.Referral
|
||||
import org.mariotaku.twidere.constant.newDocumentApiKey
|
||||
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
|
||||
import org.mariotaku.twidere.extension.model.activityStatus
|
||||
import org.mariotaku.twidere.fragment.CursorActivitiesFragment
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.util.ParcelableActivityUtils
|
||||
import org.mariotaku.twidere.extension.model.activityStatus
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
|
||||
import org.mariotaku.twidere.util.IntentUtils
|
||||
import org.mariotaku.twidere.util.JsonSerializer
|
||||
|
@ -241,7 +242,8 @@ class ParcelableActivitiesAdapter(
|
|||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
when (getItemCountIndex(position)) {
|
||||
val countIndex = getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
ITEM_INDEX_ACTIVITY -> {
|
||||
if (isGapItem(position)) {
|
||||
return ITEM_VIEW_TYPE_GAP
|
||||
|
@ -270,8 +272,8 @@ class ParcelableActivitiesAdapter(
|
|||
ITEM_INDEX_LOAD_MORE_INDICATOR -> {
|
||||
return ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
}
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun addGapLoadingId(id: ObjectId) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
|
|||
import org.mariotaku.twidere.annotation.PreviewStyle
|
||||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_DISPLAY_SENSITIVE_CONTENTS
|
||||
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
|
||||
import org.mariotaku.twidere.model.ItemCounts
|
||||
import org.mariotaku.twidere.model.ObjectId
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
|
@ -334,25 +335,24 @@ abstract class ParcelableStatusesAdapter(
|
|||
if (position == 0 && ILoadMoreSupportAdapter.START in loadMoreIndicatorPosition) {
|
||||
return ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
}
|
||||
when (getItemCountIndex(position)) {
|
||||
val countIndex = getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
ITEM_INDEX_LOAD_START_INDICATOR, ITEM_INDEX_LOAD_END_INDICATOR -> {
|
||||
return ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
}
|
||||
ITEM_INDEX_PINNED_STATUS -> {
|
||||
return VIEW_TYPE_STATUS
|
||||
}
|
||||
ITEM_INDEX_STATUS -> {
|
||||
if (isGapItem(position)) {
|
||||
return ITEM_VIEW_TYPE_GAP
|
||||
} else {
|
||||
return VIEW_TYPE_STATUS
|
||||
}
|
||||
ITEM_INDEX_STATUS -> return if (isGapItem(position)) {
|
||||
ITEM_VIEW_TYPE_GAP
|
||||
} else {
|
||||
VIEW_TYPE_STATUS
|
||||
}
|
||||
ITEM_INDEX_FILTER_HEADER -> {
|
||||
return VIEW_TYPE_FILTER_HEADER
|
||||
}
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw AssertionError()
|
||||
}
|
||||
|
||||
protected abstract fun onCreateStatusViewHolder(parent: ViewGroup): IStatusViewHolder
|
||||
|
|
|
@ -28,6 +28,8 @@ import com.bumptech.glide.RequestManager
|
|||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.Companion.ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
|
||||
import org.mariotaku.twidere.model.ItemCounts
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
@ -71,7 +73,7 @@ class SelectableUsersAdapter(
|
|||
val holder = SelectableUserViewHolder(view, this)
|
||||
return holder
|
||||
}
|
||||
ILoadMoreSupportAdapter.ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
ITEM_VIEW_TYPE_LOAD_INDICATOR -> {
|
||||
val view = inflater.inflate(R.layout.list_item_load_indicator, parent, false)
|
||||
return LoadIndicatorViewHolder(view)
|
||||
}
|
||||
|
@ -90,19 +92,20 @@ class SelectableUsersAdapter(
|
|||
override fun getItemViewType(position: Int): Int {
|
||||
val countIndex = itemCounts.getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
ITEM_TYPE_START_INDICATOR, ITEM_TYPE_END_INDICATOR -> ILoadMoreSupportAdapter.ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
ITEM_TYPE_START_INDICATOR, ITEM_TYPE_END_INDICATOR -> return ITEM_VIEW_TYPE_LOAD_INDICATOR
|
||||
ITEM_TYPE_USER -> return ITEM_VIEW_TYPE_USER
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw UnsupportedOperationException("Unsupported countIndex $countIndex, position $position")
|
||||
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
val countIndex = itemCounts.getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
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()
|
||||
return when (countIndex) {
|
||||
ITEM_TYPE_START_INDICATOR, ITEM_TYPE_END_INDICATOR -> (countIndex.toLong() shl 32)
|
||||
ITEM_TYPE_USER -> (countIndex.toLong() shl 32) or getUser(position).hashCode().toLong()
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw UnsupportedOperationException("Unsupported countIndex $countIndex, position $position")
|
||||
}
|
||||
|
||||
private fun bindUser(holder: SelectableUserViewHolder, position: Int) {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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.exception
|
||||
|
||||
class UnsupportedCountIndexException(countIndex: Int, position: Int) :
|
||||
UnsupportedOperationException("Unsupported countIndex $countIndex, position $position")
|
|
@ -76,6 +76,7 @@ import org.mariotaku.twidere.constant.IntentConstants
|
|||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.constant.nameFirstKey
|
||||
import org.mariotaku.twidere.constant.profileImageStyleKey
|
||||
import org.mariotaku.twidere.exception.UnsupportedCountIndexException
|
||||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.extension.getDirectMessageMaxParticipants
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
|
@ -572,14 +573,15 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
|
|||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
when (itemCounts.getItemCountIndex(position)) {
|
||||
val countIndex = itemCounts.getItemCountIndex(position)
|
||||
when (countIndex) {
|
||||
ITEM_INDEX_TOP_SPACE -> return VIEW_TYPE_TOP_SPACE
|
||||
ITEM_INDEX_HEADER -> return VIEW_TYPE_HEADER
|
||||
ITEM_INDEX_ITEM -> return VIEW_TYPE_USER
|
||||
ITEM_INDEX_ADD_USER -> return VIEW_TYPE_ADD_USER
|
||||
ITEM_INDEX_SPACE -> return VIEW_TYPE_BOTTOM_SPACE
|
||||
else -> throw UnsupportedCountIndexException(countIndex, position)
|
||||
}
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
|
|
Loading…
Reference in New Issue