Skip to content

Commit 81178d0

Browse files
authored
Merge pull request #78 from prudhvir3ddy/prudhvir3ddy/safe-permission-category
Refactor: Update permission handling to use PermissionType enum
2 parents 14a1cd9 + 68bc1e4 commit 81178d0

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

app/src/main/java/com/bitchat/android/onboarding/PermissionExplanationScreen.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ private fun PermissionCategoryCard(
183183
horizontalArrangement = Arrangement.spacedBy(12.dp)
184184
) {
185185
Text(
186-
text = getPermissionEmoji(category.name),
186+
text = getPermissionEmoji(category.type),
187187
style = MaterialTheme.typography.titleLarge,
188-
color = getPermissionIconColor(category.name),
188+
color = getPermissionIconColor(category.type),
189189
modifier = Modifier.size(24.dp)
190190
)
191191

192192
Text(
193-
text = category.name,
193+
text = category.type.nameValue,
194194
style = MaterialTheme.typography.titleSmall.copy(
195195
fontWeight = FontWeight.Bold,
196196
color = colorScheme.onSurface
@@ -207,7 +207,7 @@ private fun PermissionCategoryCard(
207207
)
208208
)
209209

210-
if (category.name == "Precise Location") {
210+
if (category.type == PermissionType.PRECISE_LOCATION) {
211211
// Extra emphasis for location permission
212212
Row(
213213
verticalAlignment = Alignment.CenterVertically,
@@ -232,20 +232,20 @@ private fun PermissionCategoryCard(
232232
}
233233
}
234234

235-
private fun getPermissionEmoji(categoryName: String): String {
236-
return when (categoryName) {
237-
"Nearby Devices" -> "📱"
238-
"Precise Location" -> "📍"
239-
"Notifications" -> "🔔"
240-
else -> "🔧"
235+
private fun getPermissionEmoji(permissionType: PermissionType): String {
236+
return when (permissionType) {
237+
PermissionType.NEARBY_DEVICES -> "📱"
238+
PermissionType.PRECISE_LOCATION -> "📍"
239+
PermissionType.NOTIFICATIONS -> "🔔"
240+
PermissionType.OTHER -> "🔧"
241241
}
242242
}
243243

244-
private fun getPermissionIconColor(categoryName: String): Color {
245-
return when (categoryName) {
246-
"Nearby Devices" -> Color(0xFF2196F3) // Blue
247-
"Precise Location" -> Color(0xFFFF9800) // Orange
248-
"Notifications" -> Color(0xFF4CAF50) // Green
249-
else -> Color(0xFF9C27B0) // Purple
244+
private fun getPermissionIconColor(permissionType: PermissionType): Color {
245+
return when (permissionType) {
246+
PermissionType.NEARBY_DEVICES -> Color(0xFF2196F3) // Blue
247+
PermissionType.PRECISE_LOCATION -> Color(0xFFFF9800) // Orange
248+
PermissionType.NOTIFICATIONS -> Color(0xFF4CAF50) // Green
249+
PermissionType.OTHER -> Color(0xFF9C27B0) // Purple
250250
}
251251
}

app/src/main/java/com/bitchat/android/onboarding/PermissionManager.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class PermissionManager(private val context: Context) {
115115

116116
categories.add(
117117
PermissionCategory(
118-
name = "Nearby Devices",
118+
type = PermissionType.NEARBY_DEVICES,
119119
description = "Required to discover bitchat users via Bluetooth",
120120
permissions = bluetoothPermissions,
121121
isGranted = bluetoothPermissions.all { isPermissionGranted(it) },
@@ -131,7 +131,7 @@ class PermissionManager(private val context: Context) {
131131

132132
categories.add(
133133
PermissionCategory(
134-
name = "Precise Location",
134+
type = PermissionType.PRECISE_LOCATION,
135135
description = "Required by Android to discover nearby bitchat users via Bluetooth",
136136
permissions = locationPermissions,
137137
isGranted = locationPermissions.all { isPermissionGranted(it) },
@@ -143,7 +143,7 @@ class PermissionManager(private val context: Context) {
143143
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
144144
categories.add(
145145
PermissionCategory(
146-
name = "Notifications",
146+
type = PermissionType.NOTIFICATIONS,
147147
description = "Notifications to keep you updated",
148148
permissions = listOf(Manifest.permission.POST_NOTIFICATIONS),
149149
isGranted = isPermissionGranted(Manifest.permission.POST_NOTIFICATIONS),
@@ -167,7 +167,7 @@ class PermissionManager(private val context: Context) {
167167
appendLine()
168168

169169
getCategorizedPermissions().forEach { category ->
170-
appendLine("${category.name}: ${if (category.isGranted) "✅ GRANTED" else "❌ MISSING"}")
170+
appendLine("${category.type.nameValue}: ${if (category.isGranted) "✅ GRANTED" else "❌ MISSING"}")
171171
category.permissions.forEach { permission ->
172172
val granted = isPermissionGranted(permission)
173173
appendLine(" - ${permission.substringAfterLast(".")}: ${if (granted) "" else ""}")
@@ -197,9 +197,16 @@ class PermissionManager(private val context: Context) {
197197
* Data class representing a category of related permissions
198198
*/
199199
data class PermissionCategory(
200-
val name: String,
200+
val type: PermissionType,
201201
val description: String,
202202
val permissions: List<String>,
203203
val isGranted: Boolean,
204204
val systemDescription: String
205205
)
206+
207+
enum class PermissionType(val nameValue: String) {
208+
NEARBY_DEVICES("Nearby Devices"),
209+
PRECISE_LOCATION("Precise Location"),
210+
NOTIFICATIONS("Notifications"),
211+
OTHER("Other")
212+
}

0 commit comments

Comments
 (0)