Skip to content

Commit

Permalink
NT-1962:UX – Show removed comments && NT-2024 && NT-2025 (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadia committed Jun 8, 2021
1 parent b7239fe commit d982362
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface PaginatedViewModelOutput<T> {
fun updatePaginatedState(enabled: Boolean)
fun updatePaginatedData(loadingType: LoadingType, data: List<T>?) {
if (loadingType != LoadingType.LOAD_MORE) {
loadMoreListData = mutableListOf()
updatePaginatedState(true)
}
if (data?.isEmpty() == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.kickstarter.databinding.ActivityCommentsLayoutBinding
import com.kickstarter.libs.BaseActivity
import com.kickstarter.libs.loadmore.PaginationHandler
import com.kickstarter.libs.qualifiers.RequiresActivityViewModel
import com.kickstarter.libs.utils.ApplicationUtils
import com.kickstarter.libs.utils.UrlUtils
import com.kickstarter.models.Comment
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.adapters.CommentsAdapter
Expand Down Expand Up @@ -70,23 +72,17 @@ class CommentsActivity :
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::setEmptyState)

viewModel.outputs.insertComment()
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
adapter.insertData(it, 0)
}

/*
* A little delay after new item is inserted
* This is necessary for the scroll to take effect
*/
viewModel.outputs.insertComment()
viewModel.outputs.scrollToTop()
.filter { it == true }
.compose(bindToLifecycle())
.delay(200, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
binding.commentsRecyclerView.scrollToPosition(0)
binding.commentsRecyclerView.smoothScrollToPosition(0)
}

binding.commentComposer.setCommentComposerActionClickListener(object : OnCommentComposerViewClickedListener {
Expand All @@ -95,6 +91,13 @@ class CommentsActivity :
hideKeyboard()
}
})

viewModel.outputs.showCommentGuideLinesLink()
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
ApplicationUtils.openUrlExternally(this, UrlUtils.appendPath(environment().webEndpoint(), COMMENT_KICKSTARTER_GUIDELINES))
}
}

private fun setupPagination() {
Expand Down Expand Up @@ -166,6 +169,7 @@ class CommentsActivity :
}

override fun onCommentGuideLinesClicked(comment: Comment) {
viewModel.inputs.onShowGuideLinesLinkClicked()
}

override fun onCommentRepliesClicked(comment: Comment) {
Expand Down Expand Up @@ -199,4 +203,8 @@ class CommentsActivity :
super.onDestroy()
binding.commentsRecyclerView.adapter = null
}

companion object {
const val COMMENT_KICKSTARTER_GUIDELINES = "help/community"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ class CommentsAdapter(private val delegate: Delegate) : KSListAdapter() {
submitList(items())
}

fun insertData(comment: CommentCardData, position: Int) {
val list = currentList.toMutableList()
list.add(
position,
comment
)
takeData(list as List<CommentCardData>)
}

override fun viewHolder(@LayoutRes layout: Int, viewGroup: ViewGroup): KSViewHolder {
return CommentCardViewHolder(ItemCommentCardBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false), delegate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,20 @@ interface CommentsViewHolderViewModel {
private val optimizely: ExperimentsClientType = environment.optimizely()
private val apolloClient: ApolloClientType = environment.apolloClient()
init {
this.commentInput
val updatedCommentedCard = this.commentInput
.filter { ObjectUtils.isNotNull(it) }
.map {
val commentCardState = cardStatus(it)
it.toBuilder().commentCardState(commentCardState?.commentCardStatus ?: 0).build()
}

updatedCommentedCard
.compose(bindToLifecycle())
.subscribe {
this.commentCardStatus.onNext(cardStatus(it))
}

this.commentInput
updatedCommentedCard
.compose(Transformers.combineLatestPair(environment.currentUser().observable()))
.compose(bindToLifecycle())
.subscribe {
Expand Down Expand Up @@ -198,7 +204,7 @@ interface CommentsViewHolderViewModel {
}

Observable
.combineLatest(commentData, postNewComment) { commentData, _ ->
.combineLatest(postNewComment, commentData) { _, commentData ->
return@combineLatest executePostCommentMutation(commentData)
}
.switchMap {
Expand All @@ -208,7 +214,7 @@ interface CommentsViewHolderViewModel {
}

Observable
.combineLatest(commentData, onRetryViewClicked) { commentData, _ ->
.combineLatest(onRetryViewClicked, commentData) { _, commentData ->
return@combineLatest executePostCommentMutation(commentData)
}
.switchMap {
Expand Down
Loading

0 comments on commit d982362

Please sign in to comment.