You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-22Lines changed: 14 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,6 @@ An instance of a ViewModel class is assigned to your Fragment or Activity during
8
8
9
9
You can execute asynchronous tasks in this ViewModel instance and this class is not destroyed during orientation change. All data handling and state logic should be placed inside this class. The Fragment or Activity is just a "dumb" view.
10
10
11
-

12
11
13
12
How to implement
14
13
--------
@@ -78,36 +77,29 @@ Your Fragment argument Bundle and Activity intent Bundle is forwarded to the Vie
78
77
}
79
78
```
80
79
81
-
<b>How does it work?</b>
82
-
83
-
A unique global ID is generated for the first time your Fragment or Activity is shown. This ID is passed on during orientation changes. Opening another instance of the same Fragment or Activity will result in a different ID. The ID is unique screen identifier. A ViewModel class is created and bound to this ID. The corresponding ViewModel instance is attached to your Fragment or Activity after an orientation change or if you return to the fragment in the back stack.
84
-
The ViewModel is discarded once the Fragment/Activity is not reachable anymore (activity is finished or fragment permanently removed).
85
-
86
-
<b>Why no controller layer?</b>
80
+
Data binding support
81
+
--------
82
+
Data binding is supported - extend [ViewModelBaseBindingFragment.java](library/src/main/java/eu/inloop/viewmodel/binding/ViewModelBaseBindingFragment.java) instead of ViewModelBaseFragment and implement ```getViewModelBindingConfig()``` in your Fragment.
87
83
88
-
This is not a strict MVC/MVP architecture - simply because we felt that having another layer between the "model" and the view does not bring enough advantages. So to further reduce the code this was simplified, where the Model is talking to the View over an interface. In mobile application most of the code is about interaction with the UI (getting data from API/DB, showing the data, manipulating, saving) so a more direct connection between the layers felt appropriate.
That's it. You can then directly use ObservableField in your ViewModels. See [example](sample/src/main/java/eu/inloop/viewmodel/sample/viewmodel/SampleBindingViewModel.java).
91
92
92
-
1. <small>Fragment is shown to user. A ViewModel is assigned.</small>
93
-
2. Fragment notifies the View that it's ready.
94
-
3. ViewModel starts the async task to load data. Tells the view to show progress.
95
-
4. User rotates the display. The ViewModel continues with the loading part.
96
-
5. The Fragment is recreated after the orientation change is assigned the same ViewModel instance.
97
-
6. Recreated Fragment tells the ViewModel that it's ready. ViewModel tells the UI to show loading, because it's still loading the data.
98
-
7. ViewModel finishes the async task and tells the Fragment to show the data.
99
-
8. User leaves the Activity, the Fragment is destroyed and the ViewModel is removed.
A unique global ID is generated for the first time your Fragment or Activity is shown. This ID is passed on during orientation changes. Opening another instance of the same Fragment or Activity will result in a different ID. The ID is unique screen identifier. A ViewModel class is created and bound to this ID. The corresponding ViewModel instance is attached to your Fragment or Activity after an orientation change or if you return to the fragment in the back stack.
97
+
The ViewModel is discarded once the Fragment/Activity is not reachable anymore (activity is finished or fragment permanently removed).
102
98
103
99
104
100
Download
105
101
--------
106
102
107
-
Grab via Gradle:
108
103
```groovy
109
104
compile 'eu.inloop:androidviewmodel:1.0.1'
110
105
```
111
-
112
-
Build and study sample application from source code or download from Google Play.<br/>
0 commit comments