From ad478ab72d2bca60fc225d5ea30a1975ab93b735 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 9 Feb 2024 07:55:19 -0500 Subject: [PATCH 1/6] Add string resource for super fast media deep link messaging --- WordPress/src/main/res/values/strings.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index d28bdcc5957d..62e87667048c 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4878,4 +4878,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> PHP Logs Web Server Logs We cannot open site monitoring at the moment. Please try again later + + + Site not found. Check that you are logged into the correct account. From 319ee2d1a5f5ee24d3cf58fd9b378de5899f8907 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 9 Feb 2024 07:55:52 -0500 Subject: [PATCH 2/6] Add new navigation action to support opening My Site with a message --- .../org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt index 470f6f149669..cee3bc824c2d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt @@ -97,6 +97,10 @@ class DeepLinkNavigator navigateAction.site, navigateAction.siteMonitorType ) + is NavigateAction.OpenMySiteWithMessage -> activityNavigator.openMySiteWithMessageInNewStack( + activity, + navigateAction.message + ) } if (navigateAction != LoginForResult) { activity.finish() @@ -134,5 +138,6 @@ class DeepLinkNavigator object DomainManagement : NavigateAction() data class OpenSiteMonitoringForSite(val site: SiteModel?, val siteMonitorType: SiteMonitorType) : NavigateAction() + data class OpenMySiteWithMessage(val message: Int) : NavigateAction() } } From d2c3fe1b13f180503ad2a934330cd2fd6fe0a93f Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 9 Feb 2024 07:56:36 -0500 Subject: [PATCH 3/6] Add new fun for handling open my site view with a message --- .../wordpress/android/ui/ActivityNavigator.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt index 61cb8664470a..9378e0842f6f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityNavigator.kt @@ -186,5 +186,19 @@ class ActivityNavigator @Inject constructor() { .addNextIntent(intent) .startActivities() } -} + fun openMySiteWithMessageInNewStack( + context: Context, + message: Int + ) { + val taskStackBuilder = TaskStackBuilder.create(context) + val mainActivityIntent = getMainActivityInNewStack(context) + val intent = Intent(context, WPMainActivity::class.java) + intent.putExtra(WPMainActivity.ARG_OPEN_PAGE, WPMainActivity.ARG_MY_SITE) + intent.putExtra(WPMainActivity.ARG_OPEN_PAGE_MESSAGE, message) + taskStackBuilder + .addNextIntent(mainActivityIntent) + .addNextIntent(intent) + .startActivities() + } +} From 2e43fe2561a1495d69094640cea2ace5883759fc Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 9 Feb 2024 07:57:52 -0500 Subject: [PATCH 4/6] Refactor: change the navigation action to OpenMySiteWithMessage when an error occurs finding the site --- .../android/ui/deeplinks/handlers/QRCodeMediaLinkHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandler.kt index 16f8ce2d2c7d..53b7126c967f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandler.kt @@ -28,7 +28,7 @@ class QRCodeMediaLinkHandler @Inject constructor( analyticsTrackerWrapper.track(AnalyticsTracker.Stat.DEEP_LINK_FAILED, mapOf(ERROR to INVALID_SITE_ID, CAMPAIGN to uri.getQueryParameter(CAMPAIGN)?.replace("-", "_"))) - NavigateAction.OpenMySite + NavigateAction.OpenMySiteWithMessage(org.wordpress.android.R.string.qrcode_media_deeplink_error) } else -> { NavigateAction.OpenMediaPickerForSite(siteModel) From c8ce6ee2273a652cfdfb81098f7b9bb5e7332eca Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 9 Feb 2024 07:59:42 -0500 Subject: [PATCH 5/6] Use the snackbarSequencer to show a snackbar if open page includes a message argument for super fast media uploads by qrcode. --- .../android/ui/main/WPMainActivity.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index e20b85c298d4..6d67608adebb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -29,6 +29,7 @@ import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.tasks.Task; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; import com.google.android.play.core.review.ReviewInfo; import com.google.android.play.core.review.ReviewManager; import com.google.android.play.core.review.ReviewManagerFactory; @@ -138,6 +139,7 @@ import org.wordpress.android.ui.uploads.UploadUtils; 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.whatsnew.FeatureAnnouncementDialogFragment; import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.AppLog; @@ -152,6 +154,9 @@ import org.wordpress.android.util.QuickStartUtilsWrapper; import org.wordpress.android.util.ShortcutUtils; import org.wordpress.android.util.SiteUtils; +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.analytics.AnalyticsTrackerWrapper; import org.wordpress.android.util.analytics.AnalyticsUtils; @@ -233,6 +238,7 @@ public class WPMainActivity extends LocaleAwareActivity implements public static final String ARG_IS_CHANGING_CONFIGURATION = "IS_CHANGING_CONFIGURATION"; public static final String ARG_BYPASS_MIGRATION = "bypass_migration"; public static final String ARG_MEDIA = "show_media"; + public static final String ARG_OPEN_PAGE_MESSAGE = "open_page_message"; private boolean mIsChangingConfiguration = false; private WPMainNavigationView mBottomNav; @@ -287,6 +293,8 @@ public class WPMainActivity extends LocaleAwareActivity implements @Inject ActivityNavigator mActivityNavigator; + @Inject SnackbarSequencer mSnackbarSequencer; + /* * fragments implement this if their contents can be scrolled, called when user * requests to scroll to the top @@ -380,10 +388,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } } else if (openedFromShortcut) { initSelectedSite(); - mShortcutsNavigator.showTargetScreen(getIntent().getStringExtra( - ShortcutsNavigator.ACTION_OPEN_SHORTCUT), this, getSelectedSite()); - showJetpackOverlayIfNeeded(getIntent().getStringExtra( - ShortcutsNavigator.ACTION_OPEN_SHORTCUT)); + mShortcutsNavigator.showTargetScreen(getIntent().getStringExtra( + ShortcutsNavigator.ACTION_OPEN_SHORTCUT), this, getSelectedSite()); + showJetpackOverlayIfNeeded(getIntent().getStringExtra( + ShortcutsNavigator.ACTION_OPEN_SHORTCUT)); } else if (openRequestedPage) { handleOpenPageIntent(getIntent()); } else if (isQuickStartRequestedFromPush) { @@ -880,6 +888,7 @@ protected void onNewIntent(@NonNull Intent intent) { } private void handleOpenPageIntent(@NonNull Intent intent) { + showOpenPageMessageIfNeeded(); String pagePosition = intent.getStringExtra(ARG_OPEN_PAGE); if (!TextUtils.isEmpty(pagePosition)) { switch (pagePosition) { @@ -1920,4 +1929,24 @@ private void showPrivacySettingsScreen(@Nullable Boolean requestedAnalyticsValue // startActivityForResult(intent, RequestCodes.SETTINGS); // TODO: do we need to handle the result? startActivity(intent); } + + private void showOpenPageMessageIfNeeded() { + if (getIntent() != null) { + int messageResId = getIntent().getIntExtra(ARG_OPEN_PAGE_MESSAGE, -1); + if (messageResId > -1) { + mSnackbarSequencer.enqueue( + new SnackbarItem( + new Info( + findViewById(R.id.coordinator), + new UiStringRes(messageResId), + Snackbar.LENGTH_LONG + ), + null, + null, + null + ) + ); + } + } + } } From d6921e2f28d4f0b2194d0c076121bbea3b52fc2d Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 9 Feb 2024 09:11:02 -0500 Subject: [PATCH 6/6] Update unit test to reflect new navigation action --- .../ui/deeplinks/handlers/QRCodeMediaLinkHandlerTest.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandlerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandlerTest.kt index 009f82b60a07..ec0028d4a418 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandlerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/deeplinks/handlers/QRCodeMediaLinkHandlerTest.kt @@ -8,6 +8,7 @@ import org.mockito.Mock import org.mockito.junit.MockitoJUnitRunner import org.mockito.kotlin.verify import org.mockito.kotlin.whenever +import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction @@ -76,7 +77,7 @@ class QRCodeMediaLinkHandlerTest { } @Test - fun `given unrecognized siteId, when deep linked, then opens my site view`() { + fun `given unrecognized siteId, when deep linked, then opens my site view with message`() { val mediaUri = buildUri(host = "apps.wordpress.com", queryParams = mapOf("campaign" to "qr-code-media"), path = arrayOf("get"), ) @@ -85,7 +86,7 @@ class QRCodeMediaLinkHandlerTest { val navigateAction = qrCodeMediaLinkHandler.buildNavigateAction(mediaUri) - assertThat(navigateAction).isEqualTo(NavigateAction.OpenMySite) + assertThat(navigateAction).isEqualTo(NavigateAction.OpenMySiteWithMessage(R.string.qrcode_media_deeplink_error)) } @Test