mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 06:45:19 +00:00
Merge pull request #78 from prudhvir3ddy/prudhvir3ddy/safe-permission-category
Refactor: Update permission handling to use PermissionType enum
This commit is contained in:
@@ -183,14 +183,14 @@ private fun PermissionCategoryCard(
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = getPermissionEmoji(category.name),
|
||||
text = getPermissionEmoji(category.type),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = getPermissionIconColor(category.name),
|
||||
color = getPermissionIconColor(category.type),
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = category.name,
|
||||
text = category.type.nameValue,
|
||||
style = MaterialTheme.typography.titleSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = colorScheme.onSurface
|
||||
@@ -207,7 +207,7 @@ private fun PermissionCategoryCard(
|
||||
)
|
||||
)
|
||||
|
||||
if (category.name == "Precise Location") {
|
||||
if (category.type == PermissionType.PRECISE_LOCATION) {
|
||||
// Extra emphasis for location permission
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -232,20 +232,20 @@ private fun PermissionCategoryCard(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPermissionEmoji(categoryName: String): String {
|
||||
return when (categoryName) {
|
||||
"Nearby Devices" -> "📱"
|
||||
"Precise Location" -> "📍"
|
||||
"Notifications" -> "🔔"
|
||||
else -> "🔧"
|
||||
private fun getPermissionEmoji(permissionType: PermissionType): String {
|
||||
return when (permissionType) {
|
||||
PermissionType.NEARBY_DEVICES -> "📱"
|
||||
PermissionType.PRECISE_LOCATION -> "📍"
|
||||
PermissionType.NOTIFICATIONS -> "🔔"
|
||||
PermissionType.OTHER -> "🔧"
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPermissionIconColor(categoryName: String): Color {
|
||||
return when (categoryName) {
|
||||
"Nearby Devices" -> Color(0xFF2196F3) // Blue
|
||||
"Precise Location" -> Color(0xFFFF9800) // Orange
|
||||
"Notifications" -> Color(0xFF4CAF50) // Green
|
||||
else -> Color(0xFF9C27B0) // Purple
|
||||
private fun getPermissionIconColor(permissionType: PermissionType): Color {
|
||||
return when (permissionType) {
|
||||
PermissionType.NEARBY_DEVICES -> Color(0xFF2196F3) // Blue
|
||||
PermissionType.PRECISE_LOCATION -> Color(0xFFFF9800) // Orange
|
||||
PermissionType.NOTIFICATIONS -> Color(0xFF4CAF50) // Green
|
||||
PermissionType.OTHER -> Color(0xFF9C27B0) // Purple
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class PermissionManager(private val context: Context) {
|
||||
|
||||
categories.add(
|
||||
PermissionCategory(
|
||||
name = "Nearby Devices",
|
||||
type = PermissionType.NEARBY_DEVICES,
|
||||
description = "Required to discover bitchat users via Bluetooth",
|
||||
permissions = bluetoothPermissions,
|
||||
isGranted = bluetoothPermissions.all { isPermissionGranted(it) },
|
||||
@@ -131,7 +131,7 @@ class PermissionManager(private val context: Context) {
|
||||
|
||||
categories.add(
|
||||
PermissionCategory(
|
||||
name = "Precise Location",
|
||||
type = PermissionType.PRECISE_LOCATION,
|
||||
description = "Required by Android to discover nearby bitchat users via Bluetooth",
|
||||
permissions = locationPermissions,
|
||||
isGranted = locationPermissions.all { isPermissionGranted(it) },
|
||||
@@ -143,7 +143,7 @@ class PermissionManager(private val context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
categories.add(
|
||||
PermissionCategory(
|
||||
name = "Notifications",
|
||||
type = PermissionType.NOTIFICATIONS,
|
||||
description = "Notifications to keep you updated",
|
||||
permissions = listOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||
isGranted = isPermissionGranted(Manifest.permission.POST_NOTIFICATIONS),
|
||||
@@ -167,7 +167,7 @@ class PermissionManager(private val context: Context) {
|
||||
appendLine()
|
||||
|
||||
getCategorizedPermissions().forEach { category ->
|
||||
appendLine("${category.name}: ${if (category.isGranted) "✅ GRANTED" else "❌ MISSING"}")
|
||||
appendLine("${category.type.nameValue}: ${if (category.isGranted) "✅ GRANTED" else "❌ MISSING"}")
|
||||
category.permissions.forEach { permission ->
|
||||
val granted = isPermissionGranted(permission)
|
||||
appendLine(" - ${permission.substringAfterLast(".")}: ${if (granted) "✅" else "❌"}")
|
||||
@@ -197,9 +197,16 @@ class PermissionManager(private val context: Context) {
|
||||
* Data class representing a category of related permissions
|
||||
*/
|
||||
data class PermissionCategory(
|
||||
val name: String,
|
||||
val type: PermissionType,
|
||||
val description: String,
|
||||
val permissions: List<String>,
|
||||
val isGranted: Boolean,
|
||||
val systemDescription: String
|
||||
)
|
||||
|
||||
enum class PermissionType(val nameValue: String) {
|
||||
NEARBY_DEVICES("Nearby Devices"),
|
||||
PRECISE_LOCATION("Precise Location"),
|
||||
NOTIFICATIONS("Notifications"),
|
||||
OTHER("Other")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user