Skip to content

Commit

Permalink
fix model provider bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenceDut committed Jan 15, 2019
1 parent e5fdf23 commit 09f5176
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void setDatas(List<? extends BaseMutableData> datas) {

public void clear() {
mDatas.clear();
notifyDataSetChanged();
doNotifyUI();
}

public <T extends BaseMutableData> void addData(T data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.silencedut.diffadapter.DiffAdapter;
import com.silencedut.diffadapter.IProvideItemId;
import com.silencedut.diffadapter.data.BaseMutableData;
import com.silencedut.diffadapter.utils.ModelProvider;
import com.silencedut.diffadapter.utils.DiffModelProvider;

/**
*
Expand Down Expand Up @@ -73,9 +73,9 @@ public void updatePartWithPayload(T data, @NonNull Bundle payload, int position)
*/
public <V extends ViewModel> V getViewModel(Class<V> modelType){
if(mBaseAdapter.attachedFragment == null || mBaseAdapter.attachedFragment.isDetached()) {
return ModelProvider.getModel(mContext,modelType);
return DiffModelProvider.getModel(mContext,modelType);
}
return ModelProvider.getModel(getAttachedFragment(),modelType);
return DiffModelProvider.getModel(getAttachedFragment(),modelType);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @date 2018/9/6
*/

public class ModelProvider {
public class DiffModelProvider {

private static final String TAG = "ModelProvider";

Expand All @@ -34,7 +34,7 @@ public static <T extends ViewModel> T getModel(Fragment fragment , Class<T> view
throw new RuntimeException("getModel must call in mainThread");
}

return ModelProvider.getModel(fragment,viewModel);
return ViewModelProviders.of(fragment).get(viewModel);
}

/**
Expand Down

0 comments on commit 09f5176

Please sign in to comment.