Skip to content

Commit

Permalink
Merge branch 'trunk' into 12074-woo-pos-move-floating-toolbar-to-the-…
Browse files Browse the repository at this point in the history
…home-screen-from-the-root
  • Loading branch information
kidinov authored Jul 24, 2024
2 parents 2aae80a + 8dba5e3 commit 8469716
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ object AppUrls {

// Google for Woo
const val GOOGLE_ADMIN_CAMPAIGN_CREATION_SUFFIX =
"admin.php?page=wc-admin&path=%2Fgoogle%2Fsetup-ads"
"admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&subpath=%2Fcampaigns%2Fcreate"

const val GOOGLE_ADMIN_CAMPAIGN_CREATION_SUCCESS_SUFFIX =
"admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&campaign=saved"
const val GOOGLE_ADMIN_FIRST_CAMPAIGN_CREATION_SUCCESS_TRIGGER = "guide=campaign-creation-success"
const val GOOGLE_ADMIN_SUBSEQUENT_CAMPAIGN_CREATION_SUCCESS_TRIGGER = "campaign=saved"

const val GOOGLE_ADMIN_DASHBOARD =
"admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import com.google.android.material.badge.BadgeUtils
import com.google.android.material.badge.ExperimentalBadgeUtils
import com.google.android.play.core.review.ReviewManagerFactory
import com.woocommerce.android.AppPrefsWrapper
import com.woocommerce.android.NavGraphMainDirections
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.databinding.FragmentDashboardBinding
import com.woocommerce.android.extensions.getColorCompat
import com.woocommerce.android.extensions.handleNotice
import com.woocommerce.android.extensions.navigateSafely
import com.woocommerce.android.extensions.scrollStartEvents
import com.woocommerce.android.extensions.showDateRangePicker
Expand All @@ -46,6 +48,7 @@ import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.Sh
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.ShowAIProductDescriptionDialog
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.ShowPrivacyBanner
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel
import com.woocommerce.android.ui.google.webview.GoogleAdsWebViewFragment
import com.woocommerce.android.ui.jitm.JitmFragment
import com.woocommerce.android.ui.jitm.JitmMessagePathsProvider
import com.woocommerce.android.ui.main.AppBarStatus
Expand Down Expand Up @@ -144,6 +147,7 @@ class DashboardFragment :
.launchIn(viewLifecycleOwner.lifecycleScope)

setupStateObservers()
setupResultHandlers()
}

@Suppress("ComplexMethod", "MagicNumber", "LongMethod")
Expand Down Expand Up @@ -207,6 +211,12 @@ class DashboardFragment :
}
}

private fun setupResultHandlers() {
handleNotice(GoogleAdsWebViewFragment.WEBVIEW_RESULT) {
navigateToGoogleAdsCreationSuccess()
}
}

private fun onVisitorStatsUnavailable(jetpackBenefitsBanner: DashboardViewModel.JetpackBenefitsBannerUiModel?) {
if (jetpackBenefitsBanner == null) {
binding.jetpackBenefitsBanner.root.isVisible = false
Expand Down Expand Up @@ -328,6 +338,12 @@ class DashboardFragment :
}
}

private fun navigateToGoogleAdsCreationSuccess() {
findNavController().navigateSafely(
NavGraphMainDirections.actionGlobalGoogleAdsCampaignSuccessBottomSheet()
)
}

override fun shouldExpandToolbar() = binding.statsScrollView.scrollY == 0

