Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    #Kotlin #Android #delegation #Composition_over_Inheritance Just wrote this article on Medium, hoping it's appreciated 🙂 “Composition over inheritance on Activity and Fragment” by Davide Giuseppe Farella https://link.medium.com/lhOVEDU6sX
    m

    Matej Drobnič

    3 years ago
    Imo biggest drawaback here is
    initRotationEnabledComponent
    . I wish Kotlin would support
    by RotatioEnabledDelegate(this)
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    That's half true, because I'm my real case scenario I wanted to save the initial rotation in
    onStart
    , so going back to the previous activity I will have the right rotation, otherwise if I'm in portrait, go in background, go in landscape, back to my app and press back, I'll be sent back to my old portrait rotation. Even worst, in a
    Fragment
    you won't have access to the Activity when it's created, you will have lazily when
    onActivityCreated
    So this is more a platform limitation
    You could trick it getting the
    LifecycleOwner
    in a similar way:
    m

    Matej Drobnič

    3 years ago
    Is the delegation really needed here? Wouldn't it be much simpler if
    RotationEnabled
    was just normal field in activity/fragment?
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    Well, it would be less noisy to have
    by Delegate
    than have a reference to call in every place
    rotationDelegate.rotate( )
    m

    Matej Drobnič

    3 years ago
    true
    Tuan Kiet

    Tuan Kiet

    3 years ago
    @Davide Giuseppe Farella how about making
    RotatioEnabledDelegate
    become a
    LifecyclerObserver
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    Yes, it could be an idea. There are many ways to improve it, just wanted to keep the example simple.