Refine GalleryCommentList nullability and immutability
This commit is contained in:
1 parent
7d16ad2119
commit
7abeba8b87
2 files changed
+16
-18
No files matched your search
@@ -20,8 +20,6 @@ import kotlinx.parcelize.Parcelize
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class GalleryCommentList(
|
class GalleryCommentList(
|
||||||
@JvmField
|
var comments: Array<GalleryComment>,
|
||||||
var comments: Array<GalleryComment>?,
|
val hasMore: Boolean,
|
||||||
@JvmField
|
|
||||||
var hasMore: Boolean,
|
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -341,12 +341,12 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun hideComment(position: Int) {
|
private fun hideComment(position: Int) {
|
||||||
if (mGalleryDetail == null || mGalleryDetail!!.comments.comments == null) {
|
if (mGalleryDetail == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val oldCommentsList = mGalleryDetail!!.comments.comments
|
val oldCommentsList = mGalleryDetail!!.comments.comments
|
||||||
val newCommentsList = arrayOfNulls<GalleryComment>(
|
val newCommentsList = arrayOfNulls<GalleryComment>(
|
||||||
oldCommentsList!!.size - 1,
|
oldCommentsList.size - 1,
|
||||||
)
|
)
|
||||||
var i = 0
|
var i = 0
|
||||||
var j = 0
|
var j = 0
|
||||||
@@ -423,10 +423,10 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
|||||||
|
|
||||||
private fun showCommentDialog(position: Int, text: CharSequence) {
|
private fun showCommentDialog(position: Int, text: CharSequence) {
|
||||||
val context = context
|
val context = context
|
||||||
if (context == null || mGalleryDetail == null || mGalleryDetail!!.comments.comments == null || position >= mGalleryDetail!!.comments.comments!!.size || position < 0) {
|
if (context == null || mGalleryDetail == null || position >= mGalleryDetail!!.comments.comments.size || position < 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val comment = mGalleryDetail!!.comments.comments!![position]
|
val comment = mGalleryDetail!!.comments.comments[position]
|
||||||
val menu: MutableList<String> = ArrayList()
|
val menu: MutableList<String> = ArrayList()
|
||||||
val menuId = IntList()
|
val menuId = IntList()
|
||||||
val resources = context.resources
|
val resources = context.resources
|
||||||
@@ -517,7 +517,7 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
|||||||
if (null == mViewTransition) {
|
if (null == mViewTransition) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (mGalleryDetail == null || mGalleryDetail!!.comments.comments == null || mGalleryDetail!!.comments.comments!!.isEmpty()) {
|
if (mGalleryDetail == null || mGalleryDetail!!.comments.comments.isEmpty()) {
|
||||||
mViewTransition!!.showView(1, animation)
|
mViewTransition!!.showView(1, animation)
|
||||||
} else {
|
} else {
|
||||||
mViewTransition!!.showView(0, animation)
|
mViewTransition!!.showView(0, animation)
|
||||||
@@ -748,14 +748,14 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onVoteCommentSuccess(result: VoteCommentParser.Result) {
|
private fun onVoteCommentSuccess(result: VoteCommentParser.Result) {
|
||||||
if (mAdapter == null || mGalleryDetail!!.comments.comments == null) {
|
if (mAdapter == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var position = -1
|
var position = -1
|
||||||
var i = 0
|
var i = 0
|
||||||
val n = mGalleryDetail!!.comments.comments!!.size
|
val n = mGalleryDetail!!.comments.comments.size
|
||||||
while (i < n) {
|
while (i < n) {
|
||||||
val comment = mGalleryDetail!!.comments.comments!![i]
|
val comment = mGalleryDetail!!.comments.comments[i]
|
||||||
if (comment.id == result.id) {
|
if (comment.id == result.id) {
|
||||||
position = i
|
position = i
|
||||||
break
|
break
|
||||||
@@ -768,7 +768,7 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update comment
|
// Update comment
|
||||||
val comment = mGalleryDetail!!.comments.comments!![position]
|
val comment = mGalleryDetail!!.comments.comments[position]
|
||||||
comment.score = result.score
|
comment.score = result.score
|
||||||
if (result.expectVote > 0) {
|
if (result.expectVote > 0) {
|
||||||
comment.voteUpEd = 0 != result.vote
|
comment.voteUpEd = 0 != result.vote
|
||||||
@@ -899,22 +899,22 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
|||||||
holder.itemView.isClickable = true
|
holder.itemView.isClickable = true
|
||||||
holder.itemView.isFocusable = true
|
holder.itemView.isFocusable = true
|
||||||
if (holder is ActualCommentHolder) {
|
if (holder is ActualCommentHolder) {
|
||||||
holder.bind(mGalleryDetail!!.comments.comments!![position])
|
holder.bind(mGalleryDetail!!.comments.comments[position])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return if (mGalleryDetail == null || mGalleryDetail!!.comments.comments == null) {
|
return if (mGalleryDetail == null) {
|
||||||
0
|
0
|
||||||
} else if (mGalleryDetail!!.comments.hasMore) {
|
} else if (mGalleryDetail!!.comments.hasMore) {
|
||||||
mGalleryDetail!!.comments.comments!!.size + 1
|
mGalleryDetail!!.comments.comments.size + 1
|
||||||
} else {
|
} else {
|
||||||
mGalleryDetail!!.comments.comments!!.size
|
mGalleryDetail!!.comments.comments.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return if (position >= mGalleryDetail!!.comments.comments!!.size) {
|
return if (position >= mGalleryDetail!!.comments.comments.size) {
|
||||||
if (mRefreshingComments) TYPE_PROGRESS else TYPE_MORE
|
if (mRefreshingComments) TYPE_PROGRESS else TYPE_MORE
|
||||||
} else {
|
} else {
|
||||||
TYPE_COMMENT
|
TYPE_COMMENT
|
||||||
|
|||||||
Reference in new issue
Block a user