Skip to content

Commit

Permalink
Add support for showing Post with Audio option on the dashboard FAB. …
Browse files Browse the repository at this point in the history
…Update unit test
  • Loading branch information
zwarm committed May 23, 2024
1 parent 1250a9f commit bdbc179
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ sealed class MainActionListItem {
CREATE_NEW_PAGE,
CREATE_NEW_PAGE_FROM_PAGES_CARD,
CREATE_NEW_POST,
ANSWER_BLOGGING_PROMPT
ANSWER_BLOGGING_PROMPT,
CREATE_NEW_POST_FROM_AUDIO_AI
}

data class CreateAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
import org.wordpress.android.ui.uploads.UploadUtilsWrapper;
import org.wordpress.android.ui.utils.JetpackAppMigrationFlowUtils;
import org.wordpress.android.ui.utils.UiString.UiStringRes;
import org.wordpress.android.ui.voicetocontent.VoiceToContentDialogFragment;
import org.wordpress.android.ui.whatsnew.FeatureAnnouncementDialogFragment;
import org.wordpress.android.util.AniUtils;
import org.wordpress.android.util.AppLog;
Expand Down Expand Up @@ -719,6 +720,9 @@ private void initViewModel() {

mViewModel.getCreateAction().observe(this, createAction -> {
switch (createAction) {
case CREATE_NEW_POST_FROM_AUDIO_AI:
launchVoiceToContent();
break;
case CREATE_NEW_POST:
handleNewPostAction(PagePostCreationSourcesDetail.POST_FROM_MY_SITE, -1, null);
break;
Expand Down Expand Up @@ -1325,6 +1329,15 @@ private void handleNewPostAction(PagePostCreationSourcesDetail source,
ActivityLauncher.addNewPostForResult(this, getSelectedSite(), false, source, promptId, entryPoint);
}

private void launchVoiceToContent() {
if (!mSiteStore.hasSite()) {
// No site yet - Move to My Sites fragment that shows the create new site screen
mBottomNav.setCurrentSelectedPage(PageType.MY_SITE);
return;
}
VoiceToContentDialogFragment.newInstance().show(getSupportFragmentManager(), VoiceToContentDialogFragment.TAG);
}

private void trackLastVisiblePage(@NonNull final PageType pageType) {
switch (pageType) {
case MY_SITE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.ui.prefs.privacy.banner.domain.ShouldAskPrivacyConsent
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.ui.voicetocontent.VoiceToContentFeatureUtils
import org.wordpress.android.ui.whatsnew.FeatureAnnouncementProvider
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.FluxCUtils
Expand Down Expand Up @@ -68,6 +69,7 @@ class WPMainActivityViewModel @Inject constructor(
private val bloggingPromptsStore: BloggingPromptsStore,
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher,
private val shouldAskPrivacyConsent: ShouldAskPrivacyConsent,
private val voiceToContentFeatureUtils: VoiceToContentFeatureUtils
) : ScopedViewModel(mainDispatcher) {
private var isStarted = false

Expand Down Expand Up @@ -203,6 +205,16 @@ class WPMainActivityViewModel @Inject constructor(
onClickAction = ::onCreateActionClicked
)
)
if (voiceToContentFeatureUtils.isVoiceToContentEnabled() && hasFullAccessToContent(site)) {
actionsList.add(
CreateAction(
actionType = ActionType.CREATE_NEW_POST_FROM_AUDIO_AI,
iconRes = R.drawable.ic_mic_white_24dp,
labelRes = R.string.my_site_bottom_sheet_add_post_from_audio,
onClickAction = ::onCreateActionClicked
)
)
}
if (hasFullAccessToContent(site)) {
actionsList.add(
CreateAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.ui.prefs.privacy.banner.domain.ShouldAskPrivacyConsent
import org.wordpress.android.ui.quickstart.QuickStartType
import org.wordpress.android.ui.voicetocontent.VoiceToContentFeatureUtils
import org.wordpress.android.ui.whatsnew.FeatureAnnouncement
import org.wordpress.android.ui.whatsnew.FeatureAnnouncementItem
import org.wordpress.android.ui.whatsnew.FeatureAnnouncementProvider
Expand Down Expand Up @@ -109,6 +110,9 @@ class WPMainActivityViewModelTest : BaseUnitTest() {
@Mock
private lateinit var shouldAskPrivacyConsent: ShouldAskPrivacyConsent

@Mock
private lateinit var voiceToContentFeatureUtils: VoiceToContentFeatureUtils

private val featureAnnouncement = FeatureAnnouncement(
"14.7",
2,
Expand Down Expand Up @@ -156,6 +160,7 @@ class WPMainActivityViewModelTest : BaseUnitTest() {
whenever(bloggingPromptsSettingsHelper.shouldShowPromptsFeature()).thenReturn(false)
whenever(bloggingPromptsStore.getPromptForDate(any(), any())).thenReturn(flowOf(bloggingPrompt))
whenever(shouldAskPrivacyConsent()).thenReturn(false)
whenever(voiceToContentFeatureUtils.isVoiceToContentEnabled()).thenReturn(false)
viewModel = WPMainActivityViewModel(
featureAnnouncementProvider,
buildConfigWrapper,
Expand All @@ -169,6 +174,7 @@ class WPMainActivityViewModelTest : BaseUnitTest() {
bloggingPromptsStore,
NoDelayCoroutineDispatcher(),
shouldAskPrivacyConsent,
voiceToContentFeatureUtils
)
viewModel.onFeatureAnnouncementRequested.observeForever(
onFeatureAnnouncementRequestedObserver
Expand Down

0 comments on commit bdbc179

Please sign in to comment.