Change default websocket behavior for google play store installations (#2274)

* Change default websocket behavior for google play store installations

* Fix changelog

* Text changes based on build variant

* Space out radio options

* Update notification text

* More text based changes and some design tweaks

* Clean up channel messaging

* Update changelog properly
This commit is contained in:
Daniel Shokouhi 2022-02-12 16:35:00 -08:00 committed by GitHub
parent 9861462a17
commit c6f1f64e6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 18 deletions

View file

@ -20,7 +20,7 @@ class WebsocketSettingViewModel @Inject constructor(
fun getWebsocketSetting(id: Int): Setting {
var setting = settingsDao.get(id)
if (setting == null) {
setting = Setting(id, if (BuildConfig.FLAVOR == "full") WebsocketSetting.SCREEN_ON else WebsocketSetting.ALWAYS)
setting = Setting(id, if (BuildConfig.FLAVOR == "full") WebsocketSetting.NEVER else WebsocketSetting.ALWAYS)
settingsDao.insert(setting)
}
return setting

View file

@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectable
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.RadioButton
import androidx.compose.material.Text
@ -21,6 +22,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.homeassistant.companion.android.BuildConfig
import io.homeassistant.companion.android.common.R
import io.homeassistant.companion.android.database.settings.WebsocketSetting
import io.homeassistant.companion.android.websocket.WebsocketManager
@ -32,21 +34,25 @@ fun WebsocketSettingView(
) {
val context = LocalContext.current
Column(modifier = Modifier.padding(20.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(bottom = 20.dp)
) {
Text(stringResource(R.string.websocket_setting_description))
}
Divider()
RadioButtonRow(
text = stringResource(R.string.websocket_setting_never),
text = stringResource(if (BuildConfig.FLAVOR == "full") R.string.websocket_setting_never else R.string.websocket_setting_never_minimal),
selected = websocketSetting == WebsocketSetting.NEVER,
onClick = { onSettingChanged(WebsocketSetting.NEVER) }
)
RadioButtonRow(
text = stringResource(R.string.websocket_setting_while_screen_on),
text = stringResource(if (BuildConfig.FLAVOR == "full") R.string.websocket_setting_while_screen_on else R.string.websocket_setting_while_screen_on_minimal),
selected = websocketSetting == WebsocketSetting.SCREEN_ON,
onClick = { onSettingChanged(WebsocketSetting.SCREEN_ON) }
)
RadioButtonRow(
text = stringResource(R.string.websocket_setting_always),
text = stringResource(if (BuildConfig.FLAVOR == "full") R.string.websocket_setting_always else R.string.websocket_setting_always_minimal),
selected = websocketSetting == WebsocketSetting.ALWAYS,
onClick = { onSettingChanged(WebsocketSetting.ALWAYS) }
)
@ -88,10 +94,12 @@ fun RadioButtonRow(
Row(
modifier = Modifier
.fillMaxWidth()
.selectable(selected = selected, onClick = onClick),
.selectable(selected = selected, onClick = onClick)
.padding(top = 20.dp, bottom = 20.dp),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(selected = selected, onClick = onClick)
Text(text)
}
Divider()
}

View file

@ -50,7 +50,7 @@ class WebsocketManager(
private const val SOURCE = "Websocket"
const val CHANNEL_ID = "Websocket"
private const val NOTIFICATION_ID = 65423
private val DEFAULT_WEBSOCKET_SETTING = if (BuildConfig.FLAVOR == "full") WebsocketSetting.SCREEN_ON else WebsocketSetting.ALWAYS
private val DEFAULT_WEBSOCKET_SETTING = if (BuildConfig.FLAVOR == "full") WebsocketSetting.NEVER else WebsocketSetting.ALWAYS
fun start(context: Context) {
val constraints = Constraints.Builder()
@ -170,7 +170,7 @@ class WebsocketManager(
if (notificationChannel == null) {
notificationChannel = NotificationChannel(
CHANNEL_ID,
CHANNEL_ID,
applicationContext.getString(R.string.websocket_setting_name),
NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel(notificationChannel)
@ -206,7 +206,7 @@ class WebsocketManager(
.setGroup(CHANNEL_ID)
.addAction(
io.homeassistant.companion.android.R.drawable.ic_websocket,
applicationContext.getString(R.string.websocket_setting_name),
applicationContext.getString(R.string.settings),
settingPendingIntent
)
.build()

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingDefaultResource">
<release version="2022.2.0">
<release version="2022.2">
<change>&lt;b&gt;2022.2.1:&lt;/b&gt;Change the default behavior of the WebSocket connection to "Never" for installations from the Google Play Store. Update settings page to be more understandable.</change>
<change>&lt;b&gt;Breaking Change:&lt;/b&gt; Local Push notifications directly from your Home Assistant instance. The app will need to maintain a consistent websockets connection by using a persistent notification. From the notification you will be able to access websockets settings to adjust the behavior of the connection as well as the notification channel. You are free to minimize the notification channel to hide the icon. If you are on the minimal build you will need to have Home Assistant Core on 2022.2 in order for the notify service call to be created.</change>
<change>&lt;b&gt;Breaking Change:&lt;/b&gt; The Do Not Disturb sensor is now only available on devices running Android 6 or higher. The sensor was updated to use a documented API rather than the undocumented method used.</change>
<change>&lt;b&gt;Breaking Change:&lt;/b&gt; The Last Used App sensor will now report its state as the package name to always be unique. The old state will now be an attribute of the sensor.</change>

View file

@ -690,7 +690,7 @@
<string name="wear_os_settings_title">Wear OS Settings</string>
<string name="wear_set_favorites">Select your favorite entities to appear at the top of the wear home screen. You can also drag and drop to change the order in which they appear.</string>
<string name="wear_settings">Wear Device Settings</string>
<string name="websocket_listening">Listening to Home Assistant via Websocket</string>
<string name="websocket_listening">Connected to Home Assistant</string>
<string name="webview_error_AUTH_SCHEME">Unsupported authentication scheme (not basic or digest), please check network settings.</string>
<string name="webview_error_AUTHENTICATION">User authentication failed on server, please check server settings.</string>
<string name="webview_error_description">Encountered error :</string>
@ -744,14 +744,17 @@
<string name="basic_sensor_name_last_used_app">Last Used App</string>
<string name="sensor_description_last_used_app">Application name or package name of the last used application on the device</string>
<string name="sensor_name_last_app">Last Used App</string>
<string name="websocket_setting_name">Websocket Settings</string>
<string name="websocket_setting_summary">Manage when we are in direct communication with your server via websockets.</string>
<string name="websocket_setting_description">Please select when you would like the application to attempt to directly communicate with your Home Assistant instance for all communication. This will include push notifications, if you are on a minimal build this needs to be always to consistently get push notifications.</string>
<string name="websocket_setting_never">Never</string>
<string name="websocket_setting_while_screen_on">While Screen On</string>
<string name="websocket_setting_name">Persistent Connection</string>
<string name="websocket_setting_summary">Manage when we have a persistent connection to your Home Assistant server.</string>
<string name="websocket_setting_description">The app can maintain a persistent connection with your Home Assistant instance. This allows the app to receive push notifications directly.\n\nWhen do you want to use a persistent connection:</string>
<string name="websocket_setting_never">Never\n\nNotifications will be delivered via Google. This option is the most battery efficient.</string>
<string name="websocket_setting_never_minimal">Never\n\nDisables notifications</string>
<string name="websocket_setting_while_screen_on">While the screen is on\n\nWhen the screen is off, notifications will be delivered via Google</string>
<string name="websocket_setting_while_screen_on_minimal">While the screen is on\n\nNotifications will not be received when the screen is off</string>
<string name="websocket_setting_always">Always</string>
<string name="websocket_persistent_notification">In order to maintain the websocket connection the app will need to create a persistent notification. You may use the button below to manage the appearance of this notification. It is recommended to minimize the notification to hide the icon.</string>
<string name="websocket_notification_channel">Manage Websocket Notification Channel</string>
<string name="websocket_setting_always_minimal">Always\n\nRequired to always receive notifications</string>
<string name="websocket_persistent_notification">In order to maintain the persistent connection the app will need to create a persistent notification. You may use the button below to manage the appearance of this notification. It is recommended to minimize the notification to hide the icon.</string>
<string name="websocket_notification_channel">Manage Persistent Connection Notification</string>
<string name="notification_channels">Notification Channels</string>
<string name="notification_channels_summary">Manage all notification channels configured on the device. Channels control the behavior of its notifications including visibility and sound.</string>
<string name="info">Information</string>