Skip to content

Commit

Permalink
Add "start remote activity" action to NodeDetailsScreen (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizgrp authored Dec 21, 2023
1 parent 4450c18 commit d149958
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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>

0 comments on commit d149958

Please sign in to comment.