File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
library/src/main/java/eu/inloop/viewmodel Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -152,8 +152,18 @@ public void onStart() {
152152 }
153153
154154
155- @ Nullable
155+ /**
156+ * Returns the current ViewModel instance associated with the Fragment or Activity.
157+ * Throws an {@link IllegalStateException} in case the ViewModel is null. This can happen
158+ * if you call this method too soon - before {@link Activity#onCreate(Bundle)} or {@link Fragment#onCreate(Bundle)}
159+ * or this {@link ViewModelHelper} is not properly setup.
160+ * @return {@link R}
161+ */
162+ @ NonNull
156163 public R getViewModel () {
164+ if (null == mViewModel ) {
165+ throw new IllegalStateException ("ViewModel is not ready. Are you calling this method before Activity/Fragment onCreate?" ); //NON-NLS
166+ }
157167 return mViewModel ;
158168 }
159169
Original file line number Diff line number Diff line change @@ -53,8 +53,11 @@ public void onDestroy() {
5353 super .onDestroy ();
5454 }
5555
56+ /**
57+ * @see ViewModelHelper#getViewModel()
58+ */
5659 @ SuppressWarnings ("unused" )
57- @ Nullable
60+ @ NonNull
5861 public R getViewModel () {
5962 return mViewModeHelper .getViewModel ();
6063 }
Original file line number Diff line number Diff line change @@ -61,7 +61,10 @@ public void onDestroy() {
6161 super .onDestroy ();
6262 }
6363
64- @ Nullable
64+ /**
65+ * @see ViewModelHelper#getViewModel()
66+ */
67+ @ NonNull
6568 @ SuppressWarnings ("unused" )
6669 public R getViewModel () {
6770 return mViewModeHelper .getViewModel ();
You can’t perform that action at this time.
0 commit comments