1
1
package com.github.lookupgroup27.lookup.ui.overview
2
2
3
3
import android.annotation.SuppressLint
4
+ import android.widget.Toast
4
5
import androidx.compose.foundation.Image
5
6
import androidx.compose.foundation.layout.*
6
7
import androidx.compose.foundation.rememberScrollState
@@ -13,13 +14,15 @@ import androidx.compose.ui.*
13
14
import androidx.compose.ui.draw.blur
14
15
import androidx.compose.ui.graphics.Color
15
16
import androidx.compose.ui.layout.ContentScale
17
+ import androidx.compose.ui.platform.LocalContext
16
18
import androidx.compose.ui.platform.testTag
17
19
import androidx.compose.ui.res.painterResource
18
20
import androidx.compose.ui.text.font.FontWeight
19
21
import androidx.compose.ui.unit.dp
20
22
import com.github.lookupgroup27.lookup.R
21
23
import com.github.lookupgroup27.lookup.ui.navigation.*
22
24
import com.github.lookupgroup27.lookup.ui.profile.profilepic.AvatarViewModel
25
+ import com.github.lookupgroup27.lookup.util.NetworkUtils
23
26
import com.google.firebase.auth.FirebaseAuth
24
27
25
28
@SuppressLint(" UnusedMaterial3ScaffoldPaddingParameter" )
@@ -31,6 +34,9 @@ fun MenuScreen(navigationActions: NavigationActions, avatarViewModel: AvatarView
31
34
32
35
val userId = auth.currentUser?.uid.orEmpty()
33
36
37
+ val context = LocalContext .current
38
+ val isOnline = remember { mutableStateOf(NetworkUtils .isNetworkAvailable(context)) }
39
+
34
40
// Fetch the selected avatar for the logged-in user
35
41
val selectedAvatar by avatarViewModel.selectedAvatar.collectAsState(initial = null )
36
42
@@ -104,23 +110,35 @@ fun MenuScreen(navigationActions: NavigationActions, avatarViewModel: AvatarView
104
110
}
105
111
Spacer (modifier = Modifier .height(8 .dp))
106
112
113
+ // Blocked buttons when offline
107
114
Button (
108
- onClick = { navigationActions.navigateTo(Screen .CALENDAR ) },
115
+ onClick = {
116
+ if (isOnline.value) navigationActions.navigateTo(Screen .CALENDAR )
117
+ else
118
+ Toast .makeText(
119
+ context,
120
+ " You're not connected to the internet" ,
121
+ Toast .LENGTH_SHORT )
122
+ .show()
123
+ },
124
+ enabled = isOnline.value,
109
125
modifier = Modifier .fillMaxWidth(0.6f )) {
110
- Text (
111
- text = " Calendar" ,
112
- style = MaterialTheme .typography.headlineSmall,
113
- fontWeight = FontWeight .Bold )
126
+ Text (" Calendar" , style = MaterialTheme .typography.headlineSmall)
114
127
}
115
- Spacer (modifier = Modifier .height(8 .dp))
116
128
117
129
Button (
118
- onClick = { navigationActions.navigateTo(Screen .GOOGLE_MAP ) },
130
+ onClick = {
131
+ if (isOnline.value) navigationActions.navigateTo(Screen .GOOGLE_MAP )
132
+ else
133
+ Toast .makeText(
134
+ context,
135
+ " You're not connected to the internet" ,
136
+ Toast .LENGTH_SHORT )
137
+ .show()
138
+ },
139
+ enabled = isOnline.value,
119
140
modifier = Modifier .fillMaxWidth(0.6f )) {
120
- Text (
121
- text = " Google Map" ,
122
- style = MaterialTheme .typography.headlineSmall,
123
- fontWeight = FontWeight .Bold )
141
+ Text (" Google Map" , style = MaterialTheme .typography.headlineSmall)
124
142
}
125
143
}
126
144
}
0 commit comments