Refactor: Update permission handling to use PermissionType enum

This commit is contained in:
prudhvir3ddy
2025-07-12 10:06:56 +05:30
parent bc2712eefd
commit a345d0a021
2 changed files with 28 additions and 21 deletions
@@ -115,7 +115,7 @@ class PermissionManager(private val context: Context) {
categories.add(
PermissionCategory(
name = "Nearby Devices",
type = PermissionType.NEARBY_DEVICES,
description = "Required to discover and connect to other 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 for Bluetooth scanning.",
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 = "Show notifications when you receive private messages while the app is in background",
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")
}