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

WearOS: Add app activities to ShortcutsTile #4556

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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 @@ -8,6 +8,8 @@ import dagger.hilt.android.AndroidEntryPoint
import io.homeassistant.companion.android.common.data.integration.onEntityPressedWithoutState
import io.homeassistant.companion.android.common.data.prefs.WearPrefsRepository
import io.homeassistant.companion.android.common.data.servers.ServerManager
import io.homeassistant.companion.android.conversation.ConversationActivity
import io.homeassistant.companion.android.home.HomeActivity
import javax.inject.Inject
import kotlinx.coroutines.runBlocking

Expand All @@ -28,16 +30,27 @@ class TileActionReceiver : BroadcastReceiver() {
val entityId: String? = intent?.getStringExtra("entity_id")

if (entityId != null) {
runBlocking {
if (wearPrefsRepository.getWearHapticFeedback() && context != null) hapticClick(context)

try {
onEntityPressedWithoutState(
entityId = entityId,
integrationRepository = serverManager.integrationRepository()
)
} catch (e: Exception) {
Log.e(TAG, "Cannot call tile service", e)
if (entityId.split(".")[0] == "app_shortcut" && context != null) {
val m = mapOf(
"assist" to ConversationActivity.newInstance(context),
"home_assistant" to HomeActivity.newInstance(context)
)
m[entityId.split(".")[1]]?.let {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(it)
}
} else {
runBlocking {
if (wearPrefsRepository.getWearHapticFeedback() && context != null) hapticClick(context)
dshokouhi marked this conversation as resolved.
Show resolved Hide resolved

try {
onEntityPressedWithoutState(
entityId = entityId,
integrationRepository = serverManager.integrationRepository()
)
} catch (e: Exception) {
Log.e(TAG, "Cannot call tile service", e)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fun ChooseEntityView(
// Remember expanded state of each header
val expandedStates = rememberExpandedStates(entitiesByDomainOrder)
var expandedFavorites: Boolean by rememberSaveable { mutableStateOf(false) }
var expandedAppShortcuts: Boolean by rememberSaveable { mutableStateOf(false) }

WearAppTheme {
ThemeLazyColumn {
Expand Down Expand Up @@ -118,6 +119,65 @@ fun ChooseEntityView(
}
}
}

// App Shortcuts
item {
ExpandableListHeader(
string = stringResource(commonR.string.shortcuts),
expanded = expandedAppShortcuts,
onExpandChanged = { expandedAppShortcuts = it }
)
}
if (expandedAppShortcuts) {
// HomeAssistant app shortcut
item {
Button(
modifier = Modifier
.fillMaxWidth(),
icon = {
Image(
asset = CommunityMaterial.Icon2.cmd_home_assistant,
colorFilter = ColorFilter.tint(Color.White)
)
},
label = { Text(stringResource(id = commonR.string.app_name)) },
onClick = {
onEntitySelected(
SimplifiedEntity(
"app_shortcut.home_assistant",
"Home Assistant",
"mdi:home-assistant"
)
)
},
colors = getFilledTonalButtonColors()
)
}
// Assist shortcut
item {
Button(
modifier = Modifier
.fillMaxWidth(),
icon = {
Image(
asset = CommunityMaterial.Icon.cmd_comment_processing_outline,
colorFilter = ColorFilter.tint(Color.White)
)
},
label = { Text(stringResource(id = commonR.string.assist)) },
onClick = {
onEntitySelected(
SimplifiedEntity(
"app_shortcut.assist",
"Assist",
"mdi:comment-processing-outline"
)
)
},
colors = getFilledTonalButtonColors()
)
}
}
}
}
}
Expand Down