From 4e97bafc14239b5d81784122dfca4bd0c0c13919 Mon Sep 17 00:00:00 2001 From: Chiara Chiappini Date: Sat, 16 Mar 2024 05:45:20 +0000 Subject: [PATCH 1/2] Add datalayer to README. Move Tile name to constant.Add exception if version format is not correct. --- README.md | 10 ++++++++++ datalayer/phone-ui/api/current.api | 2 +- .../phone/ui/prompt/installtile/InstallTilePrompt.kt | 3 +-- .../datalayer/phone/PhoneDataLayerAppHelper.kt | 10 ++++++++-- .../installtile/InstallTilePromptDemoViewModel.kt | 6 +++++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 50d1279f5f..c30565c41d 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,16 @@ the [Sign-In guidelines for Wear OS](https://developer.android.com/training/wear - [sample wear](https://google.github.io/horologist/auth-sample-apps/#wear-sample): sample wear app to authenticate using different methods. - [sample phone](https://google.github.io/horologist/auth-sample-apps/#phone-sample): sample phone app to authenticate using different methods. +## DataLayer + +The Horologist DataLayer library, provide common abstractions on top of the +[Wearable DataLayer](https://developer.android.com/training/wearables/data/data-layer). +It includes libraries to build +[prompts on the phone](https://google.github.io/horologist/datalayer-phone-ui/) to improve +engagament with the correspondent Wear app and a +[sample](https://google.github.io/horologist/datalayer-sample/) to see the prompts in actions. +Find guidance in the project [documentation](https://google.github.io/horologist/datalayer/). + ## ☰ Tiles Kotlin coroutines flavoured TileService. diff --git a/datalayer/phone-ui/api/current.api b/datalayer/phone-ui/api/current.api index 3e0248c82f..927a00256a 100644 --- a/datalayer/phone-ui/api/current.api +++ b/datalayer/phone-ui/api/current.api @@ -31,7 +31,7 @@ package com.google.android.horologist.datalayer.phone.ui.prompt.installtile { @com.google.android.horologist.annotations.ExperimentalHorologistApi public final class InstallTilePrompt { ctor public InstallTilePrompt(com.google.android.horologist.datalayer.phone.PhoneDataLayerAppHelper phoneDataLayerAppHelper); method public android.content.Intent getIntent(android.content.Context context, String appPackageName, @DrawableRes int image, String topMessage, String bottomMessage); - method public suspend Object? shouldDisplayPrompt(kotlin.coroutines.Continuation); + method public suspend Object? shouldDisplayPrompt(String tileName, kotlin.coroutines.Continuation); } } diff --git a/datalayer/phone-ui/src/main/java/com/google/android/horologist/datalayer/phone/ui/prompt/installtile/InstallTilePrompt.kt b/datalayer/phone-ui/src/main/java/com/google/android/horologist/datalayer/phone/ui/prompt/installtile/InstallTilePrompt.kt index 7ec0d354c2..cac99e6419 100644 --- a/datalayer/phone-ui/src/main/java/com/google/android/horologist/datalayer/phone/ui/prompt/installtile/InstallTilePrompt.kt +++ b/datalayer/phone-ui/src/main/java/com/google/android/horologist/datalayer/phone/ui/prompt/installtile/InstallTilePrompt.kt @@ -33,8 +33,7 @@ public class InstallTilePrompt(private val phoneDataLayerAppHelper: PhoneDataLay * Returns a [AppHelperNodeStatus] that meets the criteria to show this prompt, otherwise * returns null. */ - private val tileName = "com.example.MediaPlayerTile" - public suspend fun shouldDisplayPrompt(): AppHelperNodeStatus? { + public suspend fun shouldDisplayPrompt(tileName: String): AppHelperNodeStatus? { if (phoneDataLayerAppHelper.checkCompanionVersionSupportTileEditing() ?.equals(AppHelperResultCode.APP_HELPER_RESULT_SUCCESS) == true ) { diff --git a/datalayer/phone/src/main/java/com/google/android/horologist/datalayer/phone/PhoneDataLayerAppHelper.kt b/datalayer/phone/src/main/java/com/google/android/horologist/datalayer/phone/PhoneDataLayerAppHelper.kt index 4c5cf31e24..dfd7a8ec39 100644 --- a/datalayer/phone/src/main/java/com/google/android/horologist/datalayer/phone/PhoneDataLayerAppHelper.kt +++ b/datalayer/phone/src/main/java/com/google/android/horologist/datalayer/phone/PhoneDataLayerAppHelper.kt @@ -122,8 +122,14 @@ public class PhoneDataLayerAppHelper( } else { return AppHelperResultCode.APP_HELPER_RESULT_INVALID_COMPANION } - } catch (e: PackageManager.NameNotFoundException) { - return AppHelperResultCode.APP_HELPER_RESULT_NO_COMPANION_FOUND + } catch (ex: Exception) { + when (ex) { + is PackageManager.NameNotFoundException, is IllegalArgumentException -> { + return AppHelperResultCode.APP_HELPER_RESULT_NO_COMPANION_FOUND + } + + else -> throw ex + } } } diff --git a/datalayer/sample/phone/src/main/java/com/google/android/horologist/datalayer/sample/screens/inappprompts/installtile/InstallTilePromptDemoViewModel.kt b/datalayer/sample/phone/src/main/java/com/google/android/horologist/datalayer/sample/screens/inappprompts/installtile/InstallTilePromptDemoViewModel.kt index f98e01854f..cb9cc47a22 100644 --- a/datalayer/sample/phone/src/main/java/com/google/android/horologist/datalayer/sample/screens/inappprompts/installtile/InstallTilePromptDemoViewModel.kt +++ b/datalayer/sample/phone/src/main/java/com/google/android/horologist/datalayer/sample/screens/inappprompts/installtile/InstallTilePromptDemoViewModel.kt @@ -61,7 +61,7 @@ class InstallTilePromptDemoViewModel _uiState.value = InstallTilePromptDemoScreenState.Loading viewModelScope.launch { - val node = installTilePrompt.shouldDisplayPrompt() + val node = installTilePrompt.shouldDisplayPrompt(TILE_NAME) _uiState.value = if (node != null) { InstallTilePromptDemoScreenState.WatchFound(node.id) @@ -82,6 +82,10 @@ class InstallTilePromptDemoViewModel fun onPromptDismiss() { _uiState.value = InstallTilePromptDemoScreenState.PromptDismissed } + + companion object { + private const val TILE_NAME = "com.example.MediaPlayerTile" + } } sealed class InstallTilePromptDemoScreenState { From fad063e458796d9854ebf9b0a051b900fc11fc71 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Mon, 18 Mar 2024 11:58:51 +0000 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c30565c41d..573928b10e 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ The Horologist DataLayer library, provide common abstractions on top of the [Wearable DataLayer](https://developer.android.com/training/wearables/data/data-layer). It includes libraries to build [prompts on the phone](https://google.github.io/horologist/datalayer-phone-ui/) to improve -engagament with the correspondent Wear app and a +engagement with the correspondent Wear app and a [sample](https://google.github.io/horologist/datalayer-sample/) to see the prompts in actions. Find guidance in the project [documentation](https://google.github.io/horologist/datalayer/).