Posts

Showing posts from April, 2020

MVVM Architecture, ViewModel, MutableLiveData and LiveData

Image
MVVM Architecture MVVM is one of the architectural patterns which enhances separation of concerns, it allows separating the user interface logic from the business (or the back-end) logic. Its target (with other MVC patterns goal) is to achieve the following principle “Keeping UI code simple and free of app logic in order to make it easier to manage”. MVVM has mainly the following layers: Model Model represents the data and business logic of the app. One of the recommended implementation strategies of this layer, is to expose its data through observables to be decoupled completely from ViewModel or any other observer/consumer. All the UI logic should be implemented in View Model. For example, when the data is fetching, a progress bar is shown, after the data is loaded, the progress bar is dismissed, and the UI is updated. The interaction of UI logic is done in View Model, because View Model is holding all the properties that binding to the View. All the view change

Navigation Component (Implementation in kotlin with real time example), fragmentfactory and dependency

Image
What's implemented? single Activity with Fragments navigation graph in XML handling of notifications (explicit deep links) custom handling of implicit deep links (more on that later) passing arguments between Fragments via Safe Args starting Fragments for result and waiting for that result (similar to Activity's startActivityForResult and onActivityResult) transitions between fragments with shared Toolbar a simple Toolbar navigation icon morphing ("<-" -> "X") base Dagger setup with a FragmentFactory used to create Fragments with non-default constructors To include Navigation support in your project, add the following dependencies to your app's build.gradle file: dependencies { def nav_version = "2.3.0-alpha05" // Java language implementation implementation "androidx.navigation:navigation-fragment:$nav_version" implementation "androidx.navigation:navigation-ui:$nav_version" // Kotlin imp

Rx Java

Image
Observable: Observable are the sources for data to emit. An observable start providing data once a subscriber or observer start listening. An Observable may emit n number of items. It will terminate with success or with an error. For example an object of User who emits User object with a new username, when the new username is set.