i currently have this class:
import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.util.Log
/**
* Created by GHOST on 3/3/2018.
*/
class PermissionHandler {
var permission: String? = null
var activity: Activity? = null
var context: Context? = activity?.baseContext
var requestCode: Int? = 0
var permissionExplaination: String? = null
inline fun then(block: () -> Unit){
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(context!!,
permission ?: "")
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(activity!!,
permission ?: "")) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(activity!!,
arrayOf(permission),
requestCode!!)
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
// Permission has already been granted
block()
}
}
}
//and this function:
fun permissinaManager(block: PermissionHandler.() -> Unit) = block
//what m trying to do is:
permissinaManager {
activity = this@MainActivity
permission = Manifest.permission.SEND_SMS
requestCode = REQUESTCODE
then {
Log.d("my library", "it's working")
}
}
and when i do it, the compiler shows no error but the code inside permissionManager is not executed for some reason