File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
library/src/main/java/eu/inloop/viewmodel Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 88
99public abstract class AbstractViewModel <T extends IView > {
1010
11+ @ NonNull
12+ private String mUniqueIdentifier ;
13+
1114 @ Nullable
1215 private T mView ;
1316
17+ void setUniqueIdentifier (String uniqueIdentifier ) {
18+ mUniqueIdentifier = uniqueIdentifier ;
19+ }
20+
21+ /**
22+ *
23+ * @return An app unique identifier for the current viewmodel instance (will be kept during orientation
24+ * change). This identifier will be reset in case the corresponding activity is killed.
25+ */
26+ public String getUniqueIdentifier () {
27+ return mUniqueIdentifier ;
28+ }
29+
1430 public void initWithView (@ NonNull T view ) {
1531 mView = view ;
1632 }
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ public synchronized <T extends IView> ViewModelWrapper<T> getViewModel(@NonNull
4949
5050 try {
5151 instance = viewModelClass .newInstance ();
52+ instance .setUniqueIdentifier (key );
5253 mViewModelCache .put (key , instance );
5354 return new ViewModelWrapper <>(instance , true );
5455 } catch (InstantiationException | IllegalAccessException e ) {
You can’t perform that action at this time.
0 commit comments