Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Convert your legacy (Android) app to Kotlin!

Lovis
September 29, 2017

Convert your legacy (Android) app to Kotlin!

From my talk at Code Talks 2017 (https://www.codetalks.de/)
Tips & Tricks for Java-To-Kotlin conversion (live coding)

Lovis

September 29, 2017
Tweet

More Decks by Lovis

Other Decks in Programming

Transcript

  1. Kotlin • Developed by JetBrains • Concise & Expressive •

    Pragmatic & Secure Lovis Möller @lovisbrot #codetalkshh
  2. Kotlin • Developed by JetBrains • Concise & Expressive •

    Pragmatic & Secure • 100% interoperable with Java Lovis Möller @lovisbrot #codetalkshh
  3. Kotlin • Developed by JetBrains • Concise & Expressive •

    Pragmatic & Secure • 100% interoperable with Java • Easy to learn for Java developers Lovis Möller @lovisbrot #codetalkshh
  4. Live Demo Lovis Möller @lovisbrot #codetalkshh Example App: Thesaurus •

    Enter a word • See synonym results • Display errors, if any https://github.com/lmller/codetalks2017
  5. Live Demo Lovis Möller @lovisbrot #codetalkshh 1. Java 2. Kotlin

    Dependencies 3. Model Classes 4. Api & Dependency Injection 5. Android Classes 6. Domain: ViewModels, Presenters,…
  6. More Tricks Lovis Möller @lovisbrot #codetalkshh Replace oldskool GoF patterns

    with Kotlin Builder  apply function (or named constructor args) Decorator  Extension functions / function composition Interpreter  sealed classes Iterator  operator functions get() and iterator() Observer  Observable delegate Prototype  data classes Singleton  object declaration Strategy  functions Template Method  (top level) functions Visitor  Pattern matching / when https://github.com/lmller/gof-in-kotlin
  7. More Tricks Lovis Möller @lovisbrot #codetalkshh Write your own extension

    functions fun ImageView.setImageUrl(url: String) { Picasso.with(context).load(url).into(this) } imageView.setImageUrl("http://...")
  8. More Tricks Lovis Möller @lovisbrot #codetalkshh Write your own extension

    functions fun View.fadeIn() = animate().alpha(1f).setDuration(300)
 fun View.fadeOut() = animate().alpha(0f).setDuration(300) imageView.fadeIn()
  9. More Tricks Lovis Möller @lovisbrot #codetalkshh Write your own extension

    properties val ViewParent.top
 get() = (this as View).top val patentTop = view.getParent().top
  10. But how? Lovis Möller @lovisbrot #codetalkshh Strategies • Whole file

    or snippet-based • Rewrite from scratch • Start with tests?
  11. But how? Lovis Möller @lovisbrot #codetalkshh Strategies • Whole file

    or snippet-based • Rewrite from scratch • Start with tests? • Not on Backlog • Whenever you touch a file, convert it • take the chance to improve the design!
  12. But how? Lovis Möller @lovisbrot #codetalkshh Strategies • Whole file

    or snippet-based • Rewrite from scratch • Start with tests? • Not on Backlog • Whenever you touch a file, convert it • take the chance to improve the design! • Don't go overboard
  13. But how? Lovis Möller @lovisbrot #codetalkshh Strategies • Whole file

    or snippet-based • Rewrite from scratch • Start with tests? • Not on Backlog • Whenever you touch a file, convert it • take the chance to improve the design! • Don't go overboard • Keep it simple