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

Unified Dashboard: Quick Start Support #19318

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7faa984
Add QuickStartMenuStep to support steps that are in the more menu.
zwarm Oct 5, 2023
a2e96cf
Adjust tests to support QuickStartMenuStep
zwarm Oct 5, 2023
d09177a
Refactor: use QuickStartMenuStep instead of activeTask because more f…
zwarm Oct 5, 2023
021fcc0
Refactor: have quickLins depend on quickStartMenuStep and not activeT…
zwarm Oct 5, 2023
d3ba37c
Refactor tests to support QuickStartMenuStep for the more menu
zwarm Oct 5, 2023
e7c970b
Remove todo
zwarm Oct 5, 2023
a369634
Update tests to support QuickStartMenuStep
zwarm Oct 5, 2023
2e9b37a
Refactor: Add quickStartEvent to OpenMore class
zwarm Oct 6, 2023
14b49bd
Refactor: Set quickStartEvent in OpenMore SiteNavigationAction
zwarm Oct 6, 2023
c767915
Refactor: Pass along quickStartEvent from OpenMore SiteNavigationActi…
zwarm Oct 6, 2023
9da06b9
Add intent KEY for quick start event
zwarm Oct 6, 2023
cb5bb8c
Set quickStartEvent, if available in openUnifiedSiteMenu
zwarm Oct 6, 2023
c80341b
Refactor: add isFromMenu boolean to setActiveTask so the next step of…
zwarm Oct 6, 2023
05c27a4
Refactor: add separate click for more if in a quick start situation
zwarm Oct 6, 2023
560da03
Capture quickStartPrompts and snackbarMessage from quickStartRepo. Ha…
zwarm Oct 6, 2023
35e0236
Observe quickStartPrompts and snackbarMessage from quickStartRepo.Pas…
zwarm Oct 6, 2023
0924f4b
Refactor: swap the double bang for let to handle resetting the menuStep
zwarm Oct 6, 2023
b081c1d
Refactor: set the constants to public so they can be used for quickst…
zwarm Oct 9, 2023
f6936c3
Add callback to tie in compose views; they don't show traditional sna…
zwarm Oct 9, 2023
1a38f7f
Add support for showing quickStart snackbars for quick start.
zwarm Oct 9, 2023
501dd85
Add support for showing quickStart snackbars for quick start by hooki…
zwarm Oct 9, 2023
69ba37c
Add a delay before showing the snackbar because the QuickStartEvent a…
zwarm Oct 9, 2023
52326d1
Refactor: set mocks for new di injections
zwarm Oct 9, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignLis
import org.wordpress.android.ui.blaze.blazepromote.ARG_BLAZE_FLOW_SOURCE
import org.wordpress.android.ui.blaze.blazepromote.ARG_BLAZE_SHOULD_SHOW_OVERLAY
import org.wordpress.android.ui.blaze.blazepromote.BlazePromoteParentActivity
import org.wordpress.android.ui.mysite.menu.KEY_QUICK_START_EVENT
import org.wordpress.android.ui.mysite.menu.MenuActivity
import org.wordpress.android.ui.mysite.personalization.PersonalizationActivity
import org.wordpress.android.ui.quickstart.QuickStartEvent
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -66,7 +68,15 @@ class ActivityNavigator @Inject constructor() {
context.startActivity(Intent(context, PersonalizationActivity::class.java))
}

