Skip to content

Commit

Permalink
1. fixbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
beiger committed Oct 14, 2018
1 parent 2bbb9cf commit fe97117
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
import androidx.recyclerview.widget.RecyclerView;

public abstract class BaseRecycleViewAdapter<T, VH extends BaseViewHolder> extends RecyclerView.Adapter<VH> {
private List<T> mData = new ArrayList<>();
protected List<T> mData = new ArrayList<>();
protected OnClickListener mListener;

public List<T> getData() {
return mData;
}

@NonNull
@Override
public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -116,6 +117,7 @@ protected void initRecycleView() {
mRecyclerView.setLayoutManager(getLayoutManager());
mRecyclerView.setItemAnimator(getItemAnimator());
initAdapter();
mRecyclerView.setAdapter(mAdapter);
}

protected abstract RecyclerView getRecyclerView();
Expand All @@ -125,8 +127,8 @@ protected RecyclerView.ItemAnimator getItemAnimator() {
return new DefaultItemAnimator();
}
protected abstract void initAdapter();
protected abstract LiveData<Status> getNetworkState();
protected abstract LiveData<Status> getRefreshState();
protected abstract MutableLiveData<Status> getNetworkState();
protected abstract MutableLiveData<Status> getRefreshState();
protected abstract LiveData<List<T>> getData();

protected abstract void handleArguments();
Expand Down Expand Up @@ -168,6 +170,9 @@ public void onChanged(@Nullable Status status) {
@Override
public void onChanged(List<T> list) {
mAdapter.setData(list);
if (list == null || list.size() == 0) {
getNetworkState().setValue(Status.NONE);
}
}
});
getRefreshState().observe(this, new Observer<Status>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public BaseViewHolder(DB binding) {
mBinding = binding;
}

public DB getBinding() {
return mBinding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import androidx.databinding.BindingAdapter;

public class BindingAdapters {
@BindingAdapter("bind:visibleGone")
@BindingAdapter("visibleGone")
public static void showHide(View view, boolean show) {
view.setVisibility(show ? View.VISIBLE : View.GONE);
}

@BindingAdapter("bind:img_url")
@BindingAdapter("img_url")
public static void showImg(ImageView iv, String url) {
GlideApp.with(iv.getContext()).load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
}
Expand Down

0 comments on commit fe97117

Please sign in to comment.