Skip to content

Commit fe0b2a9

Browse files
committed
Apply PR comments
1 parent 5078758 commit fe0b2a9

File tree

7 files changed

+43
-49
lines changed

7 files changed

+43
-49
lines changed

app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,6 @@ class WebViewActivity :
274274

275275
private val snackbarHostState = SnackbarHostState()
276276

277-
/**
278-
* Indicates if the current state is insecure. If so we should not load the URL.
279-
*/
280-
private var isInsecureState: Boolean = false
281-
282277
@SuppressLint("SetJavaScriptEnabled")
283278
override fun onCreate(savedInstanceState: Bundle?) {
284279
if (
@@ -1422,7 +1417,6 @@ class WebViewActivity :
14221417
private suspend fun secureLoadUrl(url: String) {
14231418
fun loadAndWait() {
14241419
webView.loadUrl(url)
1425-
isInsecureState = false
14261420
waitForConnection()
14271421
}
14281422

@@ -1431,9 +1425,7 @@ class WebViewActivity :
14311425
return
14321426
}
14331427

1434-
val allowInsecureConnection = serverManager.integrationRepository(
1435-
presenter.getActiveServer(),
1436-
).getAllowInsecureConnection()
1428+
val allowInsecureConnection = presenter.getAllowInsecureConnection()
14371429

14381430
when (allowInsecureConnection) {
14391431
null, true -> loadAndWait()
@@ -1443,7 +1435,6 @@ class WebViewActivity :
14431435
)?.connection?.currentSecurityStatusForUrl(this, url)
14441436
when (status) {
14451437
is SecurityStatus.Insecure, null -> {
1446-
isInsecureState = true
14471438
showBlockInsecureFragment(
14481439
serverId = presenter.getActiveServer(),
14491440
missingHomeSetup = status?.missingHomeSetup ?: false,

app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewPresenter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ interface WebViewPresenter {
6060
*/
6161
suspend fun shouldSetSecurityLevel(): Boolean
6262

63+
suspend fun getAllowInsecureConnection(): Boolean?
64+
6365
suspend fun getAuthorizationHeader(): String
6466

6567
suspend fun parseWebViewColor(webViewColor: String): Int

app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ class WebViewPresenterImpl @Inject constructor(
362362
return serverManager.integrationRepository(serverId).getAllowInsecureConnection() == null
363363
}
364364

365+
override suspend fun getAllowInsecureConnection(): Boolean? =
366+
serverManager.integrationRepository(serverId).getAllowInsecureConnection()
367+
365368
override suspend fun getAuthorizationHeader(): String {
366369
return serverManager.getServer(serverId)?.let {
367370
serverManager.authenticationRepository(serverId).buildBearerToken()

app/src/main/kotlin/io/homeassistant/companion/android/webview/insecure/BlockInsecureFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment
1212
import androidx.fragment.app.setFragmentResult
1313
import dagger.hilt.android.AndroidEntryPoint
1414
import io.homeassistant.companion.android.common.compose.theme.HATheme
15+
import io.homeassistant.companion.android.common.data.servers.ServerManager
1516
import io.homeassistant.companion.android.common.util.DisabledLocationHandler
1617
import io.homeassistant.companion.android.settings.ConnectionSecurityLevelFragment
1718
import io.homeassistant.companion.android.settings.SettingsActivity
@@ -40,7 +41,7 @@ class BlockInsecureFragment private constructor() : Fragment() {
4041
}
4142

4243
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
43-
val serverId = arguments?.getInt(EXTRA_SERVER, -1) ?: -1
44+
val serverId = arguments?.getInt(EXTRA_SERVER, ServerManager.SERVER_ID_ACTIVE) ?: ServerManager.SERVER_ID_ACTIVE
4445
val missingHomeSetup = arguments?.getBoolean(EXTRA_MISSING_HOME_SETUP, false) ?: false
4546
val missingLocation = arguments?.getBoolean(EXTRA_MISSING_LOCATION, false) ?: false
4647

app/src/main/kotlin/io/homeassistant/companion/android/webview/insecure/BlockInsecureScreen.kt

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import androidx.compose.foundation.rememberScrollState
1717
import androidx.compose.foundation.verticalScroll
1818
import androidx.compose.material.icons.Icons
1919
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
20-
import androidx.compose.material.icons.filled.Lock
2120
import androidx.compose.material.icons.outlined.Replay
2221
import androidx.compose.material3.Icon
2322
import androidx.compose.material3.IconButton
@@ -26,10 +25,13 @@ import androidx.compose.material3.Text
2625
import androidx.compose.runtime.Composable
2726
import androidx.compose.ui.Alignment
2827
import androidx.compose.ui.Modifier
28+
import androidx.compose.ui.graphics.ColorFilter
2929
import androidx.compose.ui.res.stringResource
3030
import androidx.compose.ui.text.style.TextAlign
3131
import androidx.compose.ui.unit.dp
3232
import com.google.accompanist.permissions.ExperimentalPermissionsApi
33+
import com.mikepenz.iconics.compose.Image
34+
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
3335
import io.homeassistant.companion.android.common.R as commonR
3436
import io.homeassistant.companion.android.common.compose.composable.HAAccentButton
3537
import io.homeassistant.companion.android.common.compose.composable.HABanner
@@ -67,43 +69,38 @@ internal fun BlockInsecureScreen(
6769
Scaffold(
6870
contentWindowInsets = WindowInsets.safeDrawing,
6971
topBar = { TopBar(onRetry = onRetry, onHelpClick = onHelpClick) },
72+
modifier = modifier,
7073
) { contentPadding ->
7174
Column(
72-
modifier = modifier
75+
modifier = Modifier
7376
.fillMaxSize()
74-
.padding(contentPadding),
77+
.verticalScroll(rememberScrollState())
78+
.padding(contentPadding)
79+
.padding(horizontal = HADimens.SPACE4),
7580
horizontalAlignment = Alignment.CenterHorizontally,
81+
verticalArrangement = Arrangement.spacedBy(HADimens.SPACE6),
7682
) {
77-
Column(
78-
modifier = Modifier
79-
.fillMaxSize()
80-
.verticalScroll(rememberScrollState())
81-
.padding(horizontal = HADimens.SPACE4),
82-
horizontalAlignment = Alignment.CenterHorizontally,
83-
verticalArrangement = Arrangement.spacedBy(HADimens.SPACE6),
84-
) {
85-
Header()
86-
87-
if (missingLocation) {
88-
FixBanner(
89-
text = stringResource(commonR.string.block_insecure_missing_location),
90-
actionText = stringResource(commonR.string.block_insecure_action_enable_location),
91-
onFixClick = locationPermissions::launchMultiplePermissionRequest,
92-
)
93-
}
94-
95-
if (missingHomeSetup) {
96-
FixBanner(
97-
text = stringResource(commonR.string.block_insecure_missing_home_setup),
98-
actionText = stringResource(commonR.string.block_insecure_action_configure_home),
99-
onFixClick = onConfigureHomeNetwork,
100-
)
101-
}
102-
103-
Spacer(modifier = Modifier.weight(1f))
104-
105-
BottomButtons(onOpenSettings = onOpenSettings, onChangeSecurityLevel = onChangeSecurityLevel)
83+
Header()
84+
85+
if (missingLocation) {
86+
FixBanner(
87+
text = stringResource(commonR.string.block_insecure_missing_location),
88+
actionText = stringResource(commonR.string.block_insecure_action_enable_location),
89+
onFixClick = locationPermissions::launchMultiplePermissionRequest,
90+
)
91+
}
92+
93+
if (missingHomeSetup) {
94+
FixBanner(
95+
text = stringResource(commonR.string.block_insecure_missing_home_setup),
96+
actionText = stringResource(commonR.string.block_insecure_action_configure_home),
97+
onFixClick = onConfigureHomeNetwork,
98+
)
10699
}
100+
101+
Spacer(modifier = Modifier.weight(1f))
102+
103+
BottomButtons(onOpenSettings = onOpenSettings, onChangeSecurityLevel = onChangeSecurityLevel)
107104
}
108105
}
109106
}
@@ -132,12 +129,12 @@ private fun TopBar(onRetry: () -> Unit, onHelpClick: () -> Unit) {
132129

133130
@Composable
134131
private fun ColumnScope.Header() {
135-
Icon(
132+
Image(
136133
modifier = Modifier
137134
.padding(all = 20.dp)
138135
.size(120.dp),
139-
imageVector = Icons.Default.Lock,
140-
tint = LocalHAColorScheme.current.colorOnPrimaryNormal,
136+
asset = CommunityMaterial.Icon2.cmd_lock_open_alert,
137+
colorFilter = ColorFilter.tint(LocalHAColorScheme.current.colorOnPrimaryNormal),
141138
contentDescription = null,
142139
)
143140

build-logic/convention/src/main/kotlin/AndroidComposeConventionPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AndroidComposeConventionPlugin : Plugin<Project> {
3737
tasks.withType<PreviewScreenshotValidationTask>().configureEach {
3838
// Hack until we get the update of the screenshot libray
3939
// https://issuetracker.google.com/issues/444048026
40-
// 3g is the minimal value for our tests to pass currently
40+
// 4g is the minimal value for our tests to pass currently
4141
maxHeapSize = "4g"
4242
}
4343

common/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,8 @@
14741474
<string name="location_secure_connection_discard_permission">Location permission denied. Allow access or choose the \'Less secure\' option.</string>
14751475
<string name="block_insecure_title">Insecure connection blocked</string>
14761476
<string name="block_insecure_content">This connection is not secure because it uses HTTP. You have chosen to block insecure connections when not at home.</string>
1477-
<string name="block_insecure_missing_home_setup">The app cannot determine if you are at home because no home network has been configured.</string>
1478-
<string name="block_insecure_missing_location">Location is required to detect your home network. Android requires this because network information can be used to infer your location.</string>
1477+
<string name="block_insecure_missing_home_setup">The app cannot determine whether you are at home because no home network has been configured.</string>
1478+
<string name="block_insecure_missing_location">Location access is required to detect your home network. Android requires this because network information can be used to infer your location.</string>
14791479
<string name="block_insecure_action_enable_location">Enable location</string>
14801480
<string name="block_insecure_action_configure_home">Configure home network</string>
14811481
<string name="block_insecure_retry">Retry</string>

0 commit comments

Comments
 (0)