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

Kotlin migration permission #55

Merged
merged 4 commits into from
Dec 2, 2019

Conversation

igsosa92
Copy link
Contributor

@igsosa92 igsosa92 commented Oct 8, 2019

All test passed ok

image

@coveralls
Copy link

coveralls commented Oct 8, 2019

Coverage Status

Coverage increased (+0.03%) to 86.24% when pulling f4a9cde on kotlin-migration-permission into 2f4b145 on kotlin-migration.

Comment on lines 41 to 42
class PermissionManager @Inject
constructor(private val context: Context, private val requestListeners: SparseArray<PermissionListener>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put constructor word on the first line and the parameters on many lines.

class PermissionManager @Inject constructor(
         private val context: Context, 
         private val requestListeners: SparseArray<PermissionListener>
) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/** Filters a list of [permissions] and returns only the ones which have not been granted. */
private fun filterUngranted(vararg permissions: String): Array<String> {
val ungranted = ArrayList<String>()
permissions.filter { permission -> ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED }.forEach { ungranted.add(it) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate this on more lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 106 to 110
private fun filterUngranted(vararg permissions: String): Array<String> {
val ungranted = ArrayList<String>()
permissions.filter { permission -> ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED }.forEach { ungranted.add(it) }
return ungranted.toTypedArray()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .toTypedArray() after the filter instead of the foreach and the new list.

If you want: 👀

fun filterUngranted(vararg permissions: String) = permissions.filter { permission ->
        ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED
}.toTypedArray()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this

Comment on lines 117 to 120
private fun allGranted(results: IntArray): Boolean {
if (results.isEmpty()) return false
return results.all { it == PackageManager.PERMISSION_GRANTED }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should almost never check a boolean to return another boolean.

fun allGranted(results: IntArray) = results.isNotEmpty() && results.all { it == PackageManager.PERMISSION_GRANTED }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm loving the usage of the all ♥️)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :D

fun requestPermission(activity: Activity, listener: PermissionListener?, vararg permissions: String): Boolean {
val ungrantedPermissions = filterUngranted(*permissions)
if (ungrantedPermissions.isNotEmpty()) {
ActivityCompat.requestPermissions(activity, ungrantedPermissions, requestCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only line changed from the previous method is this. We should check how to save this code repetition.

*/
public void onPermissionsDenied(@NonNull String[] deniedPermissions) {}
/** Called when all or some of the [deniedPermissions] rejected by the user */
open fun onPermissionsDenied(deniedPermissions: Array<String>) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return an Array or a List? IMO, a List.

Copy link
Contributor Author

@igsosa92 igsosa92 Oct 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use a list, I have to change a lot of things, in particular in the tests of another classes. Is this OK?

@igsosa92 igsosa92 assigned dylan-muszel and unassigned igsosa92 Oct 25, 2019
Copy link
Contributor

@dylan-muszel dylan-muszel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dylan-muszel dylan-muszel removed their assignment Oct 28, 2019
Copy link

@Pavlo-Holota Pavlo-Holota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the use of Kotlin's dynamic code writing.
thumbs up ricardo

@igsosa92 igsosa92 merged commit 7afa098 into kotlin-migration Dec 2, 2019
@dylan-muszel dylan-muszel deleted the kotlin-migration-permission branch December 16, 2019 17:30
@dylan-muszel dylan-muszel mentioned this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants