1
+ /*
2
+ * Copyright (c) 2024, Nordic Semiconductor
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification, are
6
+ * permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
9
+ * conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12
+ * of conditions and the following disclaimer in the documentation and/or other materials
13
+ * provided with the distribution.
14
+ *
15
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be
16
+ * used to endorse or promote products derived from this software without specific prior
17
+ * written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+
32
+ package no.nordicsemi.android.common.permissions.wifi.view
33
+
34
+ import android.content.Context
35
+ import android.content.Intent
36
+ import android.provider.Settings
37
+ import androidx.compose.foundation.layout.fillMaxSize
38
+ import androidx.compose.foundation.rememberScrollState
39
+ import androidx.compose.foundation.verticalScroll
40
+ import androidx.compose.material.icons.Icons
41
+ import androidx.compose.material.icons.filled.LocationOff
42
+ import androidx.compose.material3.Button
43
+ import androidx.compose.material3.Text
44
+ import androidx.compose.runtime.Composable
45
+ import androidx.compose.ui.Modifier
46
+ import androidx.compose.ui.platform.LocalContext
47
+ import androidx.compose.ui.res.stringResource
48
+ import androidx.compose.ui.tooling.preview.Preview
49
+ import no.nordicsemi.android.common.permissions.wifi.R
50
+ import no.nordicsemi.android.common.theme.NordicTheme
51
+ import no.nordicsemi.android.common.theme.view.WarningView
52
+
53
+ @Composable
54
+ internal fun LocationDisabledView () {
55
+ WarningView (
56
+ imageVector = Icons .Default .LocationOff ,
57
+ title = stringResource(id = R .string.location_disabled),
58
+ hint = stringResource(id = R .string.location_disabled_des),
59
+ modifier = Modifier
60
+ .fillMaxSize()
61
+ .verticalScroll(rememberScrollState())
62
+ ) {
63
+ val context = LocalContext .current
64
+ Button (onClick = { enableLocation(context) }) {
65
+ Text (text = stringResource(id = R .string.enable_location))
66
+ }
67
+ }
68
+ }
69
+
70
+ private fun enableLocation (context : Context ) {
71
+ context.startActivity(Intent (Settings .ACTION_LOCATION_SOURCE_SETTINGS ))
72
+ }
73
+
74
+ @Preview
75
+ @Composable
76
+ private fun LocationDisabledViewPreview () {
77
+ NordicTheme {
78
+ LocationDisabledView ()
79
+ }
80
+ }
0 commit comments