Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wordpress-mobile/WordPress-Android
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 664aaa1af876f53e96c03005ad8e3213419b9ebd
Choose a base ref
..
head repository: wordpress-mobile/WordPress-Android
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d1967aeaab855813170ec04545279de622aa5997
Choose a head ref
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsResult
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.modules.UI_THREAD
import org.wordpress.android.ui.PagePostCreationSourcesDetail.STORY_FROM_MY_SITE
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.PostCard
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.DomainRegistrationCardBuilderParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.PostCardBuilderParams
import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams.PostCardBuilderParams.PostItemClickParams
@@ -227,60 +228,83 @@ class MySiteViewModel @Inject constructor(
backupAvailable: Boolean,
scanAvailable: Boolean,
cards: CardsResult<List<CardModel>>?
) = cardsBuilder.build(
DomainRegistrationCardBuilderParams(
isDomainCreditAvailable = isDomainCreditAvailable,
domainRegistrationClick = this::domainRegistrationClick
),
PostCardBuilderParams(
posts = cards?.model?.firstOrNull { it is PostsCardModel } as? PostsCardModel,
onPostItemClick = this::onPostItemClick,
onFooterLinkClick = this::onPostCardFooterLinkClick
),
QuickActionsCardBuilderParams(
siteModel = site,
activeTask = activeTask,
onQuickActionStatsClick = this::quickActionStatsClick,
onQuickActionPagesClick = this::quickActionPagesClick,
onQuickActionPostsClick = this::quickActionPostsClick,
onQuickActionMediaClick = this::quickActionMediaClick
),
QuickStartCardBuilderParams(
quickStartCategories = quickStartCategories,
onQuickStartBlockRemoveMenuItemClick = this::onQuickStartBlockRemoveMenuItemClick,
onQuickStartTaskTypeItemClick = this::onQuickStartTaskTypeItemClick
),
SiteInfoCardBuilderParams(
site = site,
showSiteIconProgressBar = showSiteIconProgressBar,
titleClick = this::titleClick,
iconClick = this::iconClick,
urlClick = this::urlClick,
switchSiteClick = this::switchSiteClick,
activeTask = activeTask
)
) + dynamicCardsBuilder.build(
quickStartCategories,
pinnedDynamicCard,
visibleDynamicCards,
this::onDynamicCardMoreClick,
this::onQuickStartTaskCardClick
) + siteItemsBuilder.build(
SiteItemsBuilderParams(
site = site,
activeTask = activeTask,
backupAvailable = backupAvailable,
scanAvailable = scanAvailable,
onClick = this::onItemClick
)
)
): List<MySiteCardAndItem> {
val cardsResult = cardsBuilder.build(
DomainRegistrationCardBuilderParams(
isDomainCreditAvailable = isDomainCreditAvailable,
domainRegistrationClick = this::domainRegistrationClick
),
PostCardBuilderParams(
posts = cards?.model?.firstOrNull { it is PostsCardModel } as? PostsCardModel,
onPostItemClick = this::onPostItemClick,
onFooterLinkClick = this::onPostCardFooterLinkClick
),
QuickActionsCardBuilderParams(
siteModel = site,
activeTask = activeTask,
onQuickActionStatsClick = this::quickActionStatsClick,
onQuickActionPagesClick = this::quickActionPagesClick,
onQuickActionPostsClick = this::quickActionPostsClick,
onQuickActionMediaClick = this::quickActionMediaClick
),
QuickStartCardBuilderParams(
quickStartCategories = quickStartCategories,
onQuickStartBlockRemoveMenuItemClick = this::onQuickStartBlockRemoveMenuItemClick,
onQuickStartTaskTypeItemClick = this::onQuickStartTaskTypeItemClick
),
SiteInfoCardBuilderParams(
site = site,
showSiteIconProgressBar = showSiteIconProgressBar,
titleClick = this::titleClick,
iconClick = this::iconClick,
urlClick = this::urlClick,
switchSiteClick = this::switchSiteClick,
activeTask = activeTask
)
)
val dynamicCards = dynamicCardsBuilder.build(
quickStartCategories,
pinnedDynamicCard,
visibleDynamicCards,
this::onDynamicCardMoreClick,
this::onQuickStartTaskCardClick
)

val siteItems = siteItemsBuilder.build(
SiteItemsBuilderParams(
site = site,
activeTask = activeTask,
backupAvailable = backupAvailable,
scanAvailable = scanAvailable,
onClick = this::onItemClick
)
)
return orderForDisplay(cardsResult, dynamicCards, siteItems)
}

