Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add calendar permissions #208

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ internal fun Permission.toAndroidPermission(): String {
""

Permission.ReadContacts -> Manifest.permission.READ_CONTACTS
Permission.ReadCalendar -> Manifest.permission.READ_CALENDAR
Permission.WriteCalendar -> Manifest.permission.WRITE_CALENDAR
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,7 @@ enum class Permission {
BluetoothScan,
BluetoothConnect,
BluetoothAdvertise,
ReadContacts
ReadContacts,
ReadCalendar,
WriteCalendar
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope

/**
* Creates a [MultiplePermissionsState] that is remembered across compositions.
Expand All @@ -21,7 +23,25 @@ internal actual fun rememberMutableMultiplePermissionsState(
permissions: List<Permission>,
onPermissionsResult: (Map<Permission, Boolean>) -> Unit
): MultiplePermissionsState {
TODO()
val scope = rememberCoroutineScope()

val permissionStates =
remember(permissions) {
MutableMultiplePermissionsState(
mutablePermissions = permissions.map {
MutablePermissionStateImpl(
permission = it,
onPermissionResult = { isOk ->
onPermissionsResult(mapOf(it to isOk))
},
scope = scope,
)
}
)
}

return permissionStates

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mohamedrejeb.calf.permissions

import com.mohamedrejeb.calf.permissions.helper.AVCapturePermissionHelper
import com.mohamedrejeb.calf.permissions.helper.BluetoothPermissionHelper
import com.mohamedrejeb.calf.permissions.helper.CalendarPermissionHelper
import com.mohamedrejeb.calf.permissions.helper.ContactPermissionHelper
import com.mohamedrejeb.calf.permissions.helper.GalleryPermissionHelper
import com.mohamedrejeb.calf.permissions.helper.GrantedPermissionHelper
Expand All @@ -20,7 +21,7 @@ internal fun Permission.getPermissionDelegate(): PermissionHelper {
Permission.Gallery,
Permission.ReadImage,
Permission.ReadVideo,
->
->
GalleryPermissionHelper()

Permission.ReadStorage,
Expand Down Expand Up @@ -52,5 +53,7 @@ internal fun Permission.getPermissionDelegate(): PermissionHelper {
BluetoothPermissionHelper()

Permission.ReadContacts -> ContactPermissionHelper()
Permission.ReadCalendar -> CalendarPermissionHelper()
Permission.WriteCalendar -> CalendarPermissionHelper()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mohamedrejeb.calf.permissions.helper

import com.mohamedrejeb.calf.permissions.ExperimentalPermissionsApi
import com.mohamedrejeb.calf.permissions.PermissionStatus
import platform.EventKit.EKEventStore

internal class CalendarPermissionHelper : PermissionHelper {
override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) {
handlePermissionRequest(
onPermissionResult = onPermissionResult,
launchPermissionRequest = {
EKEventStore().requestFullAccessToEventsWithCompletion { isOk, error ->
if (isOk && error == null)
onPermissionResult(true)
else
onPermissionResult(false)
}
}
)
}

@ExperimentalPermissionsApi
override fun getPermissionStatus(onPermissionResult: (PermissionStatus) -> Unit) {
onPermissionResult(PermissionStatus.Granted)
}
}