https://kotlinlang.org logo
#android
Title
# android
j

jackmiras

06/07/2017, 2:36 AM
@bachhuberdesign would you move the
isPermissionGranted(activity)
out of the presenter?
b

bachhuberdesign

06/07/2017, 2:43 AM
jackmiras: If I was writing it I would check permissions in the Activity/Fragment before calling requestCurrentLocation in presenter. But don't get too hung up on trying to keep your MVP "pure", if it works and makes the code easier to manage then go for it
I am sure a lot of people would disagree with me about not doing any permission handling in presenter. But in my experience, it doesn't make the code "cleaner" or easier to manage, just adds needless ping pong callbacks on top of the overridden Activity callback (onRequestPermissionsResult())
Anyways that's my take on it K have fun
j

jackmiras

06/07/2017, 2:51 AM
Ok, thanks 🙂
k

kingsley

06/07/2017, 5:04 PM
Something I've been doing these days:
Copy code
class RequestContinuation(private val proceed: () -> Unit, private val abort: (() -> Unit)?) {
    constructor(proceed: () -> Unit) : this(proceed, null)

    fun proceed() = proceed.invoke()
    fun abort() = abort?.invoke()
}
So, I can do this to properly structure code between presenter and view
Copy code
// In Presenter
val continuation = RequestContinuation {
    // request location updates
}
view.checkPermissions(continuation)

// In view
fun checkPermissions(continuation: RequestContinuation) {
  // Check permission and proceed as necessary
  checkOrRequestPermission()
    .onSuccess { continuation.proceed() }
Been really quite handy. Hope that helps 🙂