Skip to content

Commit

Permalink
chore: add 3.20.0 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaing committed Apr 9, 2024
1 parent 49dca08 commit 7480490
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
Expand Down Expand Up @@ -340,4 +341,11 @@ fun setBold(view: TextView, isBold: Boolean) {
@BindingAdapter("amityVisibility")
fun setVisibility(view: View, value: Boolean) {
view.visibility = if (value) View.VISIBLE else View.GONE
}

@BindingAdapter("layoutMarginEnd")
fun setLayoutMarginEnd(view: View, dimen: Float) {
val layoutParams = view.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.marginEnd = dimen.toInt()
view.layoutParams = layoutParams
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PostCommentDiffUtil : DiffUtil.ItemCallback<AmityComment>() {
&& oldItem.getReactionCount() == newItem.getReactionCount()
&& (oldItem.getMyReactions().contains(AmityConstants.POST_REACTION) == oldItem.getMyReactions().contains(AmityConstants.POST_REACTION))
&& oldItem.getEditedAt() == newItem.getEditedAt()
&& oldItem.getState() == newItem.getState()
&& areChildrenTheSame(oldItem.getLatestReplies(), newItem.getLatestReplies())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class AmityCommentCreatorFragment : AmityCommentBaseFragment() {
},
onError = {
if (AmityError.from(it) == AmityError.BAN_WORD_FOUND) {
// TODO: 21/2/23 delete a comment
// viewModel.deleteComment().subscribe()
}
updateCommentMenu(true)
if (viewModel.getReply() != null) {
view?.showSnackBar(getString(R.string.amity_add_reply_error_message))
view?.showSnackBar(getString(R.string.amity_add_blocked_words_comment_error_message))
} else {
view?.showSnackBar(getString(R.string.amity_add_comment_error_message))
if (viewModel.getReply() != null) {
view?.showSnackBar(getString(R.string.amity_add_reply_error_message))
} else {
view?.showSnackBar(getString(R.string.amity_add_comment_error_message))
}
}
updateCommentMenu(true)
})
.subscribe()
addComment.let { disposable.add(addComment) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.amity.socialcloud.uikit.community.newsfeed.fragment

import android.os.Bundle
import android.view.*
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.animation.AnimationUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
Expand All @@ -12,6 +17,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.paging.ExperimentalPagingApi
import androidx.recyclerview.widget.LinearLayoutManager
import com.amity.socialcloud.sdk.model.core.error.AmityError
import com.amity.socialcloud.sdk.model.core.file.AmityImage
import com.amity.socialcloud.sdk.model.social.comment.AmityComment
import com.amity.socialcloud.sdk.model.social.feed.AmityFeedType
Expand Down Expand Up @@ -44,8 +50,7 @@ import com.linkedin.android.spyglass.tokenization.interfaces.QueryTokenReceiver
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.schedulers.Schedulers
import org.amity.types.ObjectId
import java.util.*
import java.util.Random

class AmityPostDetailFragment : AmityBaseFragment(),
SuggestionsVisibilityManager, QueryTokenReceiver {
Expand Down Expand Up @@ -250,10 +255,8 @@ class AmityPostDetailFragment : AmityBaseFragment(),
private fun setupComposeBar(post: AmityPost) {
binding.viewBottom.visibility = if (isJoined(post)) View.VISIBLE else View.INVISIBLE
binding.commentComposeBar.getPostButton().setOnClickListener {
val commentId = ObjectId.get().toHexString()
viewModel.addComment(
replyTo?.getCommentId(),
commentId,
post.getPostId(),
binding.commentComposeBar.getTextCompose(),
binding.commentComposeBar.getCommentEditText().getUserMentions(),
Expand All @@ -262,14 +265,17 @@ class AmityPostDetailFragment : AmityBaseFragment(),
hideReplyTo()
},
onError = {
// To do handle error
},
onBanned = {
if (AmityError.from(it) == AmityError.BAN_WORD_FOUND) {
view?.showSnackBar(getString(R.string.amity_add_blocked_words_comment_error_message))
} else {
if (replyTo != null) {
view?.showSnackBar(getString(R.string.amity_add_reply_error_message))
} else {
view?.showSnackBar(getString(R.string.amity_add_comment_error_message))
}
}
binding.commentComposeBar.getCommentEditText().setText("")
hideReplyTo()
viewModel.deleteComment(commentId, onSuccess = {}, onError = {})
.untilLifecycleEnd(this)
.subscribe()
})
.untilLifecycleEnd(this)
.subscribe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.amity.socialcloud.sdk.api.social.comment.AmityCommentRepository
import com.amity.socialcloud.sdk.api.social.post.AmityPostRepository
import com.amity.socialcloud.sdk.helper.core.mention.AmityMentionMetadata
import com.amity.socialcloud.sdk.helper.core.mention.AmityMentionMetadataCreator
import com.amity.socialcloud.sdk.model.core.error.AmityError
import com.amity.socialcloud.sdk.model.core.user.AmityUser
import com.amity.socialcloud.sdk.model.social.comment.AmityComment
import com.amity.socialcloud.sdk.model.social.member.AmityCommunityMember
Expand Down Expand Up @@ -89,21 +88,10 @@ class AmityCommentViewModel : AmityBaseViewModel() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess(onSuccess)
.doOnError {
if (AmityError.from(it) == AmityError.BAN_WORD_FOUND) {

// TODO: 21/2/23 delete a comment
// viewModel.deleteComment().subscribe()
}
}
.doOnError(onError)
.ignoreElement()
}

fun deleteComment(commentId: String): Completable {
return commentRepository.softDeleteComment(commentId)
}

fun checkForCommentUpdate() {
val commentData = (comment?.getData() as? AmityComment.Data.TEXT)?.getText()
val updateAvailable = !commentText.value.isNullOrBlank() && commentData != commentText.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.amity.socialcloud.sdk.api.core.AmityCoreClient
import com.amity.socialcloud.sdk.api.social.AmitySocialClient
import com.amity.socialcloud.sdk.helper.core.mention.AmityMentionMetadata
import com.amity.socialcloud.sdk.helper.core.mention.AmityMentionMetadataCreator
import com.amity.socialcloud.sdk.model.core.error.AmityError
import com.amity.socialcloud.sdk.model.core.permission.AmityPermission
import com.amity.socialcloud.sdk.model.social.comment.AmityComment
import com.amity.socialcloud.sdk.model.social.post.AmityPost
Expand All @@ -19,13 +18,11 @@ interface CommentViewModel {

fun addComment(
parentId: String?,
commentId: String,
postId: String,
message: String,
userMentions: List<AmityMentionMetadata.USER>,
onSuccess: () -> Unit,
onError: () -> Unit,
onBanned: () -> Unit
onSuccess: (AmityComment) -> Unit,
onError: (Throwable) -> Unit,
): Completable {
val commentCreator = AmitySocialClient.newCommentRepository().createComment()
.post(postId)
Expand All @@ -43,16 +40,9 @@ interface CommentViewModel {
.send()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess {
onSuccess.invoke()
}
.doOnError {
if (AmityError.from(it) == AmityError.BAN_WORD_FOUND) {
onBanned.invoke()
} else {
onError.invoke()
}
}.ignoreElement()
.doOnSuccess(onSuccess)
.doOnError(onError)
.ignoreElement()
}

fun deleteComment(
Expand Down Expand Up @@ -142,10 +132,14 @@ interface CommentViewModel {

if (comment.getCreatorId() == AmityCoreClient.getUserId()) {
if (comment.getParentId() == null) {
items.add(editCommentMenuItem)
if (comment.getState() != AmityComment.State.FAILED) {
items.add(editCommentMenuItem)
}
items.add(deleteCommentMenuItem)
} else {
items.add(editReplyMenuItem)
if (comment.getState() != AmityComment.State.FAILED) {
items.add(editReplyMenuItem)
}
items.add(deleteReplyMenuItem)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AmityPostCommentView : ConstraintLayout {
comment.getCreator()?.getDisplayName() ?: context.getString(R.string.amity_anonymous)
binding.tvCommentTime.text = comment.getCreatedAt().millis.readableFeedPostTime(context)
binding.edited = comment.isEdited()
binding.isFailed = comment.getState() == AmityComment.State.FAILED
binding.isReplyComment = !comment.getParentId().isNullOrEmpty()

val banIcon = if (comment.getCreator()?.isGlobalBan() == true) {
Expand Down Expand Up @@ -142,6 +143,10 @@ class AmityPostCommentView : ConstraintLayout {
commentOptionClickPublisher.onNext(CommentOptionClickEvent(comment))
}

binding.ivCommentSyncFailed.setOnClickListener {
commentOptionClickPublisher.onNext(CommentOptionClickEvent(comment))
}

binding.tvNumberOfReactions.setOnClickListener {
reactionCountClickPublisher.onNext(ReactionCountClickEvent.Comment(comment))
}
Expand Down
30 changes: 27 additions & 3 deletions social/src/main/res/layout/amity_item_comment_news_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<variable
name="isReplyComment"
type="Boolean" />

<variable
name="isFailed"
type="Boolean" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -119,7 +123,7 @@
app:textColorShade="@{AmityColorShade.SHADE1}"
tools:visibility="visible" />

<RelativeLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/comment_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -134,15 +138,35 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/amity_padding_xxs"
android:layout_marginBottom="@dimen/amity_padding_xs"
layoutMarginEnd="@{isFailed ? @dimen/amity_twenty_four : @dimen/amity_zero}"
android:autoLink="web"
android:background="@drawable/amity_bg_comment_bubble"
android:maxLines="@integer/maxLineTextOnlyFeed"
android:padding="@dimen/amity_padding_s"
android:textColor="@color/amityColorBase"
android:textColorLink="@color/amityColorHighlight"
tools:text="orem ipsum dolor sit amet, consectetur" />
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="orem ipsum dolor sit amet" />

</RelativeLayout>
<ImageView
android:id="@+id/ivCommentSyncFailed"
amityTintColor="@{@color/amityColorBase}"
amityTintShade="@{AmityColorShade.SHADE2}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/amity_padding_xxs"
android:layout_marginBottom="@dimen/amity_padding_xs"
android:src="@drawable/amity_ic_error"
android:visibility="@{isFailed ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/tvPostComment"
tools:ignore="ContentDescription" />

</androidx.constraintlayout.widget.ConstraintLayout>


<com.google.android.material.checkbox.MaterialCheckBox
Expand Down
1 change: 1 addition & 0 deletions social/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<string name="amity_general">General</string>
<string name="amity_add_comment_error_message">Unable to add comment</string>
<string name="amity_update_comment_error_message">Unable to update comment</string>
<string name="amity_add_blocked_words_comment_error_message">Your comment wasn’t created as it contained blocked words. Only you can see this</string>
<plurals name="amity_feed_number_of_likes">
<item quantity="one">%s like</item>
<item quantity="other">%s likes</item>
Expand Down

0 comments on commit 7480490

Please sign in to comment.