Skip to content

Commit

Permalink
Merge pull request #18843 from wordpress-mobile/issue/18787-blaze-ove…
Browse files Browse the repository at this point in the history
…rlay-1x

Blaze: Show the blaze overlay once
  • Loading branch information
AjeshRPai authored Jul 27, 2023
2 parents f784e71 + c7a6523 commit 48da759
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 12 deletions.
2 changes: 1 addition & 1 deletion WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode_ui"/>

<activity android:name=".ui.blaze.blazepromote.BlazeParentActivity"
<activity android:name=".ui.blaze.blazepromote.BlazePromoteParentActivity"
android:exported="false"
android:label="@string/blaze_activity_title"
android:screenOrientation="portrait"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.wordpress.android.ui.activitylog.detail.ActivityLogDetailActivity;
import org.wordpress.android.ui.activitylog.list.ActivityLogListActivity;
import org.wordpress.android.ui.blaze.BlazeFlowSource;
import org.wordpress.android.ui.blaze.blazepromote.BlazeParentActivity;
import org.wordpress.android.ui.blaze.blazepromote.BlazePromoteParentActivity;
import org.wordpress.android.ui.blaze.PageUIModel;
import org.wordpress.android.ui.blaze.PostUIModel;
import org.wordpress.android.ui.bloggingprompts.promptslist.BloggingPromptsListActivity;
Expand Down Expand Up @@ -1872,7 +1872,7 @@ public static void openJetpackForDeeplink(@NonNull Context context, String actio
public static void openPromoteWithBlaze(@NonNull Context context,
@Nullable PostModel postModel,
@NonNull BlazeFlowSource source) {
Intent intent = new Intent(context, BlazeParentActivity.class);
Intent intent = new Intent(context, BlazePromoteParentActivity.class);
if (postModel != null) {
PostUIModel postUIModel = new PostUIModel(
postModel.getRemotePostId(),
Expand All @@ -1889,7 +1889,7 @@ public static void openPromoteWithBlaze(@NonNull Context context,
public static void openPromoteWithBlaze(@NonNull Context context,
@NonNull PageModel page,
@NonNull BlazeFlowSource source) {
Intent intent = new Intent(context, BlazeParentActivity.class);
Intent intent = new Intent(context, BlazePromoteParentActivity.class);
PageUIModel pageUIModel = new PageUIModel(
page.getPost().getRemotePostId(),
page.getPost().getTitle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.wordpress.android.ui.blaze.blazecampaigns.BlazeCampaignParentActivity
import org.wordpress.android.ui.blaze.blazecampaigns.campaigndetail.CampaignDetailPageSource
import org.wordpress.android.ui.blaze.blazecampaigns.campaignlisting.CampaignListingPageSource
import org.wordpress.android.ui.blaze.blazepromote.ARG_BLAZE_FLOW_SOURCE
import org.wordpress.android.ui.blaze.blazepromote.BlazeParentActivity
import org.wordpress.android.ui.blaze.blazepromote.BlazePromoteParentActivity
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -45,7 +45,7 @@ class ActivityNavigator @Inject constructor() {
context: Context,
source: BlazeFlowSource
) {
val intent = Intent(context, BlazeParentActivity::class.java)
val intent = Intent(context, BlazePromoteParentActivity::class.java)
intent.putExtra(ARG_BLAZE_FLOW_SOURCE, source)
context.startActivity(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class BlazeFeatureUtils @Inject constructor(

fun shouldShowBlazeCampaigns() = blazeManageCampaignFeatureConfig.isEnabled()

fun shouldHideBlazeOverlay() = appPrefsWrapper.getShouldHideBlazeOverlay()

fun setShouldHideBlazeOverlay() = appPrefsWrapper.setShouldHideBlazeOverlay(true)

fun track(stat: AnalyticsTracker.Stat, source: BlazeFlowSource) {
analyticsTrackerWrapper.track(
stat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class BlazeViewModel @Inject constructor(
}

private fun initializePromoteContentUIState(blazeUIModel: BlazeUIModel) {
blazeFeatureUtils.trackOverlayDisplayed(blazeFlowSource)
when(blazeUIModel) {
is PostUIModel -> initializePromotePostUIState(blazeUIModel)
is PageUIModel -> initializePromotePageUIState(blazeUIModel)
Expand All @@ -57,8 +56,13 @@ class BlazeViewModel @Inject constructor(
postModel.featuredImageId)
}
)
_uiState.value = BlazeUiState.PromoteScreen.PromotePost(updatedPostModel)

_promoteUiState.value = BlazeUiState.PromoteScreen.PromotePost(updatedPostModel)
_uiState.value = if (shouldShowOverlayAndTrack()) {
BlazeUiState.PromoteScreen.PromotePost(updatedPostModel)
} else {
BlazeUiState.WebViewScreen
}
}

private fun initializePromotePageUIState(pageModel: PageUIModel) {
Expand All @@ -69,14 +73,31 @@ class BlazeViewModel @Inject constructor(
pageModel.featuredImageId
)
)
_uiState.value = BlazeUiState.PromoteScreen.PromotePage(updatedPageModel)

_promoteUiState.value = BlazeUiState.PromoteScreen.PromotePage(updatedPageModel)
_uiState.value = if (shouldShowOverlayAndTrack()) {
BlazeUiState.PromoteScreen.PromotePage(updatedPageModel)
} else {
BlazeUiState.WebViewScreen
}
}

private fun initializePromoteSiteUIState() {
blazeFeatureUtils.trackOverlayDisplayed(blazeFlowSource)
_uiState.value = BlazeUiState.PromoteScreen.Site
_promoteUiState.value = BlazeUiState.PromoteScreen.Site
_uiState.value = if (shouldShowOverlayAndTrack()) {
BlazeUiState.PromoteScreen.Site
} else {
BlazeUiState.WebViewScreen
}
}

private fun shouldShowOverlayAndTrack() : Boolean {
val shouldShowOverlay = !blazeFeatureUtils.shouldHideBlazeOverlay()
if (shouldShowOverlay) {
blazeFeatureUtils.trackOverlayDisplayed(blazeFlowSource)
blazeFeatureUtils.setShouldHideBlazeOverlay()
}
return shouldShowOverlay
}

// to do: tracking logic and logic for done state - this might not be where we want to track
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const val ARG_EXTRA_BLAZE_UI_MODEL = "blaze_ui_model"
const val ARG_BLAZE_FLOW_SOURCE = "blaze_flow_source"

@AndroidEntryPoint
class BlazeParentActivity : AppCompatActivity() {
class BlazePromoteParentActivity : AppCompatActivity() {
private val viewModel: BlazeViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public enum DeletablePrefKey implements PrefKey {
WP_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY_LAST_SHOWN_TIMESTAMP,
NOTIFICATIONS_PERMISSION_WARNING_DISMISSED,
HAS_SAVED_PRIVACY_SETTINGS,
SHOULD_HIDE_BLAZE_OVERLAY,
}

/**
Expand Down Expand Up @@ -1674,4 +1675,12 @@ public static boolean getNotificationsPermissionsWarningDismissed() {
public static void setNotificationsPermissionWarningDismissed(boolean dismissed) {
setBoolean(DeletablePrefKey.NOTIFICATIONS_PERMISSION_WARNING_DISMISSED, dismissed);
}

public static Boolean getShouldHideBlazeOverlay() {
return getBoolean(DeletablePrefKey.SHOULD_HIDE_BLAZE_OVERLAY, false);
}

public static void setShouldHideBlazeOverlay(final boolean isHidden) {
setBoolean(DeletablePrefKey.SHOULD_HIDE_BLAZE_OVERLAY, isHidden);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ class AppPrefsWrapper @Inject constructor() {
fun incrementWPJetpackIndividualPluginOverlayShownCount() =
AppPrefs.incrementWPJetpackIndividualPluginOverlayShownCount()

fun getShouldHideBlazeOverlay(): Boolean =
AppPrefs.getShouldHideBlazeOverlay()

fun setShouldHideBlazeOverlay(isHidden: Boolean) =
AppPrefs.setShouldHideBlazeOverlay(isHidden)

fun getAllPrefs(): Map<String, Any?> = AppPrefs.getAllPrefs()

fun setString(prefKey: PrefKey, value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.store.MediaStore
import org.wordpress.android.ui.blaze.BlazeFeatureUtils
import org.wordpress.android.ui.blaze.BlazeFlowSource
import org.wordpress.android.ui.blaze.BlazeUiState
import org.wordpress.android.ui.blaze.PageUIModel
import org.wordpress.android.ui.blaze.PostUIModel
import org.wordpress.android.ui.blaze.blazeoverlay.BlazeViewModel
import org.wordpress.android.ui.mysite.SelectedSiteRepository
Expand All @@ -34,6 +37,8 @@ class BlazeViewModelTest : BaseUnitTest() {

private lateinit var blazeViewModel: BlazeViewModel

private lateinit var uiStates: MutableList<BlazeUiState>
private lateinit var promoteUiState: MutableList<BlazeUiState>
@Before
fun setUp() {
blazeViewModel = BlazeViewModel(
Expand All @@ -42,6 +47,14 @@ class BlazeViewModelTest : BaseUnitTest() {
mediaStore,
selectedSiteRepository
)
uiStates = mutableListOf()
promoteUiState = mutableListOf()
blazeViewModel.promoteUiState.observeForever {
promoteUiState.add(it)
}
blazeViewModel.uiState.observeForever {
uiStates.add(it)
}
}

@Test
Expand All @@ -55,4 +68,92 @@ class BlazeViewModelTest : BaseUnitTest() {

Assertions.assertThat(result).isNotNull
}

@Test
fun `given blaze overlay shown is false, when started from post list, then uiState is set to promote post`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

val model = PostUIModel(postId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.POSTS_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.PromotePost::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from post list, then uiState is set to webview screen`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

val model = PostUIModel(postId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.POSTS_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}

@Test
fun `given blaze overlay shown is false, when started from page list, then uiState is set to promote post`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

val model = PageUIModel(pageId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.PAGES_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.PromotePage::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from page list, then uiState is set to webview screen`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

val model = PageUIModel(pageId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.PAGES_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}

@Test
fun `given blaze overlay shown is false, when started from dashboard card, then uiState is set to site`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

blazeViewModel.start(BlazeFlowSource.DASHBOARD_CARD, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.Site::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from dashboard card, then uiState is set to webview screen`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

blazeViewModel.start(BlazeFlowSource.DASHBOARD_CARD, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}

@Test
fun `given blaze overlay shown is false, when started from no campaigns list, then uiState is set to site`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

blazeViewModel.start(BlazeFlowSource.CAMPAIGN_LISTING_PAGE, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.Site::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from no campaigns list, then uiState is set to webview`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

blazeViewModel.start(BlazeFlowSource.CAMPAIGN_LISTING_PAGE, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}
}

0 comments on commit 48da759

Please sign in to comment.