Skip to content

Commit a862f9b

Browse files
author
Thomas Horta
committed
Merge branch 'issue/20621-announcement-card-in-feeds' of github.com:wordpress-mobile/WordPress-Android into issue/20621-announcement-card-in-tags-feed
2 parents 7d83aa2 + 911be72 commit a862f9b

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderPostAdapter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import org.wordpress.android.ui.reader.discover.viewholders.ReaderPostNewViewHolder;
4747
import org.wordpress.android.ui.reader.discover.viewholders.ReaderPostViewHolder;
4848
import org.wordpress.android.ui.reader.models.ReaderBlogIdPostId;
49-
import org.wordpress.android.ui.reader.repository.ReaderAnnouncementRepository;
49+
import org.wordpress.android.ui.reader.utils.ReaderAnnouncementHelper;
5050
import org.wordpress.android.ui.reader.tracker.ReaderTab;
5151
import org.wordpress.android.ui.reader.tracker.ReaderTracker;
5252
import org.wordpress.android.ui.reader.utils.ReaderXPostUtils;
@@ -135,7 +135,7 @@ public class ReaderPostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
135135
@Inject ReaderPostMoreButtonUiStateBuilder mReaderPostMoreButtonUiStateBuilder;
136136
@Inject ReaderTracker mReaderTracker;
137137
@Inject ReaderImprovementsFeatureConfig mReaderImprovementsFeatureConfig;
138-
@Inject ReaderAnnouncementRepository mReaderAnnouncementRepository;
138+
@Inject ReaderAnnouncementHelper mReaderAnnouncementHelper;
139139

140140
public String getSource() {
141141
return mSource;
@@ -329,9 +329,9 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
329329
} else if (holder instanceof ReaderAnnouncementCardViewHolder) {
330330
ReaderAnnouncementCardViewHolder announcementViewHolder = (ReaderAnnouncementCardViewHolder) holder;
331331
announcementViewHolder.mAnnouncementCardView
332-
.setItems(mReaderAnnouncementRepository.getReaderAnnouncementItems());
332+
.setItems(mReaderAnnouncementHelper.getReaderAnnouncementItems());
333333
announcementViewHolder.mAnnouncementCardView.setOnDoneClickListener(() -> {
334-
mReaderAnnouncementRepository.dismissReaderAnnouncement();
334+
mReaderAnnouncementHelper.dismissReaderAnnouncement();
335335
notifyItemRemoved(getAnnouncementPosition());
336336
});
337337
}
@@ -717,7 +717,7 @@ private boolean hasTagHeader() {
717717
}
718718

719719
private boolean hasAnnouncement() {
720-
return mIsMainReader && mReaderAnnouncementRepository.hasReaderAnnouncement() && !isEmpty()
720+
return mIsMainReader && mReaderAnnouncementHelper.hasReaderAnnouncement() && !isEmpty()
721721
&& (getPostListType() != ReaderPostListType.BLOG_PREVIEW)
722722
&& (mCurrentTag != null && !mCurrentTag.isTagTopic());
723723
}

WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowPosts
2727
import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowReaderSubs
2828
import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowSitePickerForResult
2929
import org.wordpress.android.ui.reader.reblog.ReblogUseCase
30-
import org.wordpress.android.ui.reader.repository.ReaderAnnouncementRepository
30+
import org.wordpress.android.ui.reader.utils.ReaderAnnouncementHelper
3131
import org.wordpress.android.ui.reader.repository.ReaderDiscoverCommunication
3232
import org.wordpress.android.ui.reader.repository.ReaderDiscoverCommunication.Error
3333
import org.wordpress.android.ui.reader.repository.ReaderDiscoverCommunication.Started
@@ -63,7 +63,7 @@ class ReaderDiscoverViewModel @Inject constructor(
6363
displayUtilsWrapper: DisplayUtilsWrapper,
6464
private val getFollowedTagsUseCase: GetFollowedTagsUseCase,
6565
private val readerImprovementsFeatureConfig: ReaderImprovementsFeatureConfig,
66-
private val readerAnnouncementRepository: ReaderAnnouncementRepository,
66+
private val readerAnnouncementHelper: ReaderAnnouncementHelper,
6767
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher,
6868
@Named(IO_THREAD) private val ioDispatcher: CoroutineDispatcher
6969
) : ScopedViewModel(mainDispatcher) {
@@ -161,10 +161,10 @@ class ReaderDiscoverViewModel @Inject constructor(
161161
}
162162
} else {
163163
if (posts != null && posts.cards.isNotEmpty()) {
164-
val announcement = if (readerAnnouncementRepository.hasReaderAnnouncement()) {
164+
val announcement = if (readerAnnouncementHelper.hasReaderAnnouncement()) {
165165
listOf(
166166
ReaderCardUiState.ReaderAnnouncementCardUiState(
167-
readerAnnouncementRepository.getReaderAnnouncementItems(),
167+
readerAnnouncementHelper.getReaderAnnouncementItems(),
168168
::dismissAnnouncementCard
169169
)
170170
)
@@ -192,7 +192,7 @@ class ReaderDiscoverViewModel @Inject constructor(
192192
}
193193

194194
private fun dismissAnnouncementCard() {
195-
readerAnnouncementRepository.dismissReaderAnnouncement()
195+
readerAnnouncementHelper.dismissReaderAnnouncement()
196196
_uiState.value = (_uiState.value as? DiscoverUiState.ContentUiState)?.let { contentUiState ->
197197
contentUiState.copy(
198198
cards = contentUiState.cards.filterNot { it is ReaderCardUiState.ReaderAnnouncementCardUiState }
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.wordpress.android.ui.reader.repository
1+
package org.wordpress.android.ui.reader.utils
22

33
import dagger.Reusable
44
import org.wordpress.android.R
@@ -11,7 +11,7 @@ import org.wordpress.android.util.config.ReaderTagsFeedFeatureConfig
1111
import javax.inject.Inject
1212

1313
@Reusable
14-
class ReaderAnnouncementRepository @Inject constructor(
14+
class ReaderAnnouncementHelper @Inject constructor(
1515
private val readerAnnouncementCardFeatureConfig: ReaderAnnouncementCardFeatureConfig,
1616
private val readerTagsFeedFeatureConfig: ReaderTagsFeedFeatureConfig,
1717
private val appPrefsWrapper: AppPrefsWrapper,

WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/tagsfeed/ReaderTagsFeedViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import org.wordpress.android.ui.reader.discover.ReaderPostCardActionsHandler
2828
import org.wordpress.android.ui.reader.discover.ReaderPostMoreButtonUiStateBuilder
2929
import org.wordpress.android.ui.reader.discover.ReaderPostUiStateBuilder
3030
import org.wordpress.android.ui.reader.exceptions.ReaderPostFetchException
31-
import org.wordpress.android.ui.reader.repository.ReaderAnnouncementRepository
3231
import org.wordpress.android.ui.reader.repository.ReaderPostRepository
3332
import org.wordpress.android.ui.reader.repository.usecases.PostLikeUseCase
3433
import org.wordpress.android.ui.reader.tracker.ReaderTracker
34+
import org.wordpress.android.ui.reader.utils.ReaderAnnouncementHelper
3535
import org.wordpress.android.ui.reader.views.compose.ReaderAnnouncementCardItemData
3636
import org.wordpress.android.ui.reader.views.compose.tagsfeed.TagsFeedPostItem
3737
import org.wordpress.android.util.DisplayUtilsWrapper
@@ -55,7 +55,7 @@ class ReaderTagsFeedViewModel @Inject constructor(
5555
private val displayUtilsWrapper: DisplayUtilsWrapper,
5656
private val readerTracker: ReaderTracker,
5757
private val networkUtilsWrapper: NetworkUtilsWrapper,
58-
private val readerAnnouncementRepository: ReaderAnnouncementRepository,
58+
private val readerAnnouncementHelper: ReaderAnnouncementHelper,
5959
) : ScopedViewModel(bgDispatcher) {
6060
private val _uiStateFlow: MutableStateFlow<UiState> = MutableStateFlow(UiState.Initial)
6161
val uiStateFlow: StateFlow<UiState> = _uiStateFlow
@@ -154,17 +154,17 @@ class ReaderTagsFeedViewModel @Inject constructor(
154154
}
155155

156156
private fun getAnnouncementItem(): ReaderAnnouncementItem? =
157-
if (readerAnnouncementRepository.hasReaderAnnouncement()) {
157+
if (readerAnnouncementHelper.hasReaderAnnouncement()) {
158158
ReaderAnnouncementItem(
159-
items = readerAnnouncementRepository.getReaderAnnouncementItems(),
159+
items = readerAnnouncementHelper.getReaderAnnouncementItems(),
160160
onDoneClicked = ::dismissAnnouncementItem,
161161
)
162162
} else {
163163
null
164164
}
165165

166166
private fun dismissAnnouncementItem() {
167-
readerAnnouncementRepository.dismissReaderAnnouncement()
167+
readerAnnouncementHelper.dismissReaderAnnouncement()
168168
_uiStateFlow.update {
169169
(it as? UiState.Loaded)?.copy(announcementItem = null) ?: it
170170
}

WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverViewModelTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import org.wordpress.android.ui.reader.discover.ReaderPostCardActionType.LIKE
5454
import org.wordpress.android.ui.reader.discover.ReaderPostCardActionType.REBLOG
5555
import org.wordpress.android.ui.reader.discover.interests.TagUiState
5656
import org.wordpress.android.ui.reader.reblog.ReblogUseCase
57-
import org.wordpress.android.ui.reader.repository.ReaderAnnouncementRepository
57+
import org.wordpress.android.ui.reader.utils.ReaderAnnouncementHelper
5858
import org.wordpress.android.ui.reader.repository.ReaderDiscoverCommunication
5959
import org.wordpress.android.ui.reader.repository.ReaderDiscoverCommunication.Error.NetworkUnavailable
6060
import org.wordpress.android.ui.reader.repository.ReaderDiscoverCommunication.Started
@@ -139,7 +139,7 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
139139
private lateinit var readerImprovementsFeatureConfig: ReaderImprovementsFeatureConfig
140140

141141
@Mock
142-
private lateinit var readerAnnouncementRepository: ReaderAnnouncementRepository
142+
private lateinit var mReaderAnnouncementHelper: ReaderAnnouncementHelper
143143

144144
private val fakeDiscoverFeed = ReactiveMutableLiveData<ReaderDiscoverCards>()
145145
private val fakeCommunicationChannel = MutableLiveData<Event<ReaderDiscoverCommunication>>()
@@ -164,7 +164,7 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
164164
displayUtilsWrapper,
165165
getFollowedTagsUseCase,
166166
readerImprovementsFeatureConfig,
167-
readerAnnouncementRepository,
167+
mReaderAnnouncementHelper,
168168
testDispatcher(),
169169
testDispatcher()
170170
)
@@ -408,7 +408,7 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
408408
@Test
409409
fun `if Announcement does not exist then ReaderAnnouncementCardUiState will not be present`() = test {
410410
// Arrange
411-
whenever(readerAnnouncementRepository.hasReaderAnnouncement()).thenReturn(false)
411+
whenever(mReaderAnnouncementHelper.hasReaderAnnouncement()).thenReturn(false)
412412
val uiStates = init(autoUpdateFeed = false).uiStates
413413
// Act
414414
fakeDiscoverFeed.value = createDummyReaderCardsList() // mock finished loading
@@ -421,8 +421,8 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
421421
@Test
422422
fun `if Announcement exists then ReaderAnnouncementCardUiState will be present`() = test {
423423
// Arrange
424-
whenever(readerAnnouncementRepository.hasReaderAnnouncement()).thenReturn(true)
425-
whenever(readerAnnouncementRepository.getReaderAnnouncementItems()).thenReturn(mock())
424+
whenever(mReaderAnnouncementHelper.hasReaderAnnouncement()).thenReturn(true)
425+
whenever(mReaderAnnouncementHelper.getReaderAnnouncementItems()).thenReturn(mock())
426426
val uiStates = init(autoUpdateFeed = false).uiStates
427427
// Act
428428
fakeDiscoverFeed.value = createDummyReaderCardsList() // mock finished loading
@@ -435,8 +435,8 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
435435
@Test
436436
fun `clicking done on ReaderAnnouncementCardUiState dismisses and updates the ContentUiState`() = test {
437437
// Arrange
438-
whenever(readerAnnouncementRepository.hasReaderAnnouncement()).thenReturn(true)
439-
whenever(readerAnnouncementRepository.getReaderAnnouncementItems()).thenReturn(mock())
438+
whenever(mReaderAnnouncementHelper.hasReaderAnnouncement()).thenReturn(true)
439+
whenever(mReaderAnnouncementHelper.getReaderAnnouncementItems()).thenReturn(mock())
440440
val uiStates = init(autoUpdateFeed = false).uiStates
441441

442442
fakeDiscoverFeed.value = createDummyReaderCardsList() // mock finished loading
@@ -447,7 +447,7 @@ class ReaderDiscoverViewModelTest : BaseUnitTest() {
447447
announcementCard.onDoneClick()
448448

449449
// Assert
450-
verify(readerAnnouncementRepository).dismissReaderAnnouncement()
450+
verify(mReaderAnnouncementHelper).dismissReaderAnnouncement()
451451

452452
val newContentUiState = uiStates.last() as ContentUiState
453453
assertThat(newContentUiState.cards.first())
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.wordpress.android.ui.reader.repository
1+
package org.wordpress.android.ui.reader.utils
22

33
import org.assertj.core.api.Assertions.assertThat
44
import org.junit.Before
@@ -16,7 +16,7 @@ import org.wordpress.android.util.config.ReaderAnnouncementCardFeatureConfig
1616
import org.wordpress.android.util.config.ReaderTagsFeedFeatureConfig
1717

1818
@RunWith(MockitoJUnitRunner::class)
19-
class ReaderAnnouncementRepositoryTest {
19+
class ReaderAnnouncementHelperTest {
2020
@Mock
2121
private lateinit var readerAnnouncementCardFeatureConfig: ReaderAnnouncementCardFeatureConfig
2222

@@ -29,11 +29,11 @@ class ReaderAnnouncementRepositoryTest {
2929
@Mock
3030
private lateinit var readerTracker: ReaderTracker
3131

32-
private lateinit var repository: ReaderAnnouncementRepository
32+
private lateinit var repository: ReaderAnnouncementHelper
3333

3434
@Before
3535
fun setUp() {
36-
repository = ReaderAnnouncementRepository(
36+
repository = ReaderAnnouncementHelper(
3737
readerAnnouncementCardFeatureConfig,
3838
readerTagsFeedFeatureConfig,
3939
appPrefsWrapper,

WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderTagsFeedViewModelTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ import org.wordpress.android.ui.reader.discover.ReaderPostCardActionsHandler
3737
import org.wordpress.android.ui.reader.discover.ReaderPostMoreButtonUiStateBuilder
3838
import org.wordpress.android.ui.reader.discover.ReaderPostUiStateBuilder
3939
import org.wordpress.android.ui.reader.exceptions.ReaderPostFetchException
40-
import org.wordpress.android.ui.reader.repository.ReaderAnnouncementRepository
4140
import org.wordpress.android.ui.reader.repository.ReaderPostRepository
4241
import org.wordpress.android.ui.reader.repository.usecases.PostLikeUseCase
4342
import org.wordpress.android.ui.reader.tracker.ReaderTracker
43+
import org.wordpress.android.ui.reader.utils.ReaderAnnouncementHelper
4444
import org.wordpress.android.ui.reader.viewmodels.tagsfeed.ReaderTagsFeedUiStateMapper
4545
import org.wordpress.android.ui.reader.viewmodels.tagsfeed.ReaderTagsFeedViewModel
4646
import org.wordpress.android.ui.reader.viewmodels.tagsfeed.ReaderTagsFeedViewModel.ActionEvent
@@ -91,7 +91,7 @@ class ReaderTagsFeedViewModelTest : BaseUnitTest() {
9191
lateinit var networkUtilsWrapper: NetworkUtilsWrapper
9292

9393
@Mock
94-
lateinit var readerAnnouncementRepository: ReaderAnnouncementRepository
94+
lateinit var readerAnnouncementHelper: ReaderAnnouncementHelper
9595

9696
private lateinit var viewModel: ReaderTagsFeedViewModel
9797

@@ -123,7 +123,7 @@ class ReaderTagsFeedViewModelTest : BaseUnitTest() {
123123
displayUtilsWrapper = displayUtilsWrapper,
124124
readerTracker = readerTracker,
125125
networkUtilsWrapper = networkUtilsWrapper,
126-
readerAnnouncementRepository = readerAnnouncementRepository,
126+
readerAnnouncementHelper = readerAnnouncementHelper,
127127
)
128128
whenever(readerPostCardActionsHandler.navigationEvents)
129129
.thenReturn(navigationEvents)
@@ -158,8 +158,8 @@ class ReaderTagsFeedViewModelTest : BaseUnitTest() {
158158
val tag = ReaderTestUtils.createTag("tag")
159159
val announcementItems = listOf<ReaderAnnouncementCardItemData>(mock(), mock())
160160
mockMapInitialTagFeedItems()
161-
whenever(readerAnnouncementRepository.hasReaderAnnouncement()).thenReturn(true)
162-
whenever(readerAnnouncementRepository.getReaderAnnouncementItems()).thenReturn(announcementItems)
161+
whenever(readerAnnouncementHelper.hasReaderAnnouncement()).thenReturn(true)
162+
whenever(readerAnnouncementHelper.getReaderAnnouncementItems()).thenReturn(announcementItems)
163163

164164
// When
165165
viewModel.onTagsChanged(listOf(tag))
@@ -177,8 +177,8 @@ class ReaderTagsFeedViewModelTest : BaseUnitTest() {
177177
val tag = ReaderTestUtils.createTag("tag")
178178
val announcementItems = listOf<ReaderAnnouncementCardItemData>(mock(), mock())
179179
mockMapInitialTagFeedItems()
180-
whenever(readerAnnouncementRepository.hasReaderAnnouncement()).thenReturn(true)
181-
whenever(readerAnnouncementRepository.getReaderAnnouncementItems()).thenReturn(announcementItems)
180+
whenever(readerAnnouncementHelper.hasReaderAnnouncement()).thenReturn(true)
181+
whenever(readerAnnouncementHelper.getReaderAnnouncementItems()).thenReturn(announcementItems)
182182

183183
viewModel.onTagsChanged(listOf(tag))
184184
advanceUntilIdle()
@@ -189,7 +189,7 @@ class ReaderTagsFeedViewModelTest : BaseUnitTest() {
189189
advanceUntilIdle()
190190

191191
// Then
192-
verify(readerAnnouncementRepository).dismissReaderAnnouncement()
192+
verify(readerAnnouncementHelper).dismissReaderAnnouncement()
193193
assertThat(collectedUiStates.last()).isEqualTo(
194194
ReaderTagsFeedViewModel.UiState.Loaded(
195195
data = listOf(getInitialTagFeedItem(tag)),

0 commit comments

Comments
 (0)