@OptIn(ExperimentalBadgeUtils::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import com.woocommerce.android.NavGraphMainDirections
import com.woocommerce.android.R
import com.woocommerce.android.extensions.navigateSafely
import com.woocommerce.android.model.DashboardWidget
import com.woocommerce.android.ui.common.exitawarewebview.ExitAwareWebViewViewModel
import com.woocommerce.android.ui.common.wpcomwebview.WPComWebViewViewModel
import com.woocommerce.android.ui.compose.animations.SkeletonView
import com.woocommerce.android.ui.compose.component.WCOutlinedButton
import com.woocommerce.android.ui.compose.rememberNavController
Expand All @@ -45,6 +43,7 @@ import com.woocommerce.android.ui.dashboard.DashboardViewModel
import com.woocommerce.android.ui.dashboard.WidgetCard
import com.woocommerce.android.ui.dashboard.WidgetError
import com.woocommerce.android.ui.dashboard.google.DashboardGoogleAdsViewModel.DashboardGoogleAdsState
import com.woocommerce.android.ui.google.webview.GoogleAdsWebViewViewModel
import com.woocommerce.android.viewmodel.MultiLiveEvent

@Composable
Expand Down Expand Up @@ -79,21 +78,12 @@ private fun HandleEvents(
val observer = Observer { event: MultiLiveEvent.Event ->
when (event) {
is DashboardGoogleAdsViewModel.ViewGoogleForWooEvent -> {
val direction = if (event.canAutoLogin) {
NavGraphMainDirections.actionGlobalWPComWebViewFragment(
urlToLoad = event.url,
urlsToTriggerExit = arrayOf(), // todo-11917: Replace with the right success URL
title = webViewTitle,
urlComparisonMode = WPComWebViewViewModel.UrlComparisonMode.PARTIAL
)
} else {
NavGraphMainDirections.actionGlobalExitAwareWebViewFragment(
urlToLoad = event.url,
urlsToTriggerExit = arrayOf(), // todo-11917: Replace with the right success URL
title = webViewTitle,
urlComparisonMode = ExitAwareWebViewViewModel.UrlComparisonMode.PARTIAL
)
}
val direction = NavGraphMainDirections.actionGlobalGoogleAdsWebViewFragment(
urlToLoad = event.url,
urlsToTriggerExit = event.successUrls.toTypedArray(),
title = webViewTitle,
urlComparisonMode = GoogleAdsWebViewViewModel.UrlComparisonMode.PARTIAL
)

navController.navigateSafely(direction)
}
Expand Down Expand Up @@ -138,6 +128,7 @@ fun DashboardGoogleAdsView(
viewState.onCreateCampaignClicked,
viewState.onPerformanceAreaClicked
)

is DashboardGoogleAdsState.Error -> {
WidgetError(
onContactSupportClicked = onContactSupportClicked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetAc
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetMenu
import com.woocommerce.android.ui.dashboard.DashboardViewModel.RefreshEvent
import com.woocommerce.android.ui.dashboard.defaultHideMenuEntry
import com.woocommerce.android.ui.google.CanUseAutoLoginWebview
import com.woocommerce.android.ui.google.HasGoogleAdsCampaigns
import com.woocommerce.android.viewmodel.MultiLiveEvent
import com.woocommerce.android.viewmodel.ScopedViewModel
Expand All @@ -37,7 +36,6 @@ class DashboardGoogleAdsViewModel @AssistedInject constructor(
private val selectedSite: SelectedSite,
@Assisted private val parentViewModel: DashboardViewModel,
private val hasGoogleAdsCampaigns: HasGoogleAdsCampaigns,
private val canUseAutoLoginWebview: CanUseAutoLoginWebview,
private val googleAdsStore: WCGoogleStore,
) : ScopedViewModel(savedStateHandle) {
companion object {
Expand All @@ -51,6 +49,11 @@ class DashboardGoogleAdsViewModel @AssistedInject constructor(
private val refreshTrigger = merge(_refreshTrigger, (parentViewModel.refreshTrigger))
.onStart { emit(RefreshEvent()) }

private val successUrlTriggers = listOf(
AppUrls.GOOGLE_ADMIN_FIRST_CAMPAIGN_CREATION_SUCCESS_TRIGGER,
AppUrls.GOOGLE_ADMIN_SUBSEQUENT_CAMPAIGN_CREATION_SUCCESS_TRIGGER
)

@OptIn(ExperimentalCoroutinesApi::class)
val viewState = refreshTrigger
.transformLatest {
Expand Down Expand Up @@ -111,12 +114,12 @@ class DashboardGoogleAdsViewModel @AssistedInject constructor(

private fun launchCampaignCreation() {
val creationUrl = selectedSite.get().adminUrlOrDefault + AppUrls.GOOGLE_ADMIN_CAMPAIGN_CREATION_SUFFIX
triggerEvent(ViewGoogleForWooEvent(creationUrl, canUseAutoLoginWebview()))
triggerEvent(ViewGoogleForWooEvent(creationUrl, successUrlTriggers))
}

private fun launchCampaignDetails() {
val adminUrl = selectedSite.get().adminUrlOrDefault + AppUrls.GOOGLE_ADMIN_DASHBOARD
triggerEvent(ViewGoogleForWooEvent(adminUrl, canUseAutoLoginWebview()))
triggerEvent(ViewGoogleForWooEvent(adminUrl, successUrlTriggers))
}

fun onRefresh() {
Expand Down Expand Up @@ -147,7 +150,10 @@ class DashboardGoogleAdsViewModel @AssistedInject constructor(
) : DashboardGoogleAdsState(menu, showAllCampaignsButton)
}

data class ViewGoogleForWooEvent(val url: String, val canAutoLogin: Boolean) : MultiLiveEvent.Event()
data class ViewGoogleForWooEvent(
val url: String,
val successUrls: List<String>
) : MultiLiveEvent.Event()

@AssistedFactory
interface Factory {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.woocommerce.android.ui.google.ads.success

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.woocommerce.android.R.dimen
import com.woocommerce.android.R.drawable
import com.woocommerce.android.R.string
import com.woocommerce.android.ui.compose.component.BottomSheetHandle
import com.woocommerce.android.ui.compose.component.WCColoredButton
import com.woocommerce.android.ui.compose.preview.LightDarkThemePreviews

@Composable
fun GoogleAdsCampaignSuccessBottomSheet(
onDoneTapped: () -> Unit,
modifier: Modifier = Modifier
) {
Surface(
shape = RoundedCornerShape(
topStart = dimensionResource(id = dimen.minor_100),
topEnd = dimensionResource(id = dimen.minor_100)
)
) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(modifier = Modifier.height(8.dp))
BottomSheetHandle(Modifier.align(Alignment.CenterHorizontally))
Spacer(modifier = Modifier.height(30.dp))
Image(
painter = painterResource(id = drawable.blaze_campaign_created_success),
contentDescription = ""
)
Spacer(modifier = Modifier.height(24.dp))
Text(
text = stringResource(id = string.google_ads_campaign_created_success_title),
style = MaterialTheme.typography.h6,
color = MaterialTheme.colors.onSurface
)
Spacer(modifier = Modifier.height(16.dp))
Text(
modifier = Modifier.padding(horizontal = 20.dp),
text = stringResource(id = string.google_ads_campaign_created_success_description),
style = MaterialTheme.typography.body1,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.onSurface
)
Spacer(modifier = Modifier.height(32.dp))
WCColoredButton(
onClick = onDoneTapped,
modifier = Modifier.fillMaxWidth()
) {
Text(text = stringResource(id = string.blaze_campaign_created_success_done_button))
}
Spacer(modifier = Modifier.height(16.dp))
}
}
}

@LightDarkThemePreviews
@Composable
private fun GoogleAdsCampaignSuccessBottomSheetPreview() {
GoogleAdsCampaignSuccessBottomSheet(onDoneTapped = {})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.woocommerce.android.ui.google.ads.success

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.woocommerce.android.ui.compose.composeView
import com.woocommerce.android.widgets.WCBottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class GoogleAdsCampaignSuccessBottomSheetFragment : WCBottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return composeView {
GoogleAdsCampaignSuccessBottomSheet(::onDoneClicked)
}
}

private fun onDoneClicked() {
dismiss()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.woocommerce.android.ui.common.exitawarewebview
package com.woocommerce.android.ui.google.webview

import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.viewModels
import com.woocommerce.android.R
import com.woocommerce.android.extensions.navigateBackWithNotice
import com.woocommerce.android.ui.base.BaseFragment
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
Expand All @@ -17,7 +16,7 @@ import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ExitWithResult
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ExitAwareWebViewFragment : BaseFragment(R.layout.fragment_exitaware_webview) {
class GoogleAdsWebViewFragment : BaseFragment() {
companion object {
const val WEBVIEW_RESULT = "webview-result"
const val WEBVIEW_DISMISSED = "webview-dismissed"
Expand All @@ -26,15 +25,15 @@ class ExitAwareWebViewFragment : BaseFragment(R.layout.fragment_exitaware_webvie
override val activityAppBarStatus: AppBarStatus
get() = AppBarStatus.Hidden

private val viewModel: ExitAwareWebViewViewModel by viewModels()
private val viewModel: GoogleAdsWebViewViewModel by viewModels()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

setContent {
WooThemeWithBackground {
ExitAwareWebViewScreen(viewModel)
GoogleAdsWebViewScreen(viewModel)
}
}
}
Expand Down
Loading

0 comments on commit 8469716

Please sign in to comment.