Coder Social home page Coder Social logo

Comments (9)

iamareebjamal avatar iamareebjamal commented on September 7, 2024

First create a service layer, then use it in VM

from open-event-attendee-android.

nikit19 avatar nikit19 commented on September 7, 2024

I am a little confused. Can't we directly use it in VM?
I don't see many components that can be added to the VM from this class.
AFAIK we can only add components which do not depend on context,activity etc
So what I was thinking of doing was declaring the variables in the VM and accessing them from the fragment. Is there anything else that can be done ?

from open-event-attendee-android.

iamareebjamal avatar iamareebjamal commented on September 7, 2024

Yes, we need to create services and repository or else the same repetitive code like SharedPreferenceUtils,get(TOKEN) will just get transferred from Activities to ViewModels. In fact it won't be possible without services to create android free VMs

VMs are glue logic, they use Models, models should be the components to contain logic, not ViewModel. ViewModel should just bind models and views. This is by definition explanation of VMs

Look at Orga App code for example

from open-event-attendee-android.

iamareebjamal avatar iamareebjamal commented on September 7, 2024

Also, this is not true that you can only add logic which does not depend on Android in ViewModels, this entire notion is the reason there are half-baked MV* apps out there. You create components which encapsulate the logic separate from activities and use them in VMs

There needs to be no code in Activities other than view UI logic

from open-event-attendee-android.

simarsingh24 avatar simarsingh24 commented on September 7, 2024

@iamareebjamal I was also going to start working on Parent issue #21, just wanted to confirm that by Orga App you mean MVP architecture? they are using presenter classes
Please correct me if I am wrong 👍

from open-event-attendee-android.

iamareebjamal avatar iamareebjamal commented on September 7, 2024

I wanted to address the architecture beyond MVP and MVVM. What you use in presentation logic is irrelevant to the underlying architecture. It's just a pattern. Real abstraction and encapsulation happens in models which are common in both

MVP

authModel.login()
   .subscribe(result -> view.onResult(result)

MVVM

fun login() = authModel.login()

There's practically no difference. The real effort and elegance lies in creation of AuthModel. Your presenters and ViewModels should be clean as well or you'll just change God Acticities to God ViewModels. Follow SOLID and have only binding and glue logic in the ViewModels. The ViewModels should look like you're using an elegant library with nice API when querying the models, hence holding all logic in isolated components

from open-event-attendee-android.

iamareebjamal avatar iamareebjamal commented on September 7, 2024

Look at Orga App on how the underlying architecture has been implemented. You don't have to clone the architecture, make it even better and cleaner

from open-event-attendee-android.

nikit19 avatar nikit19 commented on September 7, 2024

@iamareebjamal seeing this article https://developer.android.com/jetpack/docs/guide
I think we have to add a repository layer along with the viewModel. Similar to how it is being done here ?

from open-event-attendee-android.

iamareebjamal avatar iamareebjamal commented on September 7, 2024

Yup. But no need to add Resource and other jargon. Just isolate the logic in it. Right now I'm working on structuring the project. Continue on this once I have pushed. Work on features and other issues for now

from open-event-attendee-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.