private fun buildNoSiteState(): NoSites {
// Hide actionable empty view image when screen height is under specified min height.
val shouldShowImage = displayUtilsWrapper.getDisplayPixelHeight() >= MIN_DISPLAY_PX_HEIGHT_NO_SITE_IMAGE
return NoSites(shouldShowImage)
}

private fun orderForDisplay(
cards: List<MySiteCardAndItem>,
dynamicCards: List<MySiteCardAndItem>,
siteItems: List<MySiteCardAndItem>
): List<MySiteCardAndItem> {
val indexOfPostsCard = cards.indexOfFirst { it is PostCard }
return if (indexOfPostsCard == -1) {
cards + dynamicCards + siteItems
} else {
mutableListOf<MySiteCardAndItem>().apply {
addAll(cards)
addAll(indexOfPostsCard, dynamicCards)
addAll(siteItems)
}.toList()
}
}

private fun scrollToQuickStartTaskIfNecessary(
quickStartTask: QuickStartTask?,
position: Int
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType
import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsResult
import org.wordpress.android.test
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistrationCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.PostCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.PostCard.FooterLink
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.PostCard.PostCardWithPostItems
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.PostCard.PostCardWithPostItems.PostItem
@@ -1375,6 +1376,28 @@ class MySiteViewModelTest : BaseUnitTest() {
verify(mySiteSourceManager).clear()
}

/* ORDERED LIST */
@InternalCoroutinesApi
@Test
fun `given no post cards exist, when cardAndItems list is ordered, then dynamic card follow all cards`() {
whenever(mySiteDashboardPhase2FeatureConfig.isEnabled()).thenReturn(false)
initSelectedSite(isQuickStartDynamicCardEnabled = true)

assertThat(getLastItems().last()).isInstanceOf(DynamicCard::class.java)
}

@InternalCoroutinesApi
@Test
fun `given post cards exist, when cardAndItems list is ordered, then dynamic cards precede the post cards`() {
whenever(mySiteDashboardPhase2FeatureConfig.isEnabled()).thenReturn(true)
initSelectedSite(isQuickStartDynamicCardEnabled = true)

val postCardIndex = getLastItems().indexOfFirst { it is PostCard }
val dynamicCardIndex = getLastItems().indexOfFirst { it is DynamicCard }

assertThat(dynamicCardIndex).isLessThan(postCardIndex)
}

private fun findQuickActionsCard() = getLastItems().find { it is QuickActionsCard } as QuickActionsCard?

private fun findQuickStartDynamicCard() = getLastItems().find { it is DynamicCard } as DynamicCard?
@@ -1441,7 +1464,22 @@ class MySiteViewModelTest : BaseUnitTest() {
val domainRegistrationCard = initDomainRegistrationCard(it)
val quickStartCard = initQuickStartCard(it)
val postCard = initPostCard(it)
listOf<MySiteCardAndItem>(siteInfoCard, quickActionsCard, domainRegistrationCard, quickStartCard, postCard)
if (mySiteDashboardPhase2FeatureConfig.isEnabled()) {
listOf<MySiteCardAndItem>(
siteInfoCard,
quickActionsCard,
domainRegistrationCard,
quickStartCard,
postCard
)
} else {
listOf<MySiteCardAndItem>(
siteInfoCard,
quickActionsCard,
domainRegistrationCard,
quickStartCard
)
}
}.whenever(cardsBuilder).build(
domainRegistrationCardBuilderParams = any(),
postCardBuilderParams = any(),