fixed some recycler view crashes

This commit is contained in:
Mariotaku Lee 2017-05-13 19:40:47 +08:00
parent 90411ff078
commit 9c6a79518d
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
1 changed files with 3 additions and 21 deletions

View File

@ -1417,8 +1417,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
private val cardBackgroundColor: Int private val cardBackgroundColor: Int
private val showCardActions = !preferences[hideCardActionsKey] private val showCardActions = !preferences[hideCardActionsKey]
private var recyclerView: RecyclerView? = null private var recyclerView: RecyclerView? = null
private var detachedStatusViewHolder: DetailStatusViewHolder? = null private var detailMediaExpanded: Boolean = false
private var mDetailMediaExpanded: Boolean = false
var status: ParcelableStatus? = null var status: ParcelableStatus? = null
internal set internal set
@ -1582,7 +1581,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
var isDetailMediaExpanded: Boolean var isDetailMediaExpanded: Boolean
get() { get() {
if (mDetailMediaExpanded) return true if (detailMediaExpanded) return true
if (mediaPreviewEnabled) { if (mediaPreviewEnabled) {
val status = this.status val status = this.status
return status != null && (sensitiveContentEnabled || !status.is_possibly_sensitive) return status != null && (sensitiveContentEnabled || !status.is_possibly_sensitive)
@ -1590,7 +1589,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
return false return false
} }
set(expanded) { set(expanded) {
mDetailMediaExpanded = expanded detailMediaExpanded = expanded
notifyDataSetChanged() notifyDataSetChanged()
updateItemDecoration() updateItemDecoration()
} }
@ -1606,9 +1605,6 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder? { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder? {
when (viewType) { when (viewType) {
VIEW_TYPE_DETAIL_STATUS -> { VIEW_TYPE_DETAIL_STATUS -> {
if (detachedStatusViewHolder != null) {
return detachedStatusViewHolder
}
val view = inflater.inflate(R.layout.header_status, parent, false) val view = inflater.inflate(R.layout.header_status, parent, false)
view.setBackgroundColor(cardBackgroundColor) view.setBackgroundColor(cardBackgroundColor)
return DetailStatusViewHolder(this, view) return DetailStatusViewHolder(this, view)
@ -1692,20 +1688,6 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
} }
} }
override fun onViewDetachedFromWindow(holder: ViewHolder?) {
if (holder is DetailStatusViewHolder) {
detachedStatusViewHolder = holder as DetailStatusViewHolder?
}
super.onViewDetachedFromWindow(holder)
}
override fun onViewAttachedToWindow(holder: ViewHolder?) {
if (holder === detachedStatusViewHolder) {
detachedStatusViewHolder = null
}
super.onViewAttachedToWindow(holder)
}
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int {
return getItemViewTypeByItemType(getItemType(position)) return getItemViewTypeByItemType(getItemType(position))
} }