fun openUnifiedMySiteMenu(context: Context) {
fun openUnifiedMySiteMenu(context: Context, quickStartEvent: QuickStartEvent? = null) {
if (quickStartEvent != null) {
context.startActivity(
Intent(context, MenuActivity::class.java).apply {
putExtra(KEY_QUICK_START_EVENT, quickStartEvent)
}
)
return
}
context.startActivity(Intent(context, MenuActivity::class.java))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.wordpress.android.util.NetworkUtils;
import org.wordpress.android.util.QuickStartUtilsWrapper;
import org.wordpress.android.util.SnackbarItem;
import org.wordpress.android.util.SnackbarItem.Info;
import org.wordpress.android.util.SnackbarSequencer;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.WPMediaUtils;
Expand Down Expand Up @@ -253,11 +254,9 @@ private void showQuickStartSnackbar() {
R.string.quick_start_dialog_upload_media_message_short_plus,
R.drawable.ic_plus_white_12dp
);
mSnackbarSequencer.enqueue(
new SnackbarItem(
new SnackbarItem.Info(getSnackbarParent(), new UiStringText(title), Snackbar.LENGTH_LONG)
)
);
new Handler().postDelayed(() -> mSnackbarSequencer.enqueue(
new SnackbarItem(new Info(getSnackbarParent(), new UiStringText(title), Snackbar.LENGTH_LONG))
), 500L);
}

private View getSnackbarParent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,10 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
is SiteNavigationAction.OpenThemes -> ActivityLauncher.viewCurrentBlogThemes(activity, action.site)
is SiteNavigationAction.OpenPlugins -> ActivityLauncher.viewPluginBrowser(activity, action.site)
is SiteNavigationAction.OpenMedia -> ActivityLauncher.viewCurrentBlogMedia(activity, action.site)
// is SiteNavigationAction.OpenMore -> ActivityLauncher.viewQuickLinkMoreMenu(activity, action.site)
is SiteNavigationAction.OpenMore -> activityNavigator.openUnifiedMySiteMenu(requireActivity())
is SiteNavigationAction.OpenMore -> activityNavigator.openUnifiedMySiteMenu(
requireActivity(),
action.quickStartEvent
)
is SiteNavigationAction.OpenUnifiedComments -> ActivityLauncher.viewUnifiedComments(activity, action.site)
is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(activity, action.site)
is SiteNavigationAction.ConnectJetpackForStats ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlinx.coroutines.launch
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode.MAIN
import org.wordpress.android.R
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.model.SiteModel
Expand Down Expand Up @@ -182,11 +181,11 @@ class MySiteViewModel @Inject constructor(

val quickLinks: LiveData<MySiteCardAndItem.Card.QuickLinksItem> = merge(
quickLinksItemViewModelSlice.uiState,
quickStartRepository.activeTask
) { quickLinks, activeTask ->
quickStartRepository.quickStartMenuStep
) { quickLinks, quickStartMenuStep ->
if (quickLinks != null &&
activeTask != null) {
return@merge quickLinksItemViewModelSlice.updateToShowMoreFocusPointIfNeeded(quickLinks, activeTask)
quickStartMenuStep != null) {
return@merge quickLinksItemViewModelSlice.updateToShowMoreFocusPointIfNeeded(quickLinks, quickStartMenuStep)
}
return@merge quickLinks
}
Expand Down Expand Up @@ -702,7 +701,7 @@ class MySiteViewModel @Inject constructor(
}

fun handleSuccessfulDomainRegistrationResult(email: String?) {
analyticsTrackerWrapper.track(AnalyticsTracker.Stat.DOMAIN_CREDIT_REDEMPTION_SUCCESS)
analyticsTrackerWrapper.track(Stat.DOMAIN_CREDIT_REDEMPTION_SUCCESS)
_onSnackbarMessage.postValue(Event(SnackbarMessageHolder(getEmailValidationMessage(email))))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.wordpress.android.ui.blaze.BlazeFlowSource
import org.wordpress.android.ui.blaze.blazecampaigns.campaigndetail.CampaignDetailPageSource
import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource
import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil.JetpackFeatureCollectionOverlaySource
import org.wordpress.android.ui.quickstart.QuickStartEvent
import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource
import org.wordpress.android.util.UriWrapper

Expand Down Expand Up @@ -39,7 +40,7 @@ sealed class SiteNavigationAction {
data class OpenThemes(val site: SiteModel) : SiteNavigationAction()
data class OpenPlugins(val site: SiteModel) : SiteNavigationAction()
data class OpenMedia(val site: SiteModel) : SiteNavigationAction()
data class OpenMore(val site:SiteModel) : SiteNavigationAction()
data class OpenMore(val site:SiteModel, val quickStartEvent: QuickStartEvent?) : SiteNavigationAction()
data class OpenUnifiedComments(val site: SiteModel) : SiteNavigationAction()
object StartWPComLoginForJetpackStats : SiteNavigationAction()
data class OpenStats(val site: SiteModel) : SiteNavigationAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignLis
import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper
import org.wordpress.android.ui.mysite.SiteNavigationAction
import org.wordpress.android.ui.mysite.items.listitem.ListItemAction
import org.wordpress.android.ui.quickstart.QuickStartEvent
import javax.inject.Inject

class ListItemActionHandler @Inject constructor(
private val accountStore: AccountStore,
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper,
private val blazeFeatureUtils: BlazeFeatureUtils
) {
fun handleAction(action: ListItemAction, selectedSite: SiteModel): SiteNavigationAction {
fun handleAction(
action: ListItemAction,
selectedSite: SiteModel,
quickStartEvent: QuickStartEvent? = null
): SiteNavigationAction {
return when (action) {
ListItemAction.ACTIVITY_LOG -> SiteNavigationAction.OpenActivityLog(selectedSite)
ListItemAction.BACKUP -> SiteNavigationAction.OpenBackup(selectedSite)
Expand All @@ -35,7 +40,7 @@ class ListItemActionHandler @Inject constructor(
ListItemAction.MEDIA -> SiteNavigationAction.OpenMedia(selectedSite)
ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite)
ListItemAction.BLAZE -> onBlazeMenuItemClick()
ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite)
ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite, quickStartEvent)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItemBuilderParams
import org.wordpress.android.ui.mysite.SelectedSiteRepository
import org.wordpress.android.ui.mysite.SiteNavigationAction
import org.wordpress.android.ui.mysite.cards.ListItemActionHandler
import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository
import org.wordpress.android.ui.mysite.items.listitem.ListItemAction
import org.wordpress.android.ui.mysite.items.listitem.SiteItemsBuilder
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.ui.quickstart.QuickStartEvent
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.viewmodel.Event
Expand All @@ -33,6 +35,7 @@ class QuickLinksItemViewModelSlice @Inject constructor(
private val listItemActionHandler: ListItemActionHandler,
private val blazeFeatureUtils: BlazeFeatureUtils,
private val appPrefsWrapper: AppPrefsWrapper,
private val quickStartRepository: QuickStartRepository
) {
lateinit var scope: CoroutineScope

Expand Down Expand Up @@ -159,11 +162,17 @@ class QuickLinksItemViewModelSlice @Inject constructor(

fun updateToShowMoreFocusPointIfNeeded(
quickLinks: MySiteCardAndItem.Card.QuickLinksItem,
activeTask: QuickStartStore.QuickStartTask
quickStartMenuStep: QuickStartRepository.QuickStartMenuStep
): MySiteCardAndItem.Card.QuickLinksItem {
val updatedQuickLinks = if (isActiveTaskInMoreMenu(activeTask)) {
val updatedQuickLinks = if (isActiveTaskInMoreMenu(quickStartMenuStep.task)) {
val quickLinkItems = quickLinks.quickLinkItems.toMutableList()
val lastItem = quickLinkItems.last().copy(showFocusPoint = true)
val lastItem = quickLinkItems.last().copy(showFocusPoint = true,
onClick = ListItemInteraction.create(
MoreClickWithTask(ListItemAction.MORE,
QuickStartEvent(task = quickStartMenuStep.task!!)
),
this@QuickLinksItemViewModelSlice::onMoreClick
))
quickLinkItems.removeLast()
quickLinkItems.add(lastItem)
quickLinks.copy(quickLinkItems = quickLinkItems, showMoreFocusPoint = true)
Expand All @@ -173,6 +182,26 @@ class QuickLinksItemViewModelSlice @Inject constructor(
return updatedQuickLinks
}

private fun onMoreClick(moreClickWithTask: MoreClickWithTask) {
quickStartRepository.clearMenuStep()
selectedSiteRepository.getSelectedSite()?.let { selectedSite ->
// add the tracking logic here
_onNavigation.postValue(
Event(
listItemActionHandler.handleAction(
moreClickWithTask.listActionType,
selectedSite,
moreClickWithTask.quickStartEvent
)
)
)
} ?: run {
_onSnackbarMessage.postValue(
Event(SnackbarMessageHolder(UiString.UiStringRes(R.string.site_cannot_be_loaded)))
)
}
}

private fun isActiveTaskInMoreMenu(activeTask: QuickStartStore.QuickStartTask?): Boolean {
return activeTask == QuickStartStore.QuickStartNewSiteTask.REVIEW_PAGES ||
activeTask == QuickStartStore.QuickStartNewSiteTask.CHECK_STATS ||
Expand All @@ -184,4 +213,9 @@ class QuickLinksItemViewModelSlice @Inject constructor(
fun onSiteChanged() {
buildQuickLinks()
}

data class MoreClickWithTask(
val listActionType: ListItemAction,
val quickStartEvent: QuickStartEvent
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ class QuickStartRepository
private val _activeTask = MutableLiveData<QuickStartTask?>()
private val _onSnackbar = MutableLiveData<Event<SnackbarMessageHolder>>()
private val _onQuickStartMySitePrompts = MutableLiveData<Event<QuickStartMySitePrompts>>()
private val _quickStartMenuStep = MutableLiveData<QuickStartMenuStep?>()
private var _isQuickStartNoticeShown: Boolean = false
val onSnackbar = _onSnackbar as LiveData<Event<SnackbarMessageHolder>>
val onQuickStartMySitePrompts = _onQuickStartMySitePrompts as LiveData<Event<QuickStartMySitePrompts>>
val activeTask = _activeTask as LiveData<QuickStartTask?>
val quickStartMenuStep = _quickStartMenuStep as LiveData<QuickStartMenuStep?>
val isQuickStartNoticeShown = _isQuickStartNoticeShown
val quickStartType: QuickStartType
get() = selectedSiteRepository.getSelectedSite()?.let {
Expand All @@ -93,6 +95,7 @@ class QuickStartRepository
fun resetTask() {
clearActiveTask()
clearPendingTask()
clearMenuStep()
}

fun clearActiveTask() {
Expand Down Expand Up @@ -125,10 +128,12 @@ class QuickStartRepository
}
}

fun setActiveTask(task: QuickStartTask) {
fun setActiveTask(task: QuickStartTask, isFromMenu: Boolean = false) {
_activeTask.postValue(task)
clearPendingTask()
clearMenuStep()
when {
!isFromMenu && task.isShownInMenu() -> requestMoreStepForTask(task)
task == QuickStartNewSiteTask.UPDATE_SITE_TITLE -> {
val shortQuickStartMessage = resourceProvider.getString(
R.string.quick_start_dialog_update_site_title_message_short,
Expand Down Expand Up @@ -184,6 +189,18 @@ class QuickStartRepository
quickStartTracker.track(quickStartUtilsWrapper.getTaskCompletedTracker(task))
}

private fun requestMoreStepForTask(task: QuickStartTask) {
clearActiveTask()
pendingTask = task
val shortQuickStartMessage = resourceProvider.getString(
R.string.quick_start_site_menu_tab_message_short,
resourceProvider.getString(R.string.more)
)

_onSnackbar.postValue(Event(SnackbarMessageHolder(UiStringText(htmlCompat.fromHtml(shortQuickStartMessage)))))
_quickStartMenuStep.postValue(QuickStartMenuStep(true, task))
}

fun requestNextStepOfTask(task: QuickStartTask) {
if (task != activeTask.value) return
clearActiveTask()
Expand All @@ -206,7 +223,7 @@ class QuickStartRepository
}
}

fun showCompletedQuickStartNotice() {
private fun showCompletedQuickStartNotice() {
launch {
delay(QUICK_START_COMPLETED_NOTICE_DELAY)
val message = htmlMessageUtils.getHtmlMessageFromStringFormat(
Expand Down Expand Up @@ -273,12 +290,32 @@ class QuickStartRepository
appPrefsWrapper.setLastSkippedQuickStartTask(task)
}

private fun QuickStartTask.isShownInMenu() =
when (this) {
quickStartType.getTaskFromString(QuickStartStore.QUICK_START_CHECK_STATS_LABEL),
quickStartType.getTaskFromString(QuickStartStore.QUICK_START_UPLOAD_MEDIA_LABEL),
QuickStartNewSiteTask.REVIEW_PAGES,
QuickStartNewSiteTask.CHECK_STATS,
QuickStartNewSiteTask.ENABLE_POST_SHARING -> true
else -> false
}

fun clearMenuStep() {
if (_quickStartMenuStep.value != null) {
_quickStartMenuStep.value = null
}
}

data class QuickStartCategory(
val taskType: QuickStartTaskType,
val uncompletedTasks: List<QuickStartTaskDetails>,
val completedTasks: List<QuickStartTaskDetails>
)

data class QuickStartMenuStep(
val isStarted: Boolean,
val task: QuickStartTask? = null
)
companion object {
private const val QUICK_START_NOTICE_DURATION = 7000
private const val QUICK_START_COMPLETED_NOTICE_DELAY = 5000L
Expand Down
Loading