Context (the Kotlin question comes at the end): I'...
# android
a
Context (the Kotlin question comes at the end): I'm building a basic finance tracking app. I have a dialog fragment that is used to enter a transaction for the account. I use a new instance method that takes in the account name and puts it in the bundle and life is good I can reference it in
onCreate()
. Now I want to expand this same dialog fragment to be used for adding or editing a transaction. In my head I see two options: a separate new instance method that takes in the transaction to be edited and I use some flag to determine the state of the dialog. Is there some way to use sealed classes for this, though? I could have like
sealed class TransactionState
with a class for add and edit, but it doesn't look like sealed classes can be parcelable, so idk if what I'm asking is feasible but would love for someone to put my mind at rest about it.
r
umm a sealed class is still a class so you could implement the parceable interface. it would be alot of boilerplate tho.. You could also just resort back to enums since they are serializble ,or even intDef
a
I've found the "sub" classes (idk what they're called?) can be parcelable but the sealed class itself can't be. Likely resorting back to the standard way to do it.
Actually, I just ended up doing my switch based on whether or not "existingTransaction" existing in the arguments bundle. Otherwise I went the other route.
d
Why not regular data classes with a
when
..? Each one is Parcelable, the only thing gained by sealed classes is exhaustability...
🤔 1
a
I didn't think about it that way... It's similar to what I already did but might look a little cleaner. Thanks for the suggestion.