Skip to content

Commit

Permalink
Add setModelView() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Novak committed May 18, 2015
1 parent 65396a0 commit 54a7d1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onCreate(@Nullable Bundle savedInstanceState,
* or {@link android.app.Activity#onCreate(android.os.Bundle)}
* @param view
*/
public void initWithView(@NonNull T view) {
public void setView(@NonNull T view) {
if (mViewModel == null) {
//no viewmodel for this fragment
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.inloop.viewmodel.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;

import eu.inloop.viewmodel.AbstractViewModel;
Expand All @@ -15,8 +16,14 @@ public abstract class ViewModelBaseActivity<T extends IView, R extends AbstractV
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mViewModeHelper.onCreate(savedInstanceState, getViewModelClass(), getIntent().getExtras());
//noinspection unchecked
mViewModeHelper.initWithView((T) this);
}

/**
* Call this after your view is ready - usually on the end of {@link android.app.Activity#onCreate(Bundle)}
* @param view
*/
public void setModelView(@NonNull T view) {
mViewModeHelper.setView(view);
}

public abstract Class<R> getViewModelClass();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.inloop.viewmodel.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
Expand All @@ -21,11 +22,12 @@ public void onCreate(Bundle savedInstanceState) {

public abstract Class<R> getViewModelClass();

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//noinspection unchecked
mViewModeHelper.initWithView((T) this);
/**
* Call this after your view is ready - usually on the end of {@link Fragment#onViewCreated(View, Bundle)}
* @param view
*/
protected void setModelView(@NonNull T view) {
mViewModeHelper.setView(view);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
return inflater.inflate(R.layout.fragment_empty, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setModelView(this);
}

@Override
public Class<SampleArgumentViewModel> getViewModelClass() {
return SampleArgumentViewModel.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
getViewModel().deleteUser(i - mListview.getHeaderViewsCount());
}
});
setModelView(this);
}

@Override
Expand Down

0 comments on commit 54a7d1a

Please sign in to comment.