diff --git a/README.md b/README.md index 50d1279f5f..573928b10e 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 +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/). + ## ☰ 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 {