1

私は RecyclerView を使用しており、各位置で、recyclerview の row_layout の SimpleDraweeView に異なる画像リンクを提供しています。問題は、画像を適切にロードするときがあることです。ただし、場合によっては、同じ画像を行数でロードしますが、行ごとに異なる画像リンクを提供しています。

何が問題なのかわかりません。キャッシュの問題である可能性があります。解決方法を教えてください。これが私がFresco Libraryをどのように使用しているかです..

 Uri uri = Uri.parse(urlImage);
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setProgressiveRenderingEnabled(true)
            .build();

    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setUri(uri)
            .setImageRequest(request)
            .setOldController(holder.productImage.getController())
            .build();
    holder.productImage.setController(draweeController);

これはrecyclerviewアダプターコードです

public class AdapterProductRow extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

LayoutInflater inflater;
Context context;
List<DesignProductRow> list = Collections.emptyList();
Map<String, String> params = new HashMap<String, String>();

private VolleySingleton volleySingleton;
private RequestQueue requestQueue;

private boolean isFooterEnabled = true;
private final int VIEW_TYPE_ITEM = 1;
private final int VIEW_TYPE_PROGRESSBAR = 0;
int previousPosition = 0;
int initSize = 0;
int numberLike = 0;
boolean userAlreadyLiked = false;

public AdapterProductRow(Context context) {
    inflater = LayoutInflater.from(context);
    this.context = context;
    volleySingleton = VolleySingleton.getsInstance();
    requestQueue = volleySingleton.getRequestQueue();

}

public void setProductList(List<DesignProductRow> list) {
    this.list = list;
    notifyItemRangeChanged(initSize, list.size());
    initSize = list.size();
}



@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    if (viewType == VIEW_TYPE_ITEM) {

        View view = inflater.inflate(R.layout.custom_row_products, parent, false);
        RecyclerView.ViewHolder vh = new ViewHolderProductRow(view);
        return vh;

    } else {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.progress_bar_recyclerview, parent, false);

        RecyclerView.ViewHolder vh = new ProgressViewHolder(v);
        return vh;

    }

}

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

    if (holder instanceof ProgressViewHolder) {
        ((ProgressViewHolder) holder).progressBar.getIndeterminateDrawable().setColorFilter(
                context.getResources().getColor(R.color.colorPrimary),
                android.graphics.PorterDuff.Mode.SRC_IN);
        ((ProgressViewHolder) holder).progressBar.setIndeterminate(true);

    } else if (list.size() > 0 && position < list.size()) {

        final DesignProductRow design = list.get(position);
        ((ViewHolderProductRow) holder).productName.setText(design.getProductName());

        if (design.getProductPrice().equalsIgnoreCase("0")) {
            ((ViewHolderProductRow) holder).productPrice.setText("Rs. NA");
        } else {
            ((ViewHolderProductRow) holder).productPrice.setText("Rs. " + design.getProductPrice());
        }

        if (design.getProductLiked().equals("1") == true) {
            ((ViewHolderProductRow) holder).productLike.setButtonDrawable(R.drawable.ic_love_dark_red);
            // ((ViewHolderProductRow) holder).productLike.setChecked(true);
            userAlreadyLiked = true;
        } else {
            ((ViewHolderProductRow) holder).productLike.setButtonDrawable(R.drawable.ic_love_holo_blank);
            //((ViewHolderProductRow) holder).productLike.setChecked(false);
            userAlreadyLiked = false;
        }

        //Load product Image
        loadFrancoImage(design.getProductImage(), ((ViewHolderProductRow) holder));

        if (design.getProductLikeCount().equalsIgnoreCase("0") == true) {
            numberLike = Integer.parseInt(design.getProductLikeCount());
            ((ViewHolderProductRow) holder).layoutLike.setVisibility(View.INVISIBLE);
        } else {
            numberLike = Integer.parseInt(design.getProductLikeCount());
            ((ViewHolderProductRow) holder).layoutLike.setVisibility(View.VISIBLE);
            ((ViewHolderProductRow) holder).productLikeCount.setText(design.getProductLikeCount());
        }


        if (position > previousPosition) {
            AnimationUtils.animateProduct(((ViewHolderProductRow) holder), true);
        } else {
            AnimationUtils.animateProduct(((ViewHolderProductRow) holder), false);
        }
        previousPosition = position;

        ((ViewHolderProductRow) holder).productLike.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {


                SharedPreferences loginData = PreferenceManager.getDefaultSharedPreferences(context);
                String USER_ID = loginData.getString("user_id", "");

                if (isChecked == true && userAlreadyLiked == false) {
                    // perform logic

                    ((ViewHolderProductRow) holder).productLike.setButtonDrawable(R.drawable.ic_love_dark_red);
                    if (((ViewHolderProductRow) holder).layoutLike.getVisibility() == View.INVISIBLE) {
                        ((ViewHolderProductRow) holder).layoutLike.setVisibility(View.VISIBLE);
                    }

                    numberLike = numberLike + 1;
                    ((ViewHolderProductRow) holder).productLikeCount.setText(String.valueOf(numberLike));
                    //Toast.makeText(context,"Checked",Toast.LENGTH_SHORT).show();
                    userAlreadyLiked = true;

                    callServerToSetLike(design.getProductId(), USER_ID, "1");

                } else if (isChecked == false && userAlreadyLiked == true) {
                    //Toast.makeText(context,"Unchecked",Toast.LENGTH_SHORT).show();
                    ((ViewHolderProductRow) holder).productLike.setButtonDrawable(R.drawable.ic_love_holo_blank);
                    numberLike = numberLike - 1;
                    userAlreadyLiked = false;
                    if (numberLike == 0) {
                        ((ViewHolderProductRow) holder).layoutLike.setVisibility(View.INVISIBLE);
                    } else {
                        ((ViewHolderProductRow) holder).layoutLike.setVisibility(View.VISIBLE);
                        ((ViewHolderProductRow) holder).productLikeCount.setText(String.valueOf(numberLike));
                    }

                    callServerToSetLike(design.getProductId(), USER_ID, "0");
                }

            }
        });

       /* ((ViewHolderProductRow) holder).productImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openProductDetailIntent(position);
            }
        });

        ((ViewHolderProductRow) holder).bottomLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openProductDetailIntent(position);
            }
        });
        */


    }

}


public void loadFrancoImage(String urlImage, final ViewHolderProductRow holder) {

    Uri uri = Uri.parse(urlImage);
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setProgressiveRenderingEnabled(true)
            .build();

    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setUri(uri)
            .setImageRequest(request)
            .setOldController(holder.productImage.getController())
            .build();
    holder.productImage.setController(draweeController);

}

@Override
public int getItemViewType(int position) {
    return (isFooterEnabled && position >= list.size()) ? VIEW_TYPE_PROGRESSBAR : VIEW_TYPE_ITEM;

}

public void enableFooter(boolean isEnabled) {
    this.isFooterEnabled = isEnabled;
}

@Override
public int getItemCount() {
    return (isFooterEnabled) ? list.size() + 1 : list.size();
}

class ViewHolderProductRow extends RecyclerView.ViewHolder {
    private SimpleDraweeView productImage;
    private TextView productPrice;
    private TextView productName;
    private CheckBox productLike;
    private TextView productLikeCount;
    private RelativeLayout bottomLayout;
    private RelativeLayout layoutLike;


    public ViewHolderProductRow(View itemView) {
        super(itemView);

        productImage = (SimpleDraweeView) itemView.findViewById(R.id.productImage);
        productPrice = (TextView) itemView.findViewById(R.id.productPrice);
        productName = (TextView) itemView.findViewById(R.id.productName);
        productLike = (CheckBox) itemView.findViewById(R.id.ProductLiked);
        productLikeCount = (TextView) itemView.findViewById(R.id.productLikedNumber);
        bottomLayout = (RelativeLayout) itemView.findViewById(R.id.bottomLayout);
        layoutLike = (RelativeLayout) itemView.findViewById(R.id.layoutLike);


    }


}

static class ProgressViewHolder extends RecyclerView.ViewHolder {
    public ProgressBar progressBar;

    public ProgressViewHolder(View v) {
        super(v);
        progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
    }

}

public void callServerToSetLike(final String productId, final String UserId, final String checked) {

    StringRequest request = new StringRequest(Request.Method.POST,
            URL_PRODUCT_LIKE,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    //Get the server Response
                    // Toast.makeText(context,response.toString(),Toast.LENGTH_SHORT).show();
                }
            }
            , new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            params.put("user_id", UserId);
            params.put("product_id", productId);
            params.put("liked", checked);
            return params;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> pars = new HashMap<String, String>();
            pars.put("Content-Type", "application/x-www-form-urlencoded");
            return pars;
        }
    };

    requestQueue.add(request);


}
}
4

0 に答える 0