TUM-Dev / Campus-Android

Development of the TUM Campus App for Android devices - for and from students at Technical University of Munich.
https://app.tum.de
GNU General Public License v3.0
208 stars 86 forks source link

Use Googles Room Persistency Library #560

Closed pfent closed 6 years ago

pfent commented 6 years ago

We currently don't have an ORM, but write all SQL queries / mappings by hand.

Google recently released the Android Architecture Components with the Room Persistency Library. We should probably use this, which should significantly reduce the complexity of our various "Managers"

kordianbruck commented 6 years ago

@pfent allowMainThreadQueries() :+1:

kordianbruck commented 6 years ago

Overview: https://speakerdeck.com/hugovisser/room-the-blessed-object-mapper-devfest-bayern

pfent commented 6 years ago

Migrate Managers to use entities and DAOs:

Misc:

OliHalu-zz commented 6 years ago

@anselm92 @psukys I allready work on ChatMessageManager, ChatRoomsManager

anselm92 commented 6 years ago

@pfent @kordianbruck Regarding the strategy to replace main thread queries, i'd suggest using rxandroid (or rxjava in case of persistence api), I've used it many times before and love it :)

See: https://medium.com/google-developers/room-rxjava-acb0cd4f3757

Advantages:

I'll implement it for one dao, to show how to use it.

kordianbruck commented 6 years ago

@anselm92 what are the benefits over using livedata?

anselm92 commented 6 years ago

Basically:

Are we going to need it? Idk, i thinks it's more a matter of taste

See: https://stackoverflow.com/questions/46312937/when-to-use-rxjava-in-android-and-when-to-use-livedata-from-android-architectura http://akarnokd.blogspot.de/2017/10/android-livedata-api-quick-look.html http://hannesdorfmann.com/android/arch-components-purist

pfent commented 6 years ago

I'd say go for it.

Rxjava would probably also be great for a lot of the Networking stuff, where we currently use AsyncTasks

Building a common rxjava usage pattern for database and network access will award you all the kudos :)

anselm92 commented 6 years ago

Alright, I've refactored the first manager (CafeteriaManager) into a viemodel approach with rxjava. (It already works, but it's still more a draft.)

Please have a look and tell me what you think about it:

https://github.com/TCA-Team/TumCampusApp/commit/c24e3996369947d7312ef38c73721ffdd691646b

psukys commented 6 years ago

I like the rxjava approach. I'mma converting NewsManager at the moment.

psukys commented 6 years ago

I haven't added rxjava (even tho PR is still big), will move into DAOizing Calendar manager as NewsManager is ready for review

kordianbruck commented 6 years ago

@TCA-Team/android three left to go :tada:

psukys commented 6 years ago

@OliHalu I take the SurveyManager then