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

KotlinでAndroid開発を気持ちよくしよう

 KotlinでAndroid開発を気持ちよくしよう

Cybozu Meetup #10 モバイル で発表した内容
-------------------------------
Kotlin はまだ使っていませんか?使っているけれど Java と比べて何が良いかがはっきりしませんか?
実は Java で当たり前な面倒くさい事いっぱいあるけれど Kotlin では当たり前な便利な事がいっぱいあります!
日々の開発が楽になり、「もっと早く Kotlin の事を知っとけばよかった!」と皆様が思うように説明させて頂きます。
Kotlin で Android の開発を気持ちよくしましょう。

Benoît Quenaudon

January 30, 2018
Tweet

More Decks by Benoît Quenaudon

Other Decks in Programming

Transcript

  1. KotlinͰAndroid։ൃ
    Λؾ࣋ͪΑ͘͠Α͏
    Benoît Quenaudon @oldergod

    View full-size slide

  2. public final class Task {
    @NonNulla
    private final String id;
    @Nullableb
    private final String title;
    @Nullablec
    private final String description;
    private final boolean completed;
    public Task(@Nullable String title, @Nullable String description,
    @NonNull String id, boolean completed) {
    this.id = id;
    this.title = title;
    this.description = description;
    this.completed = completed;
    }a
    }l

    View full-size slide

  3. this.description = description;
    this.completed = completed;
    }a
    @NonNulld
    public String getId() {
    return id;
    }b
    @Nullablee
    public String getTitle() {
    return title;
    }c
    @Nullablef
    public String getTitleForList() {
    if (!Strings.isNullOrEmpty(title)) {
    return title;
    } else {
    return description;
    }z
    }d
    @Nullableg
    public String getDescription() {
    return description;
    }e
    public boolean isCompleted() {
    return completed;
    }f
    public boolean isActive() {
    return !completed;
    }g
    public boolean isEmpty() {
    return Strings.isNullOrEmpty(title) &&
    Strings.isNullOrEmpty(description);
    }h
    }l

    View full-size slide

  4. }e
    public boolean isCompleted() {
    return completed;
    }f
    public boolean isActive() {
    return !completed;
    }g
    public boolean isEmpty() {
    return Strings.isNullOrEmpty(title) &&
    Strings.isNullOrEmpty(description);
    }h
    @Overrideh
    public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Task task = (Task) o;
    return Objects.equal(id, task.id) &&
    Objects.equal(title, task.title) &&
    Objects.equal(description, task.description);
    }i
    @Overridei
    public int hashCode() {
    return Objects.hashCode(id, title, description);
    }j
    @Overridej
    public String toString() {
    return "Task with title " + title;
    }k
    }l

    View full-size slide

  5. public final class Task {
    @NonNulla
    private final String id;
    @Nullableb
    private final String title;
    @Nullablec
    private final String description;
    private final boolean completed;
    public Task(@Nullable String title, @Nullable String description,
    @NonNull String id, boolean completed) {
    this.id = id;
    this.title = title;
    this.description = description;
    this.completed = completed;
    }a
    @NonNulld
    public String getId() {
    return id;
    }b
    @Nullablee
    public String getTitle() {
    return title;
    }c
    @Nullablef
    public String getTitleForList() {
    if (!Strings.isNullOrEmpty(title)) {
    return title;
    } else {
    return description;
    }
    }d
    @Nullableg
    public String getDescription() {
    return description;
    }e
    public boolean isCompleted() {
    return completed;
    }f
    public boolean isActive() {
    return !completed;
    }g
    public boolean isEmpty() {
    return Strings.isNullOrEmpty(title) &&
    Strings.isNullOrEmpty(description);
    }h
    @Overrideh
    public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Task task = (Task) o;
    return Objects.equal(id, task.id) &&
    Objects.equal(title, task.title) &&
    Objects.equal(description, task.description);
    }i
    @Overridei
    public int hashCode() {
    return Objects.hashCode(id, title, description);
    }j
    @Overridej
    public String toString() {
    return "Task with title " + title;
    }k
    }l

    View full-size slide

  6. @Getter
    @AllArgsConstructor
    @EqualsAndHashCode
    @ToString
    public final class Task {
    @NonNull
    private final String id;
    @Nullable
    private final String title;
    @Nullable
    private final String description;
    private final boolean completed;
    @Nullable
    public String getTitleForList() {
    if (!Strings.isNullOrEmpty(title)) {
    return title;
    } else {
    return description;
    }
    }
    public boolean isActive() {
    return !completed;
    }
    public boolean isEmpty() {
    return Strings.isNullOrEmpty(title) &&
    Strings.isNullOrEmpty(description);
    }
    }
    Lombok

    View full-size slide

  7. @AutoValue
    public abstract class Task {
    @NonNull
    abstract String getId();
    @Nullable
    abstract String getTitle();
    @Nullable
    abstract String getDescription();
    abstract boolean isCompleted();
    public static Task create(@Nullable String title, @Nullable String description,
    @NonNull String id, boolean completed) {
    return new AutoValue_Task(id, title, description, completed);
    }
    public boolean isActive() {
    return !isCompleted();
    }
    @Nullable
    public String getTitleForList() {
    if (!Strings.isNullOrEmpty(getTitle())) {
    return getTitle();
    } else {
    return getDescription();
    }
    }
    public boolean isEmpty() {
    return Strings.isNullOrEmpty(getTitle()) &&
    Strings.isNullOrEmpty(getDescription());
    }
    }
    AutoValue

    View full-size slide

  8. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    val completed: Boolean
    ) {
    val titleForList =
    if (title.isNotNullNorEmpty()) {
    title
    } else {
    description
    }
    val active = !completed
    val empty = title.isNullOrEmpty() && description.isNullOrEmpty()
    }
    Kotlin

    View full-size slide

  9. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )

    View full-size slide

  10. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  11. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  12. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  13. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  14. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  15. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  16. data class Task(
    val id: String,
    val title: String?,
    val description: String?,
    var completed: Boolean
    )
    • constructor
    • getters
    • setters (var only)
    • toString
    • equals & hashCode
    • copy
    • componentN

    View full-size slide

  17. Sealed Class

    View full-size slide

  18. sealed class ViewHolder {
    data class HeaderViewHolder(val text: String) : ViewHolder()
    class ItemViewHolder(val data: String) : ViewHolder()
    object LoadingViewHolder : ViewHolder()
    }z

    View full-size slide

  19. sealed class ViewHolder {
    data class HeaderViewHolder(val text: String) : ViewHolder()
    class ItemViewHolder(val data: String) : ViewHolder()
    object LoadingViewHolder : ViewHolder()
    }z

    View full-size slide

  20. sealed class ViewHolder {
    data class HeaderViewHolder(val text: String) : ViewHolder()
    class ItemViewHolder(val data: String) : ViewHolder()
    object LoadingViewHolder : ViewHolder()
    }z

    View full-size slide

  21. sealed class ViewHolder {
    data class HeaderViewHolder(val text: String) : ViewHolder()
    class ItemViewHolder(val data: String) : ViewHolder()
    object LoadingViewHolder : ViewHolder()
    }z

    View full-size slide

  22. sealed class ViewHolder {
    data class HeaderViewHolder(val text: String) : ViewHolder()
    class ItemViewHolder(val data: String) : ViewHolder()
    object LoadingViewHolder : ViewHolder()
    }z

    View full-size slide

  23. sealed class ViewHolder(val root: View) : RecyclerView.ViewHolder(view) {
    class HeaderViewHolder(root: View) : ViewHolder(root)
    class ItemViewHolder(root: View) : ViewHolder(root)
    class LoadingViewHolder(root: View) : ViewHolder(root)
    }z

    View full-size slide

  24. sealed class ViewHolder(val root: View) : RecyclerView.ViewHolder(view) {
    class HeaderViewHolder(root: View) : ViewHolder(root)
    class ItemViewHolder(root: View) : ViewHolder(root)
    class LoadingViewHolder(root: View) : ViewHolder(root)
    }z

    View full-size slide

  25. sealed class ViewHolder(val root: View) : RecyclerView.ViewHolder(view) {
    class HeaderViewHolder(root: View) : ViewHolder(root)
    class ItemViewHolder(root: View) : ViewHolder(root)
    class LoadingViewHolder(root: View) : ViewHolder(root)
    }z

    View full-size slide

  26. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    }
    }

    View full-size slide

  27. sealed class ViewHolder(val root: View) : RecyclerView.ViewHolder(view) {
    class HeaderViewHolder(root: View) : ViewHolder(root)
    class ItemViewHolder(root: View) : ViewHolder(root)
    class LoadingViewHolder(root: View) : ViewHolder(root)
    }d

    View full-size slide

  28. sealed class ViewHolder(val root: View) : RecyclerView.ViewHolder(view) {
    class HeaderViewHolder(root: View) : ViewHolder(root)
    class ItemViewHolder(root: View) : ViewHolder(root)
    class LoadingViewHolder(root: View) : ViewHolder(root)
    class FooterViewHolder(root: View) : ViewHolder(root)
    }d

    View full-size slide

  29. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    }
    }

    View full-size slide

  30. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    }z
    }d

    View full-size slide

  31. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    is FooterViewHolder -> { /*****/ }f
    }z
    }d

    View full-size slide

  32. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    is FooterViewHolder -> { /*****/ }f
    }z
    }d

    View full-size slide

  33. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    is FooterViewHolder -> {
    val footerVH = holder as FooterViewHolder
    footerVH.stuff()
    }f
    }z
    }d

    View full-size slide

  34. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    is FooterViewHolder -> {
    holder.stuff()
    }f
    }z
    }d

    View full-size slide

  35. override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    return when (holder) {
    is HeaderViewHolder -> { /*****/ }
    is ItemViewHolder -> { /*****/ }
    is LoadingViewHolder -> { /*****/ }
    is FooterViewHolder -> { /*****/ }f
    }z
    }d

    View full-size slide

  36. Collections API

    View full-size slide

  37. List actions;
    List tasks = new ArrayList<>(actions.size());
    for (Action action : actions) {
    Task task = new Task(action.title(), action.description());
    tasks.add(task);
    }

    View full-size slide

  38. List actions;
    List tasks = new ArrayList<>(actions.size());
    for (Action action : actions) {
    Task task = new Task(action.title(), action.description());
    tasks.add(task);
    }

    View full-size slide

  39. List actions;
    List tasks = new ArrayList<>(actions.size());
    for (Action action : actions) {
    Task task = new Task(action.title(), action.description());
    tasks.add(task);
    }

    View full-size slide

  40. List actions;
    List tasks = new ArrayList<>(actions.size());
    for (Action action : actions) {
    Task task = new Task(action.title(), action.description());
    tasks.add(task);
    }

    View full-size slide

  41. List actions;
    List tasks = new ArrayList<>(actions.size());
    for (Action action : actions) {
    Task task = new Task(action.title(), action.description());
    tasks.add(task);
    }

    View full-size slide

  42. List actions;
    List tasks = new ArrayList<>(actions.size());
    for (Action action : actions) {
    Task task = new Task(action.title(), action.description());
    tasks.add(task);
    }

    View full-size slide

  43. valaactions:zList
    valbtasksz= ArrayList(actions.size)
    for (action in actions) {
    valctask = Task(action.title, action.description)
    tasks.add(task)
    }

    View full-size slide

  44. valaactions:zList
    valbtasksz= actions.map { Task(it.title, it.description) }

    View full-size slide

  45. • map()
    • filter()
    • find()
    • distinct()
    • any()
    • groupBy()
    • zip()
    • …

    View full-size slide

  46. • map()
    • filter()
    • find()
    • distinct()
    • any()
    • groupBy()
    • zip()
    • …
    val list: List =
    listOf(1, 2, 3)
    val map: Map =
    mapOf("a" to 1, "b" to 2)
    val set: Set =
    setOf("a", "b", “c")

    View full-size slide

  47. • map()
    • filter()
    • find()
    • distinct()
    • any()
    • groupBy()
    • zip()
    • …
    val list: List =
    listOf(1, 2, 3)
    val map: Map =
    mapOf("a" to 1, "b" to 2)
    val set: Set =
    setOf("a", "b", “c")

    View full-size slide

  48. Lazy Delegate

    View full-size slide

  49. private lateinit var viewModel: TaskViewModel
    private lateinit var taskId: String
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    viewModel = ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    taskId = arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }c

    View full-size slide

  50. private lateinit var viewModel: TaskViewModel
    private lateinit var taskId: String
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    viewModel = ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    taskId = arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }c

    View full-size slide

  51. private lateinit var viewModel: TaskViewModel
    private lateinit var taskId: String
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    viewModel = ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    taskId = arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }c

    View full-size slide

  52. private lateinit var viewModel: TaskViewModel
    private lateinit var taskId: String
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    viewModel = ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    taskId = arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }c

    View full-size slide

  53. private val viewModel: TaskViewModel by lazy {
    ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    }x
    private val taskId: String by lazy {
    arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }y
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    }c

    View full-size slide

  54. private val viewModel: TaskViewModel by lazy {
    ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    }x
    private val taskId: String by lazy {
    arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }y
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    }c

    View full-size slide

  55. private val viewModel: TaskViewModel by lazy {
    ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    }x
    private val taskId: String by lazy {
    arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }y
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    }c

    View full-size slide

  56. private val viewModel: TaskViewModel by lazy {
    ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    }x
    private val taskId: String by lazy {
    arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }y
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    }c

    View full-size slide

  57. private val viewModel: TaskViewModel by lazy {
    ViewModelProviders
    .of(this, ViewModelFactory())
    .get(TaskViewModel::class.java)
    }x
    private val taskId: String by lazy {
    arguments?.getString(ARGUMENT_EDIT_TASK_ID)
    }y
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    }

    View full-size slide

  58. class TaskDetailFragment(val taskId: String) : Fragment()

    View full-size slide

  59. class TaskDetailFragment(val taskId: String) : Fragment()
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  60. class TaskDetailFragment(val taskId: String) : Fragment()
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  61. class TaskDetailFragment(val taskId: String) : Fragment()
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  62. val fragment = TaskDetailFragment()

    View full-size slide

  63. val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)

    View full-size slide

  64. val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle

    View full-size slide

  65. class TaskDetailFragment : Fragment() {
    companion object {
    fun newInstance(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c

    View full-size slide

  66. class TaskDetailFragment : Fragment() {
    companion object {
    fun newInstance(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment.newInstance(taskId)

    View full-size slide

  67. class TaskDetailFragment : Fragment() {
    companion object {
    fun newInstance(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment.newInstance(taskId)

    View full-size slide

  68. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment.newInstance(taskId)

    View full-size slide

  69. class Foo() {
    operator fun invoke(): String {
    return "invoked !"
    }
    }
    fun main(args: Array) {
    val foo: Foo = Foo()
    println(foo()) // invoked !
    }

    View full-size slide

  70. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment.newInstance(taskId)

    View full-size slide

  71. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment.newInstance(taskId)

    View full-size slide

  72. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  73. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  74. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle()
    bundle.putString(ARGUMENT_TASK_ID, taskId)
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  75. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle().apply {
    this.putString(ARGUMENT_TASK_ID, taskId)
    }p
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  76. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    val bundle = Bundle().apply {
    putString(ARGUMENT_TASK_ID, taskId)
    }p
    fragment.arguments = bundle
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  77. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment()
    fragment.arguments = Bundle().apply {
    putString(ARGUMENT_TASK_ID, taskId)
    }p
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  78. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    val fragment = TaskDetailFragment().apply {
    arguments = Bundle().apply {
    putString(ARGUMENT_TASK_ID, taskId)
    }p
    }p
    return fragment
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  79. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String): TaskDetailFragment {
    return TaskDetailFragment().apply {
    arguments = Bundle().apply {
    putString(ARGUMENT_TASK_ID, taskId)
    }p
    }p
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  80. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String) =
    TaskDetailFragment().apply {
    arguments = Bundle().apply {
    putString(ARGUMENT_TASK_ID, taskId)
    }p
    }p
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  81. class TaskDetailFragment : Fragment() {
    companion object {
    operator fun invoke(taskId: String) =
    TaskDetailFragment().apply {
    arguments = Bundle().apply {
    putString(ARGUMENT_TASK_ID, taskId)
    }p
    }p
    }a
    }b
    }c
    val fragment = TaskDetailFragment(taskId)

    View full-size slide

  82. Fin
    Benoît Quenaudon @oldergod

    View full-size slide