Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PermissionsDispatcher × Kotlin
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
@hotchemi
July 18, 2017
Programming
3.4k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PermissionsDispatcher × Kotlin
CA.kt #2
@hotchemi
July 18, 2017
More Decks by @hotchemi
See All by @hotchemi
kompile-testing internal
hotchemi
0
290
The things we’ve learned from iOS×React Native hybrid development
hotchemi
2
5.5k
React Nativeを活用したアプリ開発体制/sapuri meetup
hotchemi
3
8.3k
Type-Safe i18n on RN
hotchemi
2
1.2k
Navigation in a hybrid app
hotchemi
3
1.4k
kotlin compiler plugin
hotchemi
1
820
Rx and Preferences
hotchemi
2
180
Introducing PermissionsDispatcher
hotchemi
1
190
khronos
hotchemi
4
2k
Other Decks in Programming
See All in Programming
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
140
霧の中の代数的エフェクト
funnyycat
1
490
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
150
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
490
数百円から始めるRuby電子工作
tarosay
0
140
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
450
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
300
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
490
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
590
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
4.1k
Foundation Models frameworkで画像分析
ryodeveloper
1
600
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
590
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
360
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
210
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
420
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
790
Done Done
chrislema
186
16k
So, you think you're a good person
axbom
PRO
2
2.1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
240
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Transcript
PermissionsDispatcher ✖ Kotlin
• PermissionsDispatcher • Generate Runtime Permissions code • 100% reflection-free
• Special permissions support • Xiaomi support • committer: @shiraji, @aurae
• 3.0.0(beta) • fully Kotlin support • Why? • to
support inline modifier • to make API Kotlin-ish • Now it’s official
repositories { jcenter() maven { url ‘http://oss.jfrog.org/artifactory/oss-snapshot-local/' } } dependencies
{ compile(“com.github.hotchemi:permissionsdispatcher:3.0.0-SNAPSHOT”) { exclude module: "support-v13" } kapt "com.github.hotchemi:permissionsdispatcher-processor:3.0.0-SNAPSHOT" }
@RuntimePermissions class MainActivity extends AppCompatActivity Java
@NeedsPermission(Manifest.permission.CAMERA) void showCamera(); MainActivityPermissionsDispatcher.showCameraWithCheck(this); Java
@RuntimePermissions(kotlin = true) class MainActivity : AppCompatActivity() Kotlin
@NeedsPermission(Manifest.permission.CAMERA) inline fun showCamera() showCameraWithCheck() Kotlin
private val REQUEST_SHOWCAMERA: Int = 0 private val PERMISSION_SHOWCAMERA: Array<String>
= arrayOf("android.permission.CAMERA") fun MainActivity.showCameraWithCheck() { if (PermissionUtils.hasSelfPermissions(this, PERMISSION_SHOWCAMERA)) { showCamera() } else { if (PermissionUtils.shouldShowRequestPermissionRationale(this, PERMISSION_SHOWCAMERA)) { showRationaleForCamera(ShowCameraPermissionRequest(this)) } else { ActivityCompat.requestPermissions(this, PERMISSION_SHOWCAMERA, REQUEST_SHOWCAMERA) } } } fun MainActivity.onRequestPermissionsResult(requestCode: Int, grantResults: IntArray): Unit { when (requestCode) { REQUEST_SHOWCAMERA -> if (PermissionUtils.verifyPermissions(*grantResults)) { showCamera() } else { if (!PermissionUtils.shouldShowRequestPermissionRationale(this, PERMISSION_SHOWCAMERA)) { onCameraNeverAskAgain() } else { onCameraDenied() } } } } private class ShowCameraPermissionRequest(target: MainActivity) : PermissionRequest { private val weakTarget: WeakReference<MainActivity> = WeakReference(target) override fun proceed() { val target = weakTarget.get() ?: return ActivityCompat.requestPermissions(target, PERMISSION_SHOWCAMERA, REQUEST_SHOWCAMERA) } override fun cancel() { val target = weakTarget.get() ?: return target.onCameraDenied() } }
• Under the hood • generate .kt file at compile
time • KotlinPoet • kapt3 • Testing
• KotlinPoet • Kotlin version of JavaPoet • DSL for
generating source files • latest ver: 0.3.0 • early-access release • KDoc is not updated • writeTo(filer: Filer) is not supported
class Greeter(val name: String) { fun greet() { println("Hello, $name")
} } fun main(vararg args: String) { Greeter(args[0]).greet() }
val greeterClass = ClassName("", "Greeter") val kotlinFile = KotlinFile.builder("", "HelloWorld")
.addType(TypeSpec.classBuilder("Greeter") .primaryConstructor(FunSpec.constructorBuilder() .addParameter("name", String::class) .build()) .addProperty(PropertySpec.builder("name", String::class) .initializer("name") .build()) .addFun(FunSpec.builder("greet") .addStatement("println(%S)", "Hello, \$name") .build()) .build()) .addFun(FunSpec.builder("main") .addParameter("args", String::class, VARARG) .addStatement("%T(args[0]).greet()", greeterClass) .build()) .build() kotlinFile.writeTo(System.out)
if (isKotlin) { val kaptGeneratedDirPath = processingEnv.options[KAPT_KOTLIN_GENERATED_OPTION_NAME]?.replace("kaptKotlin", "kap processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "Can't
find the target directory for generated Kot return false } val kaptGeneratedDir = File(kaptGeneratedDirPath) if (!kaptGeneratedDir.parentFile.exists()) { kaptGeneratedDir.parentFile.mkdirs() } val processorUnits = listOf(ActivityKtProcessorUnit(), SupportFragmentKtProcessorUnit(), NativeFragmentKtProces val processorUnit = findAndValidateKtProcessorUnit(processorUnits, it) val kotlinFile = processorUnit.createKotlinFile(rpe, requestCodeProvider) kotlinFile.writeTo(kaptGeneratedDir) } else { val processorUnits = listOf(ActivityProcessorUnit(), SupportFragmentProcessorUnit(), NativeFragmentProcessorUni val processorUnit = findAndValidateProcessorUnit(processorUnits, it) val javaFile = processorUnit.createJavaFile(rpe, requestCodeProvider) javaFile.writeTo(filer) }
• kapt3 • supports .kt file generation • kt generated/source/kaptKotlin/$sourceSet
• java generated/source/kapt/$sourceSet • apt generated/source/apt/$sourceSet • processingEnv. options[“kapt.kotlin.generated”]
• kapt3 • But… • kaptKotlin dir was not recognized
correctly with Android project… • worked well only on java project • filed a bug report • youtrack.jetbrains.com/issue/KT-19097
• Testing • we can’t use google/compile-testing • write tests
for behavior, not code itself • with PowerMockito, Robolectric • check test, test-v13 projects • read Testing Against Annotation Processing • by @shiraji san
• What learned • Supporting Java/Kotlin is tough work than
we expected • class delegation is a way to go? • Anyway it was fun:D
• Misc • 3.0.0 would be officially released soon! •
Hopefully end of July • Give us feedback!
Thank you