Created
September 16, 2017 11:30
-
-
Save ryugoo/cf8d4057973eac940c7713e054c02c35 to your computer and use it in GitHub Desktop.
Permissions Dispatcher 3.0.0 / Android Studio 3.0.0 beta-6 / Kotlin 1.1.4-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (21, 12): Expecting an expression | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (21, 12): Expecting ')' | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (21, 14): Unexpected tokens (use ';' to separate expressions on the same line) | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (23, 64): Expecting an expression | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (23, 64): Expecting ')' | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (23, 66): Unexpected tokens (use ';' to separate expressions on the same line) | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (36, 26): Expecting '->' | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (56, 19): Expecting an expression | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (56, 19): Expecting ')' | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (56, 21): Unexpected tokens (use ';' to separate expressions on the same line) | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (17, 1): Property must be initialized | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (23, 5): Val cannot be reassigned | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (36, 5): Val cannot be reassigned | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (36, 5): Assignments are not expressions, and only expressions are allowed in this context | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (36, 22): Null can not be a value of a non-null type GrantableRequest | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/build/generated/source/kapt/debug/com/r384ta/android/pd3test/MainActivityPermissionsDispatcher.kt: (44, 3): Property must be initialized or be abstract | |
e: /Users/ryugoo/Workspace/GitHub/Personal/PD3Test/app/src/main/java/com/r384ta/android/pd3test/MainActivity.kt: (18, 63): Type mismatch: inferred type is kotlin.String but java.lang.String was expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.r384ta.android.pd3test | |
import android.Manifest | |
import android.os.Bundle | |
import android.support.v7.app.AppCompatActivity | |
import android.widget.Button | |
import android.widget.Toast | |
import permissions.dispatcher.NeedsPermission | |
import permissions.dispatcher.RuntimePermissions | |
@RuntimePermissions | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val button: Button = findViewById(R.id.main_button) | |
button.setOnClickListener { sampleWithPermissionCheck("Test") } | |
} | |
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, | |
grantResults: IntArray) { | |
super.onRequestPermissionsResult(requestCode, permissions, grantResults) | |
onRequestPermissionsResult(requestCode, grantResults) | |
} | |
@NeedsPermission(Manifest.permission.CAMERA) | |
fun sample(message: String) { | |
runOnUiThread { Toast.makeText(applicationContext, message, Toast.LENGTH_SHORT).show() } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file was generated by PermissionsDispatcher. Do not modify! | |
package com.r384ta.android.pd3test | |
import android.support.v4.app.ActivityCompat | |
import java.lang.ref.WeakReference | |
import kotlin.Array | |
import kotlin.Int | |
import kotlin.IntArray | |
import kotlin.String | |
import permissions.dispatcher.GrantableRequest | |
import permissions.dispatcher.PermissionUtils | |
private val REQUEST_SAMPLE: Int = 0 | |
private val PERMISSION_SAMPLE: Array<String> = arrayOf("android.permission.CAMERA") | |
private val PENDING_SAMPLE: GrantableRequest | |
fun MainActivity.sampleWithPermissionCheck(message: java.lang.String) { | |
if (PermissionUtils.hasSelfPermissions(this, *PERMISSION_SAMPLE)) { | |
sample($L) | |
} else { | |
PENDING_SAMPLE = MainActivitySamplePermissionRequest(this, $L) | |
ActivityCompat.requestPermissions(this, PERMISSION_SAMPLE, REQUEST_SAMPLE) | |
} | |
} | |
fun MainActivity.onRequestPermissionsResult(requestCode: Int, grantResults: IntArray) { | |
when (requestCode) { | |
REQUEST_SAMPLE -> | |
if (PermissionUtils.verifyPermissions(*grantResults)) { | |
if (PENDING_SAMPLE != null) { | |
PENDING_SAMPLE.grant() | |
} | |
} | |
PENDING_SAMPLE = null | |
} | |
} | |
private class MainActivitySamplePermissionRequest(target: MainActivity, | |
message: java.lang.String) : GrantableRequest { | |
private val weakTarget: WeakReference<MainActivity> = WeakReference(target) | |
private val message: java.lang.String | |
override fun proceed() { | |
val target = weakTarget.get() ?: return | |
ActivityCompat.requestPermissions(target, PERMISSION_SAMPLE, REQUEST_SAMPLE) | |
} | |
override fun cancel() { | |
} | |
override fun grant() { | |
val target = weakTarget.get() ?: return | |
target.sample($L) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment