Remove unnecessary expand list that causes crashes

This commit is contained in:
topjohnwu 2016-09-29 02:05:53 +08:00
parent bb7ff27d04
commit 35e3a479cd

View File

@ -9,6 +9,7 @@ import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -36,16 +37,11 @@ import butterknife.ButterKnife;
public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> { public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> {
private final List<Repo> mList; private final List<Repo> mList;
private List<Boolean> mExpandedList;
private View mView; private View mView;
private Context context; private Context context;
public ReposAdapter(List<Repo> list) { public ReposAdapter(List<Repo> list) {
mList = list; mList = list;
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
} }
@Override @Override
@ -59,10 +55,6 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
@Override @Override
public void onBindViewHolder(final ViewHolder holder, int position) { public void onBindViewHolder(final ViewHolder holder, int position) {
final Repo repo = mList.get(position); final Repo repo = mList.get(position);
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
if (repo.isCache()) { if (repo.isCache()) {
holder.title.setText("[Cache] " + repo.getName()); holder.title.setText("[Cache] " + repo.getName());
} else { } else {
@ -152,6 +144,8 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
private ObjectAnimator animY2; private ObjectAnimator animY2;
private ViewHolder holder; private ViewHolder holder;
private boolean expanded = false;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
@ -179,13 +173,12 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
}); });
mView.setOnClickListener(view -> { mView.setOnClickListener(view -> {
int position = getAdapterPosition(); if (expanded) {
if (mExpandedList.get(position)) {
collapse(holder.expandLayout); collapse(holder.expandLayout);
} else { } else {
expand(holder.expandLayout); expand(holder.expandLayout);
} }
mExpandedList.set(position, !mExpandedList.get(position)); expanded = !expanded;
}); });
} }