package openfoodfacts.github.scrachx.openfood.views.adapters;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.squareup.picasso.Picasso;

import java.util.List;

import openfoodfacts.github.scrachx.openfood.R;

public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder> {
    private final List<Uri> mPhotos;

    public PhotosAdapter(List<Uri> mPhotos) {
        this.mPhotos = mPhotos;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ImageView photo = (ImageView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.dialog_photo_item, parent, false);
        return new PhotosAdapter.ViewHolder(photo);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ImageView imageView = holder.getImageView();

        Picasso.get()
               .load(mPhotos.get(position))
               .placeholder(R.drawable.placeholder_thumb)
               .error(R.drawable.error_image)
               .into(imageView);
    }

    @Override
    public int getItemCount() {
        return mPhotos.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        ImageView getImageView() {
            return (ImageView) itemView;
        }
    }
}

@@ -1,8 +1,610 @@
+/*%0A * Copyright 2016-2020 Open Food Facts%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 
@@ -890,24 +890,95 @@
 ecyclerView;
+%0Aimport androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
 %0A%0Aimport com
@@ -1027,16 +1027,42 @@
 il.List;
+%0Aimport java.util.Objects;
 %0A%0Aimport
@@ -1768,16 +1768,277 @@
 eView();
+%0A        VectorDrawableCompat drawableCompat = Objects.requireNonNull(%0A            VectorDrawableCompat.create(%0A                holder.getImageView().getResources(),%0A                R.drawable.ic_product_silhouette,%0A                null%0A            )%0A        );
 %0A%0A      
@@ -2053,19 +2053,16 @@
 o.get()%0A
-   
         
@@ -2106,19 +2106,16 @@
         
-   
 .placeho
@@ -2119,26 +2119,24 @@
 eholder(
-R.
 drawable
 .placeho
@@ -2131,31 +2131,16 @@
 able
-.placeholder_thumb)%0A   
+Compat)%0A
     
@@ -2178,19 +2178,16 @@
 _image)%0A
-   
         
@@ -2361,17 +2361,16 @@
 older %7B%0A
-%0A
         

use product silhouette in image loading