Skip to content

Commit feac6ce

Browse files
author
Daniel Novak
committed
More consistent naming convention (#13)
1 parent 8c2d676 commit feac6ce

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

library/src/main/java/eu/inloop/viewmodel/AbstractViewModel.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.annotation.Nullable;
88
import android.support.v4.app.Fragment;
99
import android.util.Log;
10+
import android.view.View;
1011

1112
public abstract class AbstractViewModel<T extends IView> {
1213

@@ -39,14 +40,19 @@ public String getUniqueIdentifier() {
3940
* {@link Activity#getIntent()}.{@link Intent#getExtras()}
4041
* @param savedInstanceState bundle with saved state, will be not null
4142
* only in case the system is killed due to low memory
42-
* and restored (and {@link #saveState(Bundle)} returned a non-null bundle.
43+
* and restored (and {@link #onSaveInstanceState(Bundle)} returned a non-null bundle.
4344
*/
4445
@SuppressWarnings("EmptyMethod")
4546
public void onCreate(@Nullable Bundle arguments, @Nullable Bundle savedInstanceState) {
4647

4748
}
4849

49-
public void bindView(@NonNull T view) {
50+
/**
51+
* This method is an equivalent of {@link Fragment#onViewCreated(View, Bundle)} or {@link Activity#onCreate(Bundle)}.
52+
* At this point, the View is ready and you can initialise it.
53+
* @param view
54+
*/
55+
public void onBindView(@NonNull T view) {
5056
mBindViewWasCalled = true;
5157
mView = view;
5258
}
@@ -61,7 +67,7 @@ public void clearView() {
6167
}
6268

6369
@SuppressWarnings("EmptyMethod")
64-
public void saveState(@NonNull final Bundle bundle) {
70+
public void onSaveInstanceState(@NonNull final Bundle bundle) {
6571

6672
}
6773

@@ -82,7 +88,7 @@ public void onStart() {
8288
* This is a good place to empty any planned tasks that are useless without a UI.
8389
*/
8490
@SuppressWarnings("EmptyMethod")
85-
public void onModelRemoved() {
91+
public void onDestroy() {
8692

8793
}
8894
}

library/src/main/java/eu/inloop/viewmodel/ViewModelHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void setView(@NonNull final T view) {
7171
//no viewmodel for this fragment
7272
return;
7373
}
74-
mViewModel.bindView(view);
74+
mViewModel.onBindView(view);
7575
}
7676

7777
/**
@@ -176,15 +176,15 @@ public R getViewModel() {
176176
public void onSaveInstanceState(@NonNull Bundle bundle) {
177177
bundle.putString("identifier", mScreenId);
178178
if (mViewModel != null) {
179-
mViewModel.saveState(bundle);
179+
mViewModel.onSaveInstanceState(bundle);
180180
mOnSaveInstanceCalled = true;
181181
}
182182
}
183183

184184
private void removeViewModel(@NonNull final Activity activity) {
185185
if (mViewModel != null && !mModelRemoved) {
186186
getViewModelProvider(activity).getViewModelProvider().remove(mScreenId);
187-
mViewModel.onModelRemoved();
187+
mViewModel.onDestroy();
188188
mModelRemoved = true;
189189
}
190190
}

sample/src/main/java/eu/inloop/viewmodel/sample/viewmodel/UserListViewModel.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void onCreate(@Nullable Bundle arguments, @Nullable Bundle savedInstanceS
3232
}
3333

3434
@Override
35-
public void bindView(@NonNull IUserListView view) {
36-
super.bindView(view);
35+
public void onBindView(@NonNull IUserListView view) {
36+
super.onBindView(view);
3737

3838
//downloading list of users
3939
if (mLoadedUsers != null) {
@@ -127,16 +127,16 @@ protected void onPostExecute(Void aVoid) {
127127

128128

129129
@Override
130-
public void saveState(@NonNull final Bundle bundle) {
131-
super.saveState(bundle);
130+
public void onSaveInstanceState(@NonNull final Bundle bundle) {
131+
super.onSaveInstanceState(bundle);
132132
if (mLoadedUsers != null) {
133133
bundle.putStringArrayList("userlist", new ArrayList<>(mLoadedUsers));
134134
}
135135
}
136136

137137
@Override
138-
public void onModelRemoved() {
139-
super.onModelRemoved();
138+
public void onDestroy() {
139+
super.onDestroy();
140140
//use this to cancel any planned requests
141141
}
142142
}

0 commit comments

Comments
 (0)