Skip to content
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

Issue 15828 - Notification comment support in the new comment editor #15884

Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
289f71f
Extract CommentSource class
RenanLukas Jan 21, 2022
957e3ba
Migrate CommentSource to Kotlin
RenanLukas Jan 21, 2022
1a47d0d
Implement unit tests for CommentSource
RenanLukas Jan 21, 2022
9bde88c
Refactor CommentDetailFragment Intent creation
RenanLukas Jan 21, 2022
e34a363
Open UnifiedCommentsEditActivity instead of EditCommentActivity for a…
RenanLukas Jan 24, 2022
6168640
Add CommentIdentifier class (as implemented in @khaykov branch)
RenanLukas Jan 25, 2022
49da328
Integrate CommentIdentifier with UnifiedCommentsEdit flow
RenanLukas Jan 27, 2022
f3fe234
Implement NotificationsTableWrapper
RenanLukas Jan 31, 2022
605e0c8
Update NotificationCommentIdenfitier ID type
RenanLukas Jan 31, 2022
d727861
Support notification comment in new editor: Use CommentIdentifier to …
RenanLukas Jan 31, 2022
585fb93
Fix UnifiedCommentsEditViewModel unit tests
RenanLukas Jan 31, 2022
ccb06d2
Merge branch 'trunk' into issue/15828-migrate-edited-comment-notifica…
RenanLukas Feb 1, 2022
7a3a2e6
Extract and implement unit tests for CommentEssentials
RenanLukas Feb 1, 2022
ddb5e4f
Add new unit tests for UnifiedCommentsEditViewModel
RenanLukas Feb 1, 2022
3454634
Fix detekt, ktlint and checkstyle
RenanLukas Feb 1, 2022
e3c7554
Implement save edited notification comment in new editor
RenanLukas Feb 3, 2022
f8cc4e0
Rename downloadNoteAndUpdateDB parameter
RenanLukas Feb 3, 2022
7459adf
Update UnifiedCommentsEditViewModel unit tests considering saving of …
RenanLukas Feb 3, 2022
535bfd7
Fix detekt warning for UnifiedCommentsEditViewModel: TooManyFuncions.…
RenanLukas Feb 3, 2022
172d0ae
Fix unresolved reference in UnifiedCommentsEditViewModelTest
RenanLukas Feb 3, 2022
27d480a
Fix edit notification comment in new editor not fetching web address …
RenanLukas Feb 3, 2022
c733045
Update UnifiedCommentsEditViewModel unit tests
RenanLukas Feb 3, 2022
9ba4801
Fix detekt: MaxLineLength in UnifiedCommentsEditViewModel
RenanLukas Feb 3, 2022
9af6fb2
Fetch remote notification comment if not found locally in UnifiedComm…
RenanLukas Feb 4, 2022
4eed36c
Move remoteCommentId property to CommentIdentifier sealed class
RenanLukas Feb 4, 2022
628e0bc
Extract comment get logic to GetCommentUseCase
RenanLukas Feb 4, 2022
332442e
Extract CommentEssentials extension isNotEqualTo to separate file and…
RenanLukas Feb 4, 2022
546f084
Update UnifiedCommentsEditViewModel unit tests
RenanLukas Feb 5, 2022
0538f3b
Fix checkstyle of CommentEssentialsExtensionKtTest
RenanLukas Feb 5, 2022
8a39dc4
Update RELEASE-NOTES with notification comments support in the new ed…
RenanLukas Feb 7, 2022
0520e03
Merge branch 'trunk' into issue/15828-migrate-edited-comment-notifica…
RenanLukas Feb 7, 2022
eede892
Remove extra line in RELEASE-NOTES
RenanLukas Feb 7, 2022
d7d6dbd
Use -1 instead of 0 for CommentEssentials default ID and update unit …
RenanLukas Feb 7, 2022
1e1088d
Implement code review improvements
RenanLukas Feb 7, 2022
389a321
Add callbacks to update edited notification comment edited in comment…
RenanLukas Feb 8, 2022
3ae9e7a
Split CommentUserNoteBlock configureView method
RenanLukas Feb 9, 2022
3639e10
Update notification comment content in comment details after editing
RenanLukas Feb 9, 2022
10de4d1
Fix checkstyle errors
RenanLukas Feb 9, 2022
4373962
Implement VM logic to disable edit name, url and email for notificati…
RenanLukas Feb 9, 2022
973bb30
Add check to avoid NPE when calling refreshBlocksForEditedComment in …
RenanLukas Feb 9, 2022
22114ae
Apply input enabled settings in UnifiedCommentsEditFragment based on …
RenanLukas Feb 9, 2022
b7c39e6
Update unit tests for UnifiedCommentsEditViewModelTest considering in…
RenanLukas Feb 9, 2022
e956c7b
Update notification entity when comment notification edited in the ne…
RenanLukas Feb 11, 2022
314a16c
Refresh note blocks in comment details screen after notification comm…
RenanLukas Feb 11, 2022
717acdf
Remove Nullable annotations not found by CI
RenanLukas Feb 11, 2022
65853ab
Merge pull request #15918 from wordpress-mobile/issue/15910-fix-notif…
khaykov Feb 11, 2022
e6719f0
Merge branch 'trunk' into issue/15828-migrate-edited-comment-notifica…
RenanLukas Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

19.3
-----

* [*] Comment editor: Notification comments support in the new editor [https://github.com/wordpress-mobile/WordPress-Android/pull/15884]

19.2
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
import org.wordpress.android.ui.ViewPagerFragment;
import org.wordpress.android.ui.comments.CommentActions.OnCommentActionListener;
import org.wordpress.android.ui.comments.CommentActions.OnNoteCommentActionListener;
import org.wordpress.android.ui.comments.unified.CommentIdentifier;
import org.wordpress.android.ui.comments.unified.CommentIdentifier.NotificationCommentIdentifier;
import org.wordpress.android.ui.comments.unified.CommentIdentifier.SiteCommentIdentifier;
import org.wordpress.android.ui.comments.unified.CommentSource;
import org.wordpress.android.ui.comments.unified.CommentsStoreAdapter;
import org.wordpress.android.ui.comments.unified.UnifiedCommentsEditActivity;
import org.wordpress.android.ui.notifications.NotificationEvents;
Expand Down Expand Up @@ -101,7 +105,6 @@
import org.wordpress.android.util.ViewUtilsKt;
import org.wordpress.android.util.WPLinkMovementMethod;
import org.wordpress.android.util.analytics.AnalyticsUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource;
import org.wordpress.android.util.config.UnifiedCommentsCommentEditFeatureConfig;
import org.wordpress.android.util.image.ImageManager;
import org.wordpress.android.util.image.ImageType;
Expand Down Expand Up @@ -137,22 +140,6 @@ public class CommentDetailFragment extends ViewPagerFragment implements Notifica

private static final int INTENT_COMMENT_EDITOR = 1010;

enum CommentSource {
NOTIFICATION,
SITE_COMMENTS;

AnalyticsCommentActionSource toAnalyticsCommentActionSource() {
switch (this) {
case NOTIFICATION:
return AnalyticsCommentActionSource.NOTIFICATIONS;
case SITE_COMMENTS:
return AnalyticsCommentActionSource.SITE_COMMENTS;
}
throw new IllegalArgumentException(
this + " CommentSource is not mapped to corresponding AnalyticsCommentActionSource");
}
}

private CommentModel mComment;
private SiteModel mSite;

Expand Down Expand Up @@ -683,12 +670,10 @@ private void editComment() {
// IMPORTANT: don't use getActivity().startActivityForResult() or else onActivityResult()
// won't be called in this fragment
// https://code.google.com/p/android/issues/detail?id=15394#c45
if (mUnifiedCommentsCommentEditFeatureConfig.isEnabled() && mCommentSource == CommentSource.SITE_COMMENTS) {
Intent intent = new Intent(getActivity(), UnifiedCommentsEditActivity.class);
intent.putExtra(WordPress.SITE, mSite);
if (mComment != null) {
intent.putExtra(UnifiedCommentsEditActivity.KEY_COMMENT_ID, mComment.getId());
}
if (mUnifiedCommentsCommentEditFeatureConfig.isEnabled()) {
final CommentIdentifier commentIdentifier = mapCommentIdentifier();
final Intent intent =
UnifiedCommentsEditActivity.createIntent(requireActivity(), commentIdentifier, mSite);
startActivityForResult(intent, INTENT_COMMENT_EDITOR);
} else {
Intent intent = new Intent(getActivity(), EditCommentActivity.class);
Expand All @@ -701,6 +686,19 @@ private void editComment() {
}
}

// TODO [RenanLukas] handle Reader CommentSource when it's ready
@Nullable
private CommentIdentifier mapCommentIdentifier() {
switch (mCommentSource) {
case SITE_COMMENTS:
return new SiteCommentIdentifier(mComment.getId(), mComment.getRemoteCommentId());
case NOTIFICATION:
return new NotificationCommentIdentifier(mNote.getCommentId());
default:
return null;
}
}

/*
* display the current comment
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.wordpress.android.ui.comments.unified

data class CommentEssentials(
val commentId: Long = DEFAULT_COMMENT_ID,
val userName: String = "",
val commentText: String = "",
val userUrl: String = "",
val userEmail: String = ""
) {
/**
* Checks if this instance of CommentEssentials is valid. An invalid instance should not be used to display data.
* @return true if the instance is valid or false if it's not
*/
fun isValid(): Boolean = commentId > DEFAULT_COMMENT_ID

companion object {
private const val DEFAULT_COMMENT_ID = -1L
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.wordpress.android.ui.comments.unified

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

sealed class CommentIdentifier : Parcelable {
abstract val remoteCommentId: Long

@Parcelize
data class SiteCommentIdentifier(
val localCommentId: Int,
override val remoteCommentId: Long
) : CommentIdentifier()

@Parcelize
data class ReaderCommentIdentifier(
val blogId: Long,
val postId: Long,
override val remoteCommentId: Long
) : CommentIdentifier()

@Parcelize
data class NotificationCommentIdentifier(
override val remoteCommentId: Long
) : CommentIdentifier()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.wordpress.android.ui.comments.unified

import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource

enum class CommentSource {
NOTIFICATION, SITE_COMMENTS;

fun toAnalyticsCommentActionSource(): AnalyticsCommentActionSource =
when (this) {
NOTIFICATION -> AnalyticsCommentActionSource.NOTIFICATIONS
SITE_COMMENTS -> AnalyticsCommentActionSource.SITE_COMMENTS
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wordpress.android.ui.comments.unified

import android.content.Context
import android.content.Intent
import android.os.Bundle
import org.wordpress.android.R
import org.wordpress.android.WordPress
Expand All @@ -16,24 +18,34 @@ class UnifiedCommentsEditActivity : LocaleAwareActivity() {
}

val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel
val commentId: Int = intent.getIntExtra(KEY_COMMENT_ID, 0)
val commentIdentifier = requireNotNull(intent.getParcelableExtra<CommentIdentifier>(KEY_COMMENT_IDENTIFIER))

val fm = supportFragmentManager
var editCommentFragment = fm.findFragmentByTag(
TAG_UNIFIED_EDIT_COMMENT_FRAGMENT
) as? UnifiedCommentsEditFragment

if (editCommentFragment == null) {
editCommentFragment = UnifiedCommentsEditFragment.newInstance(site, commentId)
editCommentFragment = UnifiedCommentsEditFragment.newInstance(site, commentIdentifier)
fm.beginTransaction()
.add(R.id.fragment_container, editCommentFragment, TAG_UNIFIED_EDIT_COMMENT_FRAGMENT)
.commit()
}
}

companion object {
const val KEY_COMMENT_ID = "key_comment_id"

@JvmStatic
fun createIntent(
context: Context,
commentIdentifier: CommentIdentifier,
siteModel: SiteModel
): Intent =
Intent(context, UnifiedCommentsEditActivity::class.java).apply {
putExtra(KEY_COMMENT_IDENTIFIER, commentIdentifier)
putExtra(WordPress.SITE, siteModel)
}

private const val KEY_COMMENT_IDENTIFIER = "key_comment_identifier"
private const val TAG_UNIFIED_EDIT_COMMENT_FRAGMENT = "tag_unified_edit_comment_fragment"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag
super.onViewCreated(view, savedInstanceState)

val site = requireArguments().getSerializable(WordPress.SITE) as SiteModel
val commentId = requireArguments().getInt(KEY_COMMENT_ID)
val commentIdentifier = requireNotNull(
requireArguments().getParcelable<CommentIdentifier>(
KEY_COMMENT_IDENTIFIER
)
)

UnifiedCommentsEditFragmentBinding.bind(view).apply {
setupToolbar()
setupObservers(site, commentId)
setupObservers(site, commentIdentifier)
}
}

Expand Down Expand Up @@ -89,7 +93,10 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag
ActivityUtils.hideKeyboardForced(view)
}

private fun UnifiedCommentsEditFragmentBinding.setupObservers(site: SiteModel, commentId: Int) {
private fun UnifiedCommentsEditFragmentBinding.setupObservers(
site: SiteModel,
commentIdentifier: CommentIdentifier
) {
viewModel.uiActionEvent.observeEvent(viewLifecycleOwner, {
when (it) {
CLOSE -> {
Expand Down Expand Up @@ -144,7 +151,7 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag
}
})

viewModel.start(site, commentId)
viewModel.start(site, commentIdentifier)
}

private fun UnifiedCommentsEditFragmentBinding.showSnackbar(holder: SnackbarMessageHolder) {
Expand Down Expand Up @@ -210,13 +217,13 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag
}

companion object {
private const val KEY_COMMENT_ID = "key_comment_id"
private const val KEY_COMMENT_IDENTIFIER = "key_comment_identifier"

fun newInstance(site: SiteModel, commentId: Int): UnifiedCommentsEditFragment {
fun newInstance(site: SiteModel, commentIdentifier: CommentIdentifier): UnifiedCommentsEditFragment {
val args = Bundle()

args.putSerializable(WordPress.SITE, site)
args.putInt(KEY_COMMENT_ID, commentId)
args.putParcelable(KEY_COMMENT_IDENTIFIER, commentIdentifier)

val fragment = UnifiedCommentsEditFragment()

Expand Down
Loading