From 76105052fefe894bdbfb3cbd74a3eb46bbfa0ab0 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Mon, 4 Feb 2019 16:41:26 +0100 Subject: [PATCH 01/13] Add support for dialogFragment without title --- .../wordpress/android/ui/posts/BasicFragmentDialog.kt | 11 +++++++---- .../android/viewmodel/helpers/DialogHolder.kt | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt index 302656276dfc..5d3bbfe13246 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt @@ -14,9 +14,9 @@ import org.wordpress.android.R */ class BasicFragmentDialog : AppCompatDialogFragment() { private lateinit var mTag: String - private lateinit var mTitle: String private lateinit var mMessage: String private lateinit var mPositiveButtonLabel: String + private var mTitle: String? = null private var mNegativeButtonLabel: String? = null private var mCancelButtonLabel: String? = null private var dismissedByPositiveButton = false @@ -37,7 +37,7 @@ class BasicFragmentDialog : AppCompatDialogFragment() { fun initialize( tag: String, - title: String, + title: String? = null, message: String, positiveButtonLabel: String, negativeButtonLabel: String? = null, @@ -79,8 +79,7 @@ class BasicFragmentDialog : AppCompatDialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val builder = Builder(ContextThemeWrapper(activity, R.style.Calypso_Dialog_Alert)) - builder.setTitle(mTitle) - .setMessage(mMessage) + builder.setMessage(mMessage) .setPositiveButton(mPositiveButtonLabel) { _, _ -> dismissedByPositiveButton = true val activity = activity @@ -89,6 +88,10 @@ class BasicFragmentDialog : AppCompatDialogFragment() { } }.setCancelable(true) + mTitle?.let { + builder.setTitle(mTitle) + } + mNegativeButtonLabel?.let { builder.setNegativeButton(mNegativeButtonLabel) { _, _ -> dismissedByNegativeButton = true diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/helpers/DialogHolder.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/helpers/DialogHolder.kt index 428589b205cf..8e247a1b7d7b 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/helpers/DialogHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/helpers/DialogHolder.kt @@ -8,7 +8,7 @@ import org.wordpress.android.ui.utils.UiString class DialogHolder( private val tag: String, - private val title: UiString, + private val title: UiString?, private val message: UiString, private val positiveButton: UiString, private val negativeButton: UiString @@ -17,7 +17,7 @@ class DialogHolder( val dialog = BasicFragmentDialog() dialog.initialize( tag = tag, - title = uiHelpers.getTextOfUiString(context, title), + title = title?.let { uiHelpers.getTextOfUiString(context, title) }, message = uiHelpers.getTextOfUiString(context, message), positiveButtonLabel = uiHelpers.getTextOfUiString(context, positiveButton), negativeButtonLabel = uiHelpers.getTextOfUiString(context, negativeButton), From 4c4df67bbf6809cedf5659d842a56320575cc9bd Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 10:57:27 +0100 Subject: [PATCH 02/13] Add warning dialog on back pressed during SiteCreation --- .../sitecreation/NewSiteCreationActivity.kt | 44 ++++++++++++---- .../ui/sitecreation/NewSiteCreationMainVM.kt | 51 +++++++++++++++++-- WordPress/src/main/res/values/strings.xml | 3 ++ 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt index 6d61dd82bf89..cb0418bcdc58 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt @@ -14,30 +14,33 @@ import org.wordpress.android.WordPress import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.accounts.HelpActivity.Origin import org.wordpress.android.ui.main.SitePickerActivity +import org.wordpress.android.ui.posts.BasicFragmentDialog.BasicDialogNegativeClickInterface +import org.wordpress.android.ui.posts.BasicFragmentDialog.BasicDialogPositiveClickInterface import org.wordpress.android.ui.sitecreation.NewSiteCreationMainVM.NewSiteCreationScreenTitle.ScreenTitleEmpty import org.wordpress.android.ui.sitecreation.NewSiteCreationMainVM.NewSiteCreationScreenTitle.ScreenTitleGeneral import org.wordpress.android.ui.sitecreation.NewSiteCreationMainVM.NewSiteCreationScreenTitle.ScreenTitleStepCount -import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState -import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteCreationCompleted -import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteNotCreated -import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteNotInLocalDb import org.wordpress.android.ui.sitecreation.SiteCreationStep.DOMAINS import org.wordpress.android.ui.sitecreation.SiteCreationStep.SEGMENTS import org.wordpress.android.ui.sitecreation.SiteCreationStep.SITE_INFO import org.wordpress.android.ui.sitecreation.SiteCreationStep.SITE_PREVIEW import org.wordpress.android.ui.sitecreation.SiteCreationStep.VERTICALS -import org.wordpress.android.ui.sitecreation.previews.NewSiteCreationPreviewFragment -import org.wordpress.android.ui.sitecreation.previews.SitePreviewScreenListener import org.wordpress.android.ui.sitecreation.domains.DomainsScreenListener import org.wordpress.android.ui.sitecreation.domains.NewSiteCreationDomainsFragment import org.wordpress.android.ui.sitecreation.misc.OnHelpClickedListener import org.wordpress.android.ui.sitecreation.misc.OnSkipClickedListener +import org.wordpress.android.ui.sitecreation.previews.NewSiteCreationPreviewFragment +import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState +import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteCreationCompleted +import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteNotCreated +import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteNotInLocalDb +import org.wordpress.android.ui.sitecreation.previews.SitePreviewScreenListener import org.wordpress.android.ui.sitecreation.segments.NewSiteCreationSegmentsFragment import org.wordpress.android.ui.sitecreation.segments.SegmentsScreenListener import org.wordpress.android.ui.sitecreation.siteinfo.NewSiteCreationSiteInfoFragment import org.wordpress.android.ui.sitecreation.siteinfo.SiteInfoScreenListener import org.wordpress.android.ui.sitecreation.verticals.NewSiteCreationVerticalsFragment import org.wordpress.android.ui.sitecreation.verticals.VerticalsScreenListener +import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.wizard.WizardNavigationTarget import javax.inject.Inject @@ -48,8 +51,11 @@ class NewSiteCreationActivity : AppCompatActivity(), SiteInfoScreenListener, SitePreviewScreenListener, OnSkipClickedListener, - OnHelpClickedListener { + OnHelpClickedListener, + BasicDialogPositiveClickInterface, + BasicDialogNegativeClickInterface { @Inject internal lateinit var viewModelFactory: ViewModelProvider.Factory + @Inject internal lateinit var uiHelpers: UiHelpers private lateinit var mainViewModel: NewSiteCreationMainVM override fun onCreate(savedInstanceState: Bundle?) { @@ -89,6 +95,19 @@ class NewSiteCreationActivity : AppCompatActivity(), finish() } }) + mainViewModel.dialogActionObservable.observe(this, Observer { dialogHolder -> + dialogHolder?.let { + val supportFragmentManager = requireNotNull(supportFragmentManager) { + "FragmentManager can't be null " + + "at this point" + } + dialogHolder.show(this, supportFragmentManager, uiHelpers) + } + }) + mainViewModel.cancelFlowObservable.observe(this, Observer { + setResult(Activity.RESULT_CANCELED) + finish() + }) } override fun onSegmentSelected(segmentId: Long) { @@ -162,6 +181,14 @@ class NewSiteCreationActivity : AppCompatActivity(), fragmentTransaction.commit() } + override fun onPositiveClicked(instanceTag: String) { + mainViewModel.onPositiveDialogButtonClicked(instanceTag) + } + + override fun onNegativeClicked(instanceTag: String) { + mainViewModel.onNegativeDialogButtonClicked(instanceTag) + } + override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { onBackPressed() @@ -171,8 +198,7 @@ class NewSiteCreationActivity : AppCompatActivity(), } override fun onBackPressed() { - if (!mainViewModel.shouldSuppressBackPress()) { - mainViewModel.onBackPressed() + if (!mainViewModel.onBackPressed()) { super.onBackPressed() } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index 72f9a96fbf88..cc104d63bcb8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -14,13 +14,16 @@ import org.wordpress.android.ui.sitecreation.NewSiteCreationMainVM.NewSiteCreati import org.wordpress.android.ui.sitecreation.NewSiteCreationMainVM.NewSiteCreationScreenTitle.ScreenTitleStepCount import org.wordpress.android.ui.sitecreation.misc.NewSiteCreationTracker import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState +import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.util.wizard.WizardNavigationTarget import org.wordpress.android.util.wizard.WizardState import org.wordpress.android.viewmodel.SingleEventObservable import org.wordpress.android.viewmodel.SingleLiveEvent +import org.wordpress.android.viewmodel.helpers.DialogHolder import javax.inject.Inject +private const val TAG_WARNING_DIALOG = "back_pressed_warning_dialog" private const val KEY_CURRENT_STEP = "key_current_step" private const val KEY_SITE_CREATION_STATE = "key_site_creation_state" private val SITE_CREATION_STEPS = @@ -57,9 +60,15 @@ class NewSiteCreationMainVM @Inject constructor(private val tracker: NewSiteCrea ) } + private val _dialogAction = SingleLiveEvent() + val dialogActionObservable: LiveData = _dialogAction + private val _wizardFinishedObservable = SingleLiveEvent() val wizardFinishedObservable: LiveData = _wizardFinishedObservable + private val _cancelFlowObservable = SingleLiveEvent() + val cancelFlowObservable: LiveData = _cancelFlowObservable + fun start(savedInstanceState: Bundle?) { if (isStarted) return if (savedInstanceState == null) { @@ -88,10 +97,25 @@ class NewSiteCreationMainVM @Inject constructor(private val tracker: NewSiteCrea wizardManager.showNextStep() } - fun shouldSuppressBackPress(): Boolean = wizardManager.isLastStep() - - fun onBackPressed() { - wizardManager.onBackPressed() + private fun shouldSuppressBackPress(): Boolean = wizardManager.isLastStep() + + /** + * Returns true if the back pressed event was handled, false otherwise. + */ + fun onBackPressed(): Boolean { + return if (shouldSuppressBackPress()) { + _dialogAction.value = DialogHolder( + tag = TAG_WARNING_DIALOG, + title = null, + message = UiStringRes(R.string.new_site_creation_preview_back_pressed_warning), + positiveButton = UiStringRes(R.string.exit), + negativeButton = UiStringRes(R.string.cancel) + ) + true + } else { + wizardManager.onBackPressed() + false + } } fun onVerticalsScreenFinished(verticalId: String) { @@ -134,6 +158,25 @@ class NewSiteCreationMainVM @Inject constructor(private val tracker: NewSiteCrea _wizardFinishedObservable.value = createSiteState } + fun onPositiveDialogButtonClicked(instanceTag: String) { + when (instanceTag) { + TAG_WARNING_DIALOG -> cancelFlow() + else -> NotImplementedError("Unknown dialog tag: $instanceTag") + } + } + + fun onNegativeDialogButtonClicked(instanceTag: String) { + when (instanceTag) { + TAG_WARNING_DIALOG -> Unit // TODO log event + else -> NotImplementedError("Unknown dialog tag: $instanceTag") + } + } + + private fun cancelFlow() { + // TODO log event + _cancelFlowObservable.call() + } + sealed class NewSiteCreationScreenTitle { data class ScreenTitleStepCount(@StringRes val resId: Int, val stepsCount: Int, val stepPosition: Int) : NewSiteCreationScreenTitle() diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 16d2638b81c0..be9b4690fd65 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -109,6 +109,8 @@ Preview %d Write Post dismiss + exit + warning Not now @@ -2485,4 +2487,5 @@ It seems like you\'re on a slow connection. If you don\'t see your new site in the list, try refreshing. Clear Showing site preview + Exiting may result in losing your progress. Are you sure you want to continue? From 3e7043fa2ebf10086b2cfee010d6e685c0657332 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 11:14:06 +0100 Subject: [PATCH 03/13] Track an event when the user exits the site creation flow --- .../ui/sitecreation/NewSiteCreationMainVM.kt | 16 +++++++++------- .../sitecreation/misc/NewSiteCreationTracker.kt | 4 ++++ .../android/analytics/AnalyticsTracker.java | 1 + .../analytics/AnalyticsTrackerNosara.java | 2 ++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index cc104d63bcb8..ed6245904b96 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -66,8 +66,8 @@ class NewSiteCreationMainVM @Inject constructor(private val tracker: NewSiteCrea private val _wizardFinishedObservable = SingleLiveEvent() val wizardFinishedObservable: LiveData = _wizardFinishedObservable - private val _cancelFlowObservable = SingleLiveEvent() - val cancelFlowObservable: LiveData = _cancelFlowObservable + private val _exitFlowObservable = SingleLiveEvent() + val cancelFlowObservable: LiveData = _exitFlowObservable fun start(savedInstanceState: Bundle?) { if (isStarted) return @@ -160,21 +160,23 @@ class NewSiteCreationMainVM @Inject constructor(private val tracker: NewSiteCrea fun onPositiveDialogButtonClicked(instanceTag: String) { when (instanceTag) { - TAG_WARNING_DIALOG -> cancelFlow() + TAG_WARNING_DIALOG -> exitFlow() else -> NotImplementedError("Unknown dialog tag: $instanceTag") } } fun onNegativeDialogButtonClicked(instanceTag: String) { when (instanceTag) { - TAG_WARNING_DIALOG -> Unit // TODO log event + TAG_WARNING_DIALOG -> { + // do nothing + } else -> NotImplementedError("Unknown dialog tag: $instanceTag") } } - private fun cancelFlow() { - // TODO log event - _cancelFlowObservable.call() + private fun exitFlow() { + tracker.trackFlowExited() + _exitFlowObservable.call() } sealed class NewSiteCreationScreenTitle { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/misc/NewSiteCreationTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/misc/NewSiteCreationTracker.kt index cdfd8927ea8f..51a393def8f3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/misc/NewSiteCreationTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/misc/NewSiteCreationTracker.kt @@ -97,6 +97,10 @@ class NewSiteCreationTracker @Inject constructor(val tracker: AnalyticsTrackerWr tracker.track(AnalyticsTracker.Stat.ENHANCED_SITE_CREATION_COMPLETED) } + fun trackFlowExited() { + tracker.track(AnalyticsTracker.Stat.ENHANCED_SITE_CREATION_EXITED) + } + fun trackErrorShown(errorContext: String, errorType: NewSiteCreationErrorType, errorDescription: String? = null) { trackErrorShown(errorContext, errorType.toString().toLowerCase(), errorDescription) } diff --git a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 3f346b447211..081ffc514b02 100644 --- a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -382,6 +382,7 @@ public enum Stat { ENHANCED_SITE_CREATION_SUCCESS_PREVIEW_VIEWED, ENHANCED_SITE_CREATION_SUCCESS_PREVIEW_LOADED, ENHANCED_SITE_CREATION_COMPLETED, + ENHANCED_SITE_CREATION_EXITED, ENHANCED_SITE_CREATION_ERROR_SHOWN, ENHANCED_SITE_CREATION_BACKGROUND_SERVICE_UPDATED, MEDIA_LIBRARY_ADDED_PHOTO, diff --git a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index f6648fdee5b4..910875648741 100644 --- a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -1125,6 +1125,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "enhanced_site_creation_success_preview_loaded"; case ENHANCED_SITE_CREATION_COMPLETED: return "enhanced_site_creation_completed"; + case ENHANCED_SITE_CREATION_EXITED: + return "enhanced_site_creation_exited"; case ENHANCED_SITE_CREATION_ERROR_SHOWN: return "enhanced_site_creation_error_shown"; case PERSON_REMOVED: From 02b571ca93c687e1c809b967a2d11db9a383e6ae Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 12:07:28 +0100 Subject: [PATCH 04/13] Add tests for warning dialog in NewSiteCreationMainVM --- .../sitecreation/NewSiteCreationActivity.kt | 2 +- .../ui/sitecreation/NewSiteCreationMainVM.kt | 6 ++--- .../sitecreation/NewSiteCreationMainVMTest.kt | 24 ++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt index cb0418bcdc58..496de29e1945 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt @@ -104,7 +104,7 @@ class NewSiteCreationActivity : AppCompatActivity(), dialogHolder.show(this, supportFragmentManager, uiHelpers) } }) - mainViewModel.cancelFlowObservable.observe(this, Observer { + mainViewModel.exitFlowObservable.observe(this, Observer { setResult(Activity.RESULT_CANCELED) finish() }) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index af7646a7c094..9538890772ce 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -23,7 +23,7 @@ import org.wordpress.android.viewmodel.SingleLiveEvent import org.wordpress.android.viewmodel.helpers.DialogHolder import javax.inject.Inject -private const val TAG_WARNING_DIALOG = "back_pressed_warning_dialog" +const val TAG_WARNING_DIALOG = "back_pressed_warning_dialog" const val KEY_CURRENT_STEP = "key_current_step" const val KEY_SITE_CREATION_STATE = "key_site_creation_state" @@ -62,7 +62,7 @@ class NewSiteCreationMainVM @Inject constructor( val wizardFinishedObservable: LiveData = _wizardFinishedObservable private val _exitFlowObservable = SingleLiveEvent() - val cancelFlowObservable: LiveData = _exitFlowObservable + val exitFlowObservable: LiveData = _exitFlowObservable fun start(savedInstanceState: Bundle?) { if (isStarted) return @@ -94,7 +94,7 @@ class NewSiteCreationMainVM @Inject constructor( private fun shouldSuppressBackPress(): Boolean = wizardManager.isLastStep() /** - * Returns true if the back pressed event was handled, false otherwise. + * Returns true if the back pressed event was handled and the activity should suppress it, false otherwise. */ fun onBackPressed(): Boolean { return if (shouldSuppressBackPress()) { diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt index aaf9401547b0..4d3a6fab23a5 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt @@ -24,6 +24,7 @@ import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.Cr import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.CreateSiteState.SiteCreationCompleted import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.viewmodel.SingleLiveEvent +import org.wordpress.android.viewmodel.helpers.DialogHolder private const val LOCAL_SITE_ID = 1 private const val SEGMENT_ID = 1L @@ -43,6 +44,8 @@ class NewSiteCreationMainVMTest { @Mock lateinit var tracker: NewSiteCreationTracker @Mock lateinit var navigationTargetObserver: Observer @Mock lateinit var wizardFinishedObserver: Observer + @Mock lateinit var wizardExitedObserver: Observer + @Mock lateinit var dialogActionsObserver: Observer @Mock lateinit var savedInstanceState: Bundle @Mock lateinit var wizardManager: WizardManager @Mock lateinit var siteCreationStep: SiteCreationStep @@ -61,6 +64,8 @@ class NewSiteCreationMainVMTest { viewModel.start(null) viewModel.navigationTargetObservable.observeForever(navigationTargetObserver) viewModel.wizardFinishedObservable.observeForever(wizardFinishedObserver) + viewModel.dialogActionObservable.observeForever(dialogActionsObserver) + viewModel.exitFlowObservable.observeForever(wizardExitedObserver) whenever(wizardManager.stepsCount).thenReturn(STEP_COUNT) // clear invocations since viewModel.start() calls wizardManager.showNextStep clearInvocations(wizardManager) @@ -144,13 +149,26 @@ class NewSiteCreationMainVMTest { @Test fun backNotSuppressedWhenNotLastStep() { whenever(wizardManager.isLastStep()).thenReturn(false) - assertThat(viewModel.shouldSuppressBackPress()).isFalse() + assertThat(viewModel.onBackPressed()).isFalse() } @Test - fun backSuppressedForLastStep() { + fun backSuppressedWhenLastStep() { whenever(wizardManager.isLastStep()).thenReturn(true) - assertThat(viewModel.shouldSuppressBackPress()).isTrue() + assertThat(viewModel.onBackPressed()).isTrue() + } + + @Test + fun dialogShownOnBackPressedForLastStep() { + whenever(wizardManager.isLastStep()).thenReturn(true) + viewModel.onBackPressed() + verify(dialogActionsObserver).onChanged(any()) + } + + @Test + fun flowExitedOnDialogPositiveButtonClicked() { + viewModel.onPositiveDialogButtonClicked(TAG_WARNING_DIALOG) + verify(wizardExitedObserver).onChanged(any()) } @Test From b12731dcabd156bc64dd4fe70c2831579d64c96a Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 14:37:55 +0100 Subject: [PATCH 05/13] Fix back button behavior on Site Preview screen --- .../sitecreation/NewSiteCreationActivity.kt | 4 ++ .../ui/sitecreation/NewSiteCreationMainVM.kt | 37 +++++++++++-------- .../NewSiteCreationPreviewFragment.kt | 3 ++ .../previews/NewSitePreviewViewModel.kt | 5 +++ .../previews/SitePreviewScreenListener.kt | 1 + .../sitecreation/NewSiteCreationMainVMTest.kt | 13 ++++++- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt index 496de29e1945..0dafb75d546d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt @@ -122,6 +122,10 @@ class NewSiteCreationActivity : AppCompatActivity(), mainViewModel.onDomainsScreenFinished(domain) } + override fun onPreviewLayoutShown() { + mainViewModel.onPreviewLayoutShown() + } + override fun onSitePreviewScreenDismissed(createSiteState: CreateSiteState) { mainViewModel.onSitePreviewScreenFinished(createSiteState) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index 9538890772ce..57c28c9605a0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -44,6 +44,7 @@ class NewSiteCreationMainVM @Inject constructor( private val wizardManager: WizardManager ) : ViewModel() { private var isStarted = false + private var isSitePreviewLayoutShown = false private lateinit var siteCreationState: SiteCreationState @@ -91,20 +92,22 @@ class NewSiteCreationMainVM @Inject constructor( wizardManager.showNextStep() } - private fun shouldSuppressBackPress(): Boolean = wizardManager.isLastStep() - /** * Returns true if the back pressed event was handled and the activity should suppress it, false otherwise. */ fun onBackPressed(): Boolean { - return if (shouldSuppressBackPress()) { - _dialogAction.value = DialogHolder( - tag = TAG_WARNING_DIALOG, - title = null, - message = UiStringRes(R.string.new_site_creation_preview_back_pressed_warning), - positiveButton = UiStringRes(R.string.exit), - negativeButton = UiStringRes(R.string.cancel) - ) + return if (wizardManager.isLastStep()) { + if(isSitePreviewLayoutShown){ + _exitFlowObservable.call() + } else { + _dialogAction.value = DialogHolder( + tag = TAG_WARNING_DIALOG, + title = null, + message = UiStringRes(R.string.new_site_creation_preview_back_pressed_warning), + positiveButton = UiStringRes(R.string.exit), + negativeButton = UiStringRes(R.string.cancel) + ) + } true } else { wizardManager.onBackPressed() @@ -148,13 +151,20 @@ class NewSiteCreationMainVM @Inject constructor( } } + fun onPreviewLayoutShown() { + isSitePreviewLayoutShown = true + } + fun onSitePreviewScreenFinished(createSiteState: CreateSiteState) { _wizardFinishedObservable.value = createSiteState } fun onPositiveDialogButtonClicked(instanceTag: String) { when (instanceTag) { - TAG_WARNING_DIALOG -> exitFlow() + TAG_WARNING_DIALOG -> { + tracker.trackFlowExited() + _exitFlowObservable.call() + } else -> NotImplementedError("Unknown dialog tag: $instanceTag") } } @@ -168,11 +178,6 @@ class NewSiteCreationMainVM @Inject constructor( } } - private fun exitFlow() { - tracker.trackFlowExited() - _exitFlowObservable.call() - } - sealed class NewSiteCreationScreenTitle { data class ScreenTitleStepCount(@StringRes val resId: Int, val stepsCount: Int, val stepPosition: Int) : NewSiteCreationScreenTitle() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt index 8c425cc74f89..015f83e31c88 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt @@ -149,6 +149,9 @@ class NewSiteCreationPreviewFragment : NewSiteCreationBaseFormFragment(), viewModel.onHelpClicked.observe(this, Observer { helpClickedListener.onHelpClicked(HelpActivity.Origin.SITE_CREATION_CREATING) }) + viewModel.onPreviewShown.observe(this, Observer { + sitePreviewScreenListener.onPreviewLayoutShown() + }) viewModel.onOkButtonClicked.observe(this, Observer { createSiteState -> createSiteState?.let { sitePreviewScreenListener.onSitePreviewScreenDismissed(createSiteState) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt index 8dfbf01f363b..0d04d86b3f3d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt @@ -86,6 +86,9 @@ class NewSitePreviewViewModel @Inject constructor( private val _onOkButtonClicked = SingleLiveEvent() val onOkButtonClicked: LiveData = _onOkButtonClicked + private val _onPreviewShown = SingleLiveEvent() + val onPreviewShown: LiveData = _onPreviewShown + init { dispatcher.register(fetchWpComSiteUseCase) } @@ -219,6 +222,7 @@ class NewSitePreviewViewModel @Inject constructor( */ withContext(mainDispatcher) { if (uiState.value !is SitePreviewContentUiState) { + _onPreviewShown.call() tracker.trackPreviewWebviewShown() updateUiState(SitePreviewLoadingShimmerState(createSitePreviewData())) } @@ -242,6 +246,7 @@ class NewSitePreviewViewModel @Inject constructor( * In other words don't update it after a configuration change. */ if (uiState.value !is SitePreviewContentUiState) { + _onPreviewShown.call() updateUiState(SitePreviewContentUiState(createSitePreviewData())) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt index 9a91791e66ef..3f601b80aabf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt @@ -4,4 +4,5 @@ import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.Cr interface SitePreviewScreenListener { fun onSitePreviewScreenDismissed(createSiteState: CreateSiteState) + fun onPreviewLayoutShown() } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt index 4d3a6fab23a5..c06fc76e5ecc 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt @@ -4,6 +4,7 @@ import android.arch.core.executor.testing.InstantTaskExecutorRule import android.arch.lifecycle.Observer import android.os.Bundle import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.argThat import com.nhaarman.mockitokotlin2.clearInvocations import com.nhaarman.mockitokotlin2.verify @@ -159,16 +160,24 @@ class NewSiteCreationMainVMTest { } @Test - fun dialogShownOnBackPressedForLastStep() { + fun dialogShownOnBackPressedWhenLastStepAndPreviewNotShown() { whenever(wizardManager.isLastStep()).thenReturn(true) viewModel.onBackPressed() verify(dialogActionsObserver).onChanged(any()) } + @Test + fun flowExitedOnBackPressedWhenLastStepAndPreviewAlreadyShown() { + whenever(wizardManager.isLastStep()).thenReturn(true) + viewModel.onPreviewLayoutShown() + viewModel.onBackPressed() + verify(wizardExitedObserver).onChanged(anyOrNull()) + } + @Test fun flowExitedOnDialogPositiveButtonClicked() { viewModel.onPositiveDialogButtonClicked(TAG_WARNING_DIALOG) - verify(wizardExitedObserver).onChanged(any()) + verify(wizardExitedObserver).onChanged(anyOrNull()) } @Test From 2d8ed6c7d764c1094353b3b6b7efaadc2179fd9f Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 14:57:01 +0100 Subject: [PATCH 06/13] Fix lint issues in NewSiteCreationMainVM --- .../wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index 57c28c9605a0..e60f3ed057cf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -97,7 +97,7 @@ class NewSiteCreationMainVM @Inject constructor( */ fun onBackPressed(): Boolean { return if (wizardManager.isLastStep()) { - if(isSitePreviewLayoutShown){ + if (isSitePreviewLayoutShown) { _exitFlowObservable.call() } else { _dialogAction.value = DialogHolder( From dccb5ed00993f02a0db11c1b9f332b58347d1c68 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 15:38:05 +0100 Subject: [PATCH 07/13] Remove unused string resource --- WordPress/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index be9b4690fd65..33ba7b0e2be4 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -110,7 +110,6 @@ Write Post dismiss exit - warning Not now From 8768ccec8f0e6439eebec460cf1b538d6ac15337 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Wed, 6 Feb 2019 16:22:35 +0100 Subject: [PATCH 08/13] Update warning dialog text in NewSiteCreationFlow --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 33ba7b0e2be4..e08914ab6771 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -2486,5 +2486,5 @@ It seems like you\'re on a slow connection. If you don\'t see your new site in the list, try refreshing. Clear Showing site preview - Exiting may result in losing your progress. Are you sure you want to continue? + You may lose your progress. Are you sure you want to exit? From 0fe922d705373909459d6c0bfe4a722dda21c95d Mon Sep 17 00:00:00 2001 From: malinajirka Date: Tue, 12 Feb 2019 05:22:59 +0100 Subject: [PATCH 09/13] Remove default param in BasicFragmentDialog --- .../java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt index 5d3bbfe13246..3ad7805108cf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicFragmentDialog.kt @@ -37,7 +37,7 @@ class BasicFragmentDialog : AppCompatDialogFragment() { fun initialize( tag: String, - title: String? = null, + title: String?, message: String, positiveButtonLabel: String, negativeButtonLabel: String? = null, From d9877432b1f3788866aba3815b04f0bb1cf33f9f Mon Sep 17 00:00:00 2001 From: malinajirka Date: Tue, 12 Feb 2019 09:49:26 +0100 Subject: [PATCH 10/13] Update onBackPressed method in NewSiteCreationMainVM --- .../ui/sitecreation/NewSiteCreationActivity.kt | 10 +++++----- .../android/ui/sitecreation/NewSiteCreationMainVM.kt | 11 +++++------ .../ui/sitecreation/NewSiteCreationMainVMTest.kt | 9 +++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt index 0dafb75d546d..03da0130f5ed 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt @@ -98,8 +98,7 @@ class NewSiteCreationActivity : AppCompatActivity(), mainViewModel.dialogActionObservable.observe(this, Observer { dialogHolder -> dialogHolder?.let { val supportFragmentManager = requireNotNull(supportFragmentManager) { - "FragmentManager can't be null " + - "at this point" + "FragmentManager can't be null at this point" } dialogHolder.show(this, supportFragmentManager, uiHelpers) } @@ -108,6 +107,9 @@ class NewSiteCreationActivity : AppCompatActivity(), setResult(Activity.RESULT_CANCELED) finish() }) + mainViewModel.onBackPressedObservable.observe(this, Observer { + super.onBackPressed() + }) } override fun onSegmentSelected(segmentId: Long) { @@ -202,8 +204,6 @@ class NewSiteCreationActivity : AppCompatActivity(), } override fun onBackPressed() { - if (!mainViewModel.onBackPressed()) { - super.onBackPressed() - } + mainViewModel.onBackPressed() } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index e60f3ed057cf..dcfa0b288ad7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -65,6 +65,9 @@ class NewSiteCreationMainVM @Inject constructor( private val _exitFlowObservable = SingleLiveEvent() val exitFlowObservable: LiveData = _exitFlowObservable + private val _onBackPressedObservable = SingleLiveEvent() + val onBackPressedObservable: LiveData = _onBackPressedObservable + fun start(savedInstanceState: Bundle?) { if (isStarted) return if (savedInstanceState == null) { @@ -92,10 +95,7 @@ class NewSiteCreationMainVM @Inject constructor( wizardManager.showNextStep() } - /** - * Returns true if the back pressed event was handled and the activity should suppress it, false otherwise. - */ - fun onBackPressed(): Boolean { + fun onBackPressed() { return if (wizardManager.isLastStep()) { if (isSitePreviewLayoutShown) { _exitFlowObservable.call() @@ -108,10 +108,9 @@ class NewSiteCreationMainVM @Inject constructor( negativeButton = UiStringRes(R.string.cancel) ) } - true } else { wizardManager.onBackPressed() - false + _onBackPressedObservable.call() } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt index c06fc76e5ecc..f7b41ae91c14 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt @@ -8,6 +8,7 @@ import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.argThat import com.nhaarman.mockitokotlin2.clearInvocations import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever import org.assertj.core.api.Assertions.assertThat import org.junit.Before @@ -47,6 +48,7 @@ class NewSiteCreationMainVMTest { @Mock lateinit var wizardFinishedObserver: Observer @Mock lateinit var wizardExitedObserver: Observer @Mock lateinit var dialogActionsObserver: Observer + @Mock lateinit var onBackPressedObserver: Observer @Mock lateinit var savedInstanceState: Bundle @Mock lateinit var wizardManager: WizardManager @Mock lateinit var siteCreationStep: SiteCreationStep @@ -67,6 +69,7 @@ class NewSiteCreationMainVMTest { viewModel.wizardFinishedObservable.observeForever(wizardFinishedObserver) viewModel.dialogActionObservable.observeForever(dialogActionsObserver) viewModel.exitFlowObservable.observeForever(wizardExitedObserver) + viewModel.onBackPressedObservable.observeForever(onBackPressedObserver) whenever(wizardManager.stepsCount).thenReturn(STEP_COUNT) // clear invocations since viewModel.start() calls wizardManager.showNextStep clearInvocations(wizardManager) @@ -150,13 +153,15 @@ class NewSiteCreationMainVMTest { @Test fun backNotSuppressedWhenNotLastStep() { whenever(wizardManager.isLastStep()).thenReturn(false) - assertThat(viewModel.onBackPressed()).isFalse() + viewModel.onBackPressed() + verify(onBackPressedObserver).onChanged(anyOrNull()) } @Test fun backSuppressedWhenLastStep() { whenever(wizardManager.isLastStep()).thenReturn(true) - assertThat(viewModel.onBackPressed()).isTrue() + viewModel.onBackPressed() + verifyNoMoreInteractions(onBackPressedObserver) } @Test From 7f3ab2aecf60d31fa8c210d63ff34a867c201398 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Tue, 12 Feb 2019 09:56:22 +0100 Subject: [PATCH 11/13] Refactor exitflow in NewSiteCreationMainVM --- .../ui/sitecreation/NewSiteCreationMainVM.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index dcfa0b288ad7..747856fc0e5e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -98,7 +98,7 @@ class NewSiteCreationMainVM @Inject constructor( fun onBackPressed() { return if (wizardManager.isLastStep()) { if (isSitePreviewLayoutShown) { - _exitFlowObservable.call() + exitFlow(false) } else { _dialogAction.value = DialogHolder( tag = TAG_WARNING_DIALOG, @@ -154,6 +154,16 @@ class NewSiteCreationMainVM @Inject constructor( isSitePreviewLayoutShown = true } + /** + * Exits the flow and tracks an event when the user force-exits the "site creation in progress" before it completes. + */ + private fun exitFlow(forceExit: Boolean) { + if (forceExit) { + tracker.trackFlowExited() + } + _exitFlowObservable.call() + } + fun onSitePreviewScreenFinished(createSiteState: CreateSiteState) { _wizardFinishedObservable.value = createSiteState } @@ -161,8 +171,7 @@ class NewSiteCreationMainVM @Inject constructor( fun onPositiveDialogButtonClicked(instanceTag: String) { when (instanceTag) { TAG_WARNING_DIALOG -> { - tracker.trackFlowExited() - _exitFlowObservable.call() + exitFlow(true) } else -> NotImplementedError("Unknown dialog tag: $instanceTag") } From 97b0d1a55fa81eb310569baa46163ae33e0b44c3 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Tue, 12 Feb 2019 10:10:14 +0100 Subject: [PATCH 12/13] Replace sitePreviewShown with siteCreationCompleted --- .../android/ui/sitecreation/NewSiteCreationActivity.kt | 4 ++-- .../android/ui/sitecreation/NewSiteCreationMainVM.kt | 8 ++++---- .../previews/NewSiteCreationPreviewFragment.kt | 4 ++-- .../ui/sitecreation/previews/NewSitePreviewViewModel.kt | 7 +++---- .../ui/sitecreation/previews/SitePreviewScreenListener.kt | 2 +- .../android/ui/sitecreation/NewSiteCreationMainVMTest.kt | 6 +++--- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt index 03da0130f5ed..5061af50f959 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationActivity.kt @@ -124,8 +124,8 @@ class NewSiteCreationActivity : AppCompatActivity(), mainViewModel.onDomainsScreenFinished(domain) } - override fun onPreviewLayoutShown() { - mainViewModel.onPreviewLayoutShown() + override fun onSiteCreationCompleted() { + mainViewModel.onSiteCreationCompleted() } override fun onSitePreviewScreenDismissed(createSiteState: CreateSiteState) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt index 747856fc0e5e..ecb27fc85698 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVM.kt @@ -44,7 +44,7 @@ class NewSiteCreationMainVM @Inject constructor( private val wizardManager: WizardManager ) : ViewModel() { private var isStarted = false - private var isSitePreviewLayoutShown = false + private var siteCreationCompleted = false private lateinit var siteCreationState: SiteCreationState @@ -97,7 +97,7 @@ class NewSiteCreationMainVM @Inject constructor( fun onBackPressed() { return if (wizardManager.isLastStep()) { - if (isSitePreviewLayoutShown) { + if (siteCreationCompleted) { exitFlow(false) } else { _dialogAction.value = DialogHolder( @@ -150,8 +150,8 @@ class NewSiteCreationMainVM @Inject constructor( } } - fun onPreviewLayoutShown() { - isSitePreviewLayoutShown = true + fun onSiteCreationCompleted() { + siteCreationCompleted = true } /** diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt index 015f83e31c88..7d51ba7005af 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSiteCreationPreviewFragment.kt @@ -149,8 +149,8 @@ class NewSiteCreationPreviewFragment : NewSiteCreationBaseFormFragment(), viewModel.onHelpClicked.observe(this, Observer { helpClickedListener.onHelpClicked(HelpActivity.Origin.SITE_CREATION_CREATING) }) - viewModel.onPreviewShown.observe(this, Observer { - sitePreviewScreenListener.onPreviewLayoutShown() + viewModel.onSiteCreationCompleted.observe(this, Observer { + sitePreviewScreenListener.onSiteCreationCompleted() }) viewModel.onOkButtonClicked.observe(this, Observer { createSiteState -> createSiteState?.let { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt index 0d04d86b3f3d..dc37f9e8bc0b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt @@ -86,8 +86,8 @@ class NewSitePreviewViewModel @Inject constructor( private val _onOkButtonClicked = SingleLiveEvent() val onOkButtonClicked: LiveData = _onOkButtonClicked - private val _onPreviewShown = SingleLiveEvent() - val onPreviewShown: LiveData = _onPreviewShown + private val _onSiteCreationCompleted = SingleLiveEvent() + val onSiteCreationCompleted: LiveData = _onSiteCreationCompleted init { dispatcher.register(fetchWpComSiteUseCase) @@ -178,6 +178,7 @@ class NewSitePreviewViewModel @Inject constructor( val remoteSiteId = event.payload as Long createSiteState = SiteNotInLocalDb(remoteSiteId) fetchNewlyCreatedSiteModel(remoteSiteId) + _onSiteCreationCompleted.call() } FAILURE -> { serviceStateForRetry = event.payload as NewSiteCreationServiceState @@ -222,7 +223,6 @@ class NewSitePreviewViewModel @Inject constructor( */ withContext(mainDispatcher) { if (uiState.value !is SitePreviewContentUiState) { - _onPreviewShown.call() tracker.trackPreviewWebviewShown() updateUiState(SitePreviewLoadingShimmerState(createSitePreviewData())) } @@ -246,7 +246,6 @@ class NewSitePreviewViewModel @Inject constructor( * In other words don't update it after a configuration change. */ if (uiState.value !is SitePreviewContentUiState) { - _onPreviewShown.call() updateUiState(SitePreviewContentUiState(createSitePreviewData())) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt index 3f601b80aabf..dae0139cef2b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewScreenListener.kt @@ -4,5 +4,5 @@ import org.wordpress.android.ui.sitecreation.previews.NewSitePreviewViewModel.Cr interface SitePreviewScreenListener { fun onSitePreviewScreenDismissed(createSiteState: CreateSiteState) - fun onPreviewLayoutShown() + fun onSiteCreationCompleted() } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt index f7b41ae91c14..8afb04830623 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/NewSiteCreationMainVMTest.kt @@ -165,16 +165,16 @@ class NewSiteCreationMainVMTest { } @Test - fun dialogShownOnBackPressedWhenLastStepAndPreviewNotShown() { + fun dialogShownOnBackPressedWhenLastStepAndSiteCreationNotCompleted() { whenever(wizardManager.isLastStep()).thenReturn(true) viewModel.onBackPressed() verify(dialogActionsObserver).onChanged(any()) } @Test - fun flowExitedOnBackPressedWhenLastStepAndPreviewAlreadyShown() { + fun flowExitedOnBackPressedWhenLastStepAndSiteCreationCompleted() { whenever(wizardManager.isLastStep()).thenReturn(true) - viewModel.onPreviewLayoutShown() + viewModel.onSiteCreationCompleted() viewModel.onBackPressed() verify(wizardExitedObserver).onChanged(anyOrNull()) } From b2baf64707ca63f7634e56c5ef4e2c8edd6f88e4 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Tue, 12 Feb 2019 10:24:56 +0100 Subject: [PATCH 13/13] Fix onSiteCreationCompleted call --- .../android/ui/sitecreation/previews/NewSitePreviewViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt index dc37f9e8bc0b..8e3b213079e7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/NewSitePreviewViewModel.kt @@ -178,7 +178,7 @@ class NewSitePreviewViewModel @Inject constructor( val remoteSiteId = event.payload as Long createSiteState = SiteNotInLocalDb(remoteSiteId) fetchNewlyCreatedSiteModel(remoteSiteId) - _onSiteCreationCompleted.call() + _onSiteCreationCompleted.asyncCall() } FAILURE -> { serviceStateForRetry = event.payload as NewSiteCreationServiceState