https://kotlinlang.org logo
#feed
Title
d

Davide Giuseppe Farella

06/12/2019, 8:50 PM
#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
👍 1
m

Matej Drobnič

06/13/2019, 6:20 AM
Imo biggest drawaback here is
initRotationEnabledComponent
. I wish Kotlin would support
by RotatioEnabledDelegate(this)
d

Davide Giuseppe Farella

06/13/2019, 6:27 AM
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č

06/13/2019, 6:30 AM
Is the delegation really needed here? Wouldn't it be much simpler if
RotationEnabled
was just normal field in activity/fragment?
d

Davide Giuseppe Farella

06/13/2019, 6:32 AM
Well, it would be less noisy to have
by Delegate
than have a reference to call in every place
rotationDelegate.rotate( )
👍 1
m

Matej Drobnič

06/13/2019, 6:33 AM
true
t

Tuan Kiet

06/15/2019, 3:36 AM
@Davide Giuseppe Farella how about making
RotatioEnabledDelegate
become a
LifecyclerObserver
d

Davide Giuseppe Farella

06/15/2019, 5:55 AM
Yes, it could be an idea. There are many ways to improve it, just wanted to keep the example simple.
16 Views