fondesa/kpermissions

⚡ Simplify 'permissionsBuilder()' ext fun by merging the params into a single 'vararg' param

RahulSDeshpande opened this issue · 6 comments

Description

Simplify permissionsBuilder() extension function by merging both the params into one.
In short, add and extra remove firstPermission: String & only keep a single param as vararg permissions: String.

Motivation

I am using 3.4.0 version of this library.
This feature would be very useful, as the developer will have to only pass the param as vararg in array format (or even a list).

Example

Currently we have to do it like this:

val permissionRequest = 
    permissionsBuilder(
        Manifest.permission.CAMERA,
        Manifest.permission.READ_SMS
    ).build()

We cannot do this:

val permissions =
    arrayOf(
        Manifest.permission.CAMERA,
        Manifest.permission.READ_SMS
    )
val permissionRequest = permissionsBuilder(permissions).build()

This is what I am suggesting as a part of this feature request.

I really loved how you did for this ext function in CheckPermissionsStatus.kt:

internal fun Activity.checkRuntimePermissionsStatus(permissions: List<String>): List<PermissionStatus> =
    permissions.map { permission ->
        if (isPermissionGranted(permission)) {
            return@map PermissionStatus.Granted(permission)
        }
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
            PermissionStatus.Denied.ShouldShowRationale(permission)
        } else {
            PermissionStatus.RequestRequired(permission)
        }
    }

I know you have a pretty good architecture setup for this.
This would impact many places, primarily at:

  • PermissionRequestBuilder
  • BasePermissionRequestBuilder
  • checkPermissionsStatus()

So, my suggestion is also applicable exactly for the checkPermissionsStatus() ext fun.

Please let me know. ✋🏼


❤️ Amazing library btw.
❤️ I would really love to contribute, please let me know.

I've been busy sorry, so I'm pretty late in answering this.

add and extra remove firstPermission: String

This was done primarly to avoid to pass an empty vararg.

We cannot do this:

Your suggestion makes sense, to avoid to make breaking changes though, I'm adding the possibility to pass a List, still supporting the vararg functions which are already there.

Hence, to make an example, there will be these two functions:

fun Type.permissionsBuilder(firstPermission: String, vararg others: String)
fun Type.permissionsBuilder(permissions: List<String>)

Thanks for the suggestion!

PR to implement this: #393

The next release will contain this, thanks again for the suggestion.

This looks perfect!!

Welcome & thanks. ❤️💯🚀🚀

@fondesa
Buddy, any plans to releasing the latest lib builds including this change??

So much sorry @RahulSDeshpande, I didn't used much Github lately. I released the version 3.5.0 with this new API!

Thanks @fondesa bro!! ❤️