Skip to content

Commit

Permalink
Merge pull request #100 from NordicPlayground/permission/wifi/enablel…
Browse files Browse the repository at this point in the history
…ocation

Added enable location view
  • Loading branch information
himalia416 authored Jun 17, 2024
2 parents 7e8f64b + 24d5ae5 commit b242995
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import no.nordicsemi.android.common.permissions.wifi.utils.WifiPermissionNotAvailableReason
import no.nordicsemi.android.common.permissions.wifi.utils.WifiPermissionState
import no.nordicsemi.android.common.permissions.wifi.view.LocationDisabledView
import no.nordicsemi.android.common.permissions.wifi.view.LocationPermissionRequiredView
import no.nordicsemi.android.common.permissions.wifi.viewmodel.PermissionViewModel

Expand All @@ -60,7 +61,7 @@ fun RequireLocationForWifi(
when (val s = state) {
WifiPermissionState.Available -> content(false)
is WifiPermissionState.NotAvailable -> when (s.reason) {
WifiPermissionNotAvailableReason.DISABLED -> content(true)
WifiPermissionNotAvailableReason.DISABLED -> LocationDisabledView()
else -> contentWithoutLocation()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package no.nordicsemi.android.common.permissions.wifi.view

import android.content.Context
import android.content.Intent
import android.provider.Settings
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LocationOff
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import no.nordicsemi.android.common.permissions.wifi.R
import no.nordicsemi.android.common.theme.NordicTheme
import no.nordicsemi.android.common.theme.view.WarningView

@Composable
internal fun LocationDisabledView() {
WarningView(
imageVector = Icons.Default.LocationOff,
title = stringResource(id = R.string.location_disabled),
hint = stringResource(id = R.string.location_disabled_des),
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
) {
val context = LocalContext.current
Button(onClick = { enableLocation(context) }) {
Text(text = stringResource(id = R.string.enable_location))
}
}
}

private fun enableLocation(context: Context) {
context.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
}

@Preview
@Composable
private fun LocationDisabledViewPreview() {
NordicTheme {
LocationDisabledView()
}
}
4 changes: 4 additions & 0 deletions permissions-wifi/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<string name="wifi_not_available">WI-FI NOT AVAILABLE</string>
<string name="wifi_not_available_des">Wi-Fi is not available on this device.</string>

<string name="location_disabled">LOCATION DISABLED</string>
<string name="location_disabled_des">Location is disabled. Please enable location to scan for Wi-Fi networks.</string>
<string name="enable_location">Enable Location</string>

<string name="grant_permission">Grant Permission</string>
<string name="settings">Settings</string>

Expand Down

0 comments on commit b242995

Please sign in to comment.