-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add app helper nodes actions screen to datalayer wear sample
- Loading branch information
Showing
11 changed files
with
546 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
.../com/google/android/horologist/datalayer/sample/screens/nodesactions/NodeDetailsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.datalayer.sample.screens.nodesactions | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.wear.compose.material.Text | ||
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumn | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumnState | ||
import com.google.android.horologist.compose.layout.belowTimeTextPreview | ||
import com.google.android.horologist.compose.material.Chip | ||
import com.google.android.horologist.datalayer.sample.R | ||
|
||
@Composable | ||
fun NodeDetailsScreen( | ||
columnState: ScalingLazyColumnState, | ||
modifier: Modifier = Modifier, | ||
viewModel: NodeDetailsViewModel = hiltViewModel(), | ||
) { | ||
NodeDetailsScreen( | ||
nodeId = viewModel.nodeId, | ||
onStartCompanionClick = viewModel::onStartCompanionClick, | ||
onInstallOnNodeClick = viewModel::onInstallOnNodeClick, | ||
onStartRemoteOwnAppClick = viewModel::onStartRemoteOwnAppClick, | ||
columnState = columnState, | ||
modifier = modifier, | ||
) | ||
} | ||
|
||
@Composable | ||
fun NodeDetailsScreen( | ||
nodeId: String, | ||
onStartCompanionClick: () -> Unit, | ||
onInstallOnNodeClick: () -> Unit, | ||
onStartRemoteOwnAppClick: () -> Unit, | ||
columnState: ScalingLazyColumnState, | ||
modifier: Modifier = Modifier, | ||
) { | ||
ScalingLazyColumn( | ||
columnState = columnState, | ||
modifier = modifier.fillMaxSize(), | ||
) { | ||
item { | ||
Text( | ||
text = stringResource(id = R.string.node_details_header), | ||
modifier = Modifier.padding(bottom = 10.dp), | ||
) | ||
} | ||
|
||
item { | ||
Text( | ||
text = stringResource(id = R.string.node_details_id, nodeId), | ||
) | ||
} | ||
item { | ||
Chip( | ||
label = stringResource(id = R.string.node_details_start_companion_chip_label), | ||
onClick = onStartCompanionClick, | ||
) | ||
} | ||
item { | ||
Chip( | ||
label = stringResource(id = R.string.node_details_install_on_node_chip_label), | ||
onClick = onInstallOnNodeClick, | ||
) | ||
} | ||
item { | ||
Chip( | ||
label = stringResource(id = R.string.node_details_start_remote_own_app_chip_label), | ||
onClick = onStartRemoteOwnAppClick, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@WearPreviewDevices | ||
@Composable | ||
fun NodeDetailsScreenPreview() { | ||
NodeDetailsScreen( | ||
nodeId = "12345", | ||
onStartCompanionClick = { }, | ||
onInstallOnNodeClick = { }, | ||
onStartRemoteOwnAppClick = { }, | ||
columnState = belowTimeTextPreview(), | ||
) | ||
} |
57 changes: 57 additions & 0 deletions
57
...e/android/horologist/datalayer/sample/screens/nodesactions/NodeDetailsScreenNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.datalayer.sample.screens.nodesactions | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavType | ||
import androidx.navigation.navArgument | ||
import com.google.android.horologist.compose.navscaffold.scrollable | ||
import com.google.android.horologist.datalayer.sample.Screen | ||
import java.net.URLDecoder | ||
import java.net.URLEncoder | ||
|
||
private const val nodeIdArg = "nodeId" | ||
private const val routePrefix = "appHelperNodeDetailsScreen" | ||
|
||
private val URL_CHARACTER_ENCODING = Charsets.UTF_8.name() | ||
|
||
const val nodeDetailsScreenRoute = "$routePrefix/{$nodeIdArg}" | ||
|
||
internal class NodeDetailsScreenArgs(val nodeId: String) { | ||
constructor(savedStateHandle: SavedStateHandle) : | ||
this(URLDecoder.decode(checkNotNull(savedStateHandle[nodeIdArg]), URL_CHARACTER_ENCODING)) | ||
} | ||
|
||
fun NavController.navigateToNodeDetailsScreen(message: String) { | ||
val encodedMessage = URLEncoder.encode(message, URL_CHARACTER_ENCODING) | ||
this.navigate("$routePrefix/$encodedMessage") | ||
} | ||
|
||
fun NavGraphBuilder.nodeDetailsScreen() { | ||
scrollable( | ||
route = Screen.AppHelperNodeDetailsScreen.route, | ||
arguments = listOf( | ||
navArgument(nodeIdArg) { type = NavType.StringType }, | ||
), | ||
) { | ||
NodeDetailsScreen( | ||
columnState = it.columnState, | ||
) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...m/google/android/horologist/datalayer/sample/screens/nodesactions/NodeDetailsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.datalayer.sample.screens.nodesactions | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.google.android.horologist.datalayer.watch.WearDataLayerAppHelper | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class NodeDetailsViewModel | ||
@Inject | ||
constructor( | ||
savedStateHandle: SavedStateHandle, | ||
private val wearDataLayerAppHelper: WearDataLayerAppHelper, | ||
) : ViewModel() { | ||
private val nodeDetailsScreenArgs: NodeDetailsScreenArgs = | ||
NodeDetailsScreenArgs(savedStateHandle) | ||
|
||
val nodeId: String | ||
get() = nodeDetailsScreenArgs.nodeId | ||
|
||
fun onStartCompanionClick() { | ||
viewModelScope.launch { | ||
wearDataLayerAppHelper.startCompanion(node = nodeId) | ||
} | ||
} | ||
|
||
fun onInstallOnNodeClick() { | ||
viewModelScope.launch { | ||
wearDataLayerAppHelper.installOnNode(node = nodeId) | ||
} | ||
} | ||
|
||
fun onStartRemoteOwnAppClick() { | ||
viewModelScope.launch { | ||
wearDataLayerAppHelper.startRemoteOwnApp(node = nodeId) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...n/java/com/google/android/horologist/datalayer/sample/screens/nodesactions/NodeUiModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.datalayer.sample.screens.nodesactions | ||
|
||
data class NodeUiModel( | ||
val id: String, | ||
val name: String, | ||
val appInstalled: Boolean, | ||
val type: NodeTypeUiModel, | ||
) | ||
|
||
enum class NodeTypeUiModel { | ||
WATCH, | ||
PHONE, | ||
UNKNOWN, | ||
} |
Oops, something went wrong.