Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "start remote activity" action to NodeDetailsScreen #1912

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fun NodeDetailsScreen(
onStartCompanionClick = viewModel::onStartCompanionClick,
onInstallOnNodeClick = viewModel::onInstallOnNodeClick,
onStartRemoteOwnAppClick = viewModel::onStartRemoteOwnAppClick,
onStartRemoteActivityClick = viewModel::onStartRemoteActivityClick,
onDialogDismiss = viewModel::onDialogDismiss,
columnState = columnState,
modifier = modifier,
Expand All @@ -76,6 +77,7 @@ fun NodeDetailsScreen(
onStartCompanionClick: () -> Unit,
onInstallOnNodeClick: () -> Unit,
onStartRemoteOwnAppClick: () -> Unit,
onStartRemoteActivityClick: () -> Unit,
onDialogDismiss: () -> Unit,
columnState: ScalingLazyColumnState,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -120,6 +122,12 @@ fun NodeDetailsScreen(
onClick = onStartRemoteOwnAppClick,
)
}
item {
Chip(
label = stringResource(id = R.string.node_details_start_remote_activity_chip_label),
onClick = onStartRemoteActivityClick,
)
}
}

NodeDetailsScreenState.ActionRunning -> {
Expand Down Expand Up @@ -209,6 +217,7 @@ fun NodeDetailsScreenPreview() {
onStartCompanionClick = { },
onInstallOnNodeClick = { },
onStartRemoteOwnAppClick = { },
onStartRemoteActivityClick = { },
onDialogDismiss = { },
columnState = belowTimeTextPreview(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.horologist.data.AppHelperResultCode
import com.google.android.horologist.data.activityConfig
import com.google.android.horologist.datalayer.watch.WearDataLayerAppHelper
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

private const val REMOTE_ACTIVITY_SAMPLE_PACKAGE_NAME = "com.google.android.gm"
private const val REMOTE_ACTIVITY_SAMPLE_CLASS_FULL_NAME = "com.google.android.gm.ConversationListActivityGmail"

@HiltViewModel
class NodeDetailsViewModel
@Inject
Expand Down Expand Up @@ -70,6 +74,16 @@ class NodeDetailsViewModel
}
}

fun onStartRemoteActivityClick() {
runActionAndHandleAppHelperResult {
val config = activityConfig {
packageName = REMOTE_ACTIVITY_SAMPLE_PACKAGE_NAME
classFullName = REMOTE_ACTIVITY_SAMPLE_CLASS_FULL_NAME
}
wearDataLayerAppHelper.startRemoteActivity(nodeId, config)
}
}

fun onDialogDismiss() {
_uiState.value = NodeDetailsScreenState.Idle
}
Expand Down
1 change: 1 addition & 0 deletions datalayer/sample/wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<string name="node_details_start_companion_chip_label">Start companion</string>
<string name="node_details_install_on_node_chip_label">Install on node</string>
<string name="node_details_start_remote_own_app_chip_label">Start remote own app</string>
<string name="node_details_start_remote_activity_chip_label">Start remote activity</string>
<string name="node_details_success_dialog_message">Success!</string>
<string name="node_details_failure_dialog_message">Failed: \n%1$s</string>
</resources>