https://kotlinlang.org logo
#android
Title
# android
a

Alin B.

07/10/2018, 5:06 PM
Maybe a bit out of case, but I see mostly naming convention like
UserListFragment
,
UserDetailsFragment
,
UserListAdapter
,
UserListViewModel
. Now if I have all these open in Android studio I find it a lot harder to find which one is adapter, which is ModelView. Why not go with
FragmentUserList
,
AdapterUserList
,
ViewModelUserList
?
l

louiscad

07/10/2018, 5:19 PM
Then you open another ViewModel, another Adapter, another Fragment, and you have trouble finding which one is which…
a

Alin B.

07/10/2018, 5:22 PM
hmmm... now this is a good point
So I guess I'd better go with the way I see in projects, the NameFragment, NameAdapter and so on
Thank you for your input.
In java I used the package name pojo to store the data classes, for kotlin could it be poko?
l

louiscad

07/10/2018, 5:25 PM
You can also just search a class by typing the
PascalCase
initials like
PC
, or
PasC
to quickly find what you're looking for. I used to code without tabs at all and was quite fine with that.
What do you call the "package name pojo", and what do you call "to store the data classes"?
a

Alin B.

07/10/2018, 5:27 PM
I will try, thank you. I am figthing to do the switch to kotlin and I want to do things the right way. In my project structure there is a package mypackage.com.pojo where I store classes like class User, class Product and so on. POJO = Plain old java object
l

louiscad

07/10/2018, 5:30 PM
Oh, I usually call the subpackage
model
(as long as it's not part of a library, in which case I pick the package name more thoughtfully)
👍 1
a

Alin B.

07/10/2018, 5:31 PM
Thank you very much for you help and time!
I am trying to figure out kotlin, jetpack and MVVM
l

louiscad

07/10/2018, 5:32 PM
@Alin B. Maybe the sample of an Android Library I am migrating to AndroidX can help you: https://github.com/LouisCAD/Splitties/tree/androidx-refactor
a

Alin B.

07/10/2018, 5:34 PM
Wow, that looks like quite a project
l

louiscad

07/10/2018, 5:35 PM
Better understood in your IDE
a

Alin B.

07/10/2018, 5:35 PM
👍 1
l

louiscad

07/10/2018, 5:35 PM
This can serve as a playground projet where you try things
Android-Sunflower: Good starting point too 👌
a

Alin B.

07/10/2018, 5:37 PM
I did undertand how room works, room entities, the repository and ViewModel but I need to see how to properly continue with ViewModel->Fragment or activity and data binding according to MVVM pattern
I believe that I need data binding so the Fragment uses the ViewModel data but probably also get the events from fragment (like onClick) back to ViewModel to handle it there
l

louiscad

07/10/2018, 5:40 PM
You either use ViewModel data from a Fragment/Activity and edit the Views accordingly, or you can use databinding, or you can use a custom class that your Fragment/Activity instantiates
a

Alin B.

07/10/2018, 5:43 PM
I see that DataBinding is recommended as it avoids using findviewbyid and updating manually
I'll see how LiveData and Observable gets mixed in VIewModel... these are new concepts for me so I need to digest them very well
l

louiscad

07/10/2018, 5:44 PM
You can see in the project I linked there are other ways of avoiding
findViewById(…)
😉
a

Alin B.

07/10/2018, 5:49 PM
Are you using MVVM?
l

louiscad

07/10/2018, 6:01 PM
Sort of, when it makes sense. I avoid having too much logic in Activities, I use ViewModels, top level functions and #coroutines
a

Alin B.

07/10/2018, 6:19 PM
Thank you very much for all your help and links! Time to get to study.