-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The redesign of comment details content #20798
Changes from 21 commits
8d88bfa
5618cdf
79e0915
65a6bb0
880e609
348774e
5dfac69
8c5d27b
b0be301
c02aace
8ffe0f3
2dd8b4a
912a8d4
c660322
6070f47
5456a99
2ab5cf0
d1bf95b
a752f8a
381bb1d
dc5cbe4
2b82a68
360d311
d04ef21
1b18034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,17 @@ package org.wordpress.android.ui.comments | |
|
||
import android.os.Bundle | ||
import androidx.core.view.isVisible | ||
import com.gravatar.AvatarQueryOptions | ||
import com.gravatar.AvatarUrl | ||
import com.gravatar.types.Email | ||
import org.wordpress.android.R | ||
import org.wordpress.android.fluxc.model.CommentModel | ||
import org.wordpress.android.fluxc.model.SiteModel | ||
import org.wordpress.android.ui.comments.unified.CommentIdentifier | ||
import org.wordpress.android.ui.comments.unified.CommentSource | ||
import org.wordpress.android.ui.engagement.BottomSheetUiState | ||
import org.wordpress.android.ui.reader.tracker.ReaderTracker | ||
import org.wordpress.android.util.WPAvatarUtils | ||
|
||
/** | ||
* Used when called from comment list | ||
|
@@ -23,6 +31,28 @@ class SiteCommentDetailFragment : CommentDetailFragment() { | |
} | ||
} | ||
|
||
override fun getUserProfileUiState(): BottomSheetUiState.UserProfileUiState { | ||
return BottomSheetUiState.UserProfileUiState( | ||
userAvatarUrl = CommentExtension.getAvatarUrl( | ||
mComment!!, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick: I wonder if we should avoid the non-null assertion operator for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I just reviewed the I plan to replace it with
|
||
resources.getDimensionPixelSize(R.dimen.avatar_sz_large) | ||
), | ||
blavatarUrl = "", | ||
userName = mComment!!.authorName ?: getString(R.string.anonymous), | ||
userLogin = mComment!!.authorEmail ?: "", | ||
// keep them empty because there's no data for displaying on UI | ||
userBio = "", | ||
siteTitle = "", | ||
siteUrl = "", | ||
siteId = 0L, | ||
blogPreviewSource = ReaderTracker.SOURCE_SITE_COMMENTS_USER_PROFILE | ||
) | ||
} | ||
|
||
override fun getCommentIdentifier(): CommentIdentifier = | ||
CommentIdentifier.SiteCommentIdentifier(mComment!!.id, mComment!!.remoteCommentId) | ||
|
||
|
||
override fun handleHeaderVisibility() { | ||
mBinding?.headerView?.isVisible = true | ||
} | ||
|
@@ -48,3 +78,19 @@ class SiteCommentDetailFragment : CommentDetailFragment() { | |
} | ||
} | ||
} | ||
|
||
object CommentExtension { | ||
fun getAvatarUrl(comment: CommentModel, size: Int): String = when { | ||
comment.authorProfileImageUrl != null -> WPAvatarUtils.rewriteAvatarUrl( | ||
comment.authorProfileImageUrl!!, | ||
size | ||
) | ||
|
||
comment.authorEmail != null -> AvatarUrl( | ||
Email(comment.authorEmail!!), | ||
AvatarQueryOptions(size, null, null, null) | ||
).url().toString() | ||
|
||
else -> "" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package org.wordpress.android.ui.comments.unified | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.widget.PopupWindow | ||
import org.wordpress.android.R | ||
import org.wordpress.android.databinding.CommentActionsBinding | ||
import org.wordpress.android.ui.comments.CommentDetailFragment | ||
import org.wordpress.android.util.ToastUtils | ||
|
||
object CommentActionPopupHandler { | ||
@JvmStatic | ||
fun show(anchorView: View, listener: CommentDetailFragment.OnActionClickListener?) { | ||
val popupWindow = PopupWindow(anchorView.context, null, R.style.WordPress) | ||
popupWindow.isOutsideTouchable = true | ||
popupWindow.elevation = anchorView.context.resources.getDimension(R.dimen.popup_over_toolbar_elevation) | ||
popupWindow.contentView = CommentActionsBinding | ||
.inflate(LayoutInflater.from(anchorView.context)) | ||
.apply { | ||
textUserInfo.setOnClickListener { | ||
listener?.onUserInfoClicked() | ||
popupWindow.dismiss() | ||
} | ||
textShare.setOnClickListener { | ||
ToastUtils.showToast(it.context, "not yet implemented") | ||
popupWindow.dismiss() | ||
} | ||
textEditComment.setOnClickListener { | ||
listener?.onEditCommentClicked() | ||
popupWindow.dismiss() | ||
} | ||
textChangeStatus.setOnClickListener { | ||
ToastUtils.showToast(it.context, "not yet implemented") | ||
popupWindow.dismiss() | ||
} | ||
}.root | ||
popupWindow.showAsDropDown(anchorView) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package org.wordpress.android.ui.engagement | ||
|
||
import java.io.Serializable | ||
|
||
sealed class BottomSheetUiState { | ||
@Suppress("SerialVersionUIDInSerializableClass") | ||
data class UserProfileUiState( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we shouldn't mark some fields as nullable because not all are always available for all the cases. For example, if the user does not have an avatar URL, it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I 100% agree with you, straight meaning is important for us to handle those fields correctly. I find many implementations use default values, but it'd be better if they are defined as nullable. I suspect that when handling this data with Java in the past, there was a tendency to use defensive programming to avoid crashes. However, now with Kotlin, handling nullables has become much easier. I think we can find time to refactor this. |
||
val userAvatarUrl: String, | ||
val blavatarUrl: String, | ||
|
@@ -10,9 +13,8 @@ sealed class BottomSheetUiState { | |
val siteTitle: String, | ||
val siteUrl: String, | ||
val siteId: Long, | ||
val onSiteClickListener: ((siteId: Long, siteUrl: String, source: String) -> Unit)? = null, | ||
val blogPreviewSource: String | ||
) : BottomSheetUiState() { | ||
) : BottomSheetUiState(), Serializable { | ||
val hasSiteUrl: Boolean = siteUrl.isNotBlank() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's safe to use the not-null assertion for
mNote
. Shouldn't we use the same approach as for themComment
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
NotificationCommentDetailFragment
,mNote
should be non-null afteronCreate()
.I replaced with
note
here.