/* * Copyright (C) 2014 pengjianbo(pengjianbosoft@gmail.com), Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.yalantis.ucrop.ui; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.yalantis.ucrop.R; import com.yalantis.ucrop.entity.LocalMedia; import java.util.ArrayList; import java.util.List; /** * author:luck * project:PictureSelector * package:com.luck.picture.adapter * email:893855882@qq.com * data:16/12/31 */ public class PicturePhotoGalleryAdapter extends RecyclerView.Adapter<PicturePhotoGalleryAdapter.ViewHolder> { private Context context; private List<LocalMedia> list = new ArrayList<>(); private LayoutInflater mInflater; public PicturePhotoGalleryAdapter(Context context, List<LocalMedia> list) { mInflater = LayoutInflater.from(context); this.context = context; this.list = list; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int position) { View view = mInflater.inflate(R.layout.picture_gf_adapter_edit_list, parent, false); return new ViewHolder(view); } @Override public void onBindViewHolder(ViewHolder holder, int position) { String path = ""; LocalMedia photoInfo = list.get(position); if (photoInfo != null) { path = photoInfo.getPath(); } if (photoInfo.isCut()) { holder.iv_dot.setVisibility(View.VISIBLE); holder.iv_dot.setImageResource(R.drawable.crop_oval_true); } else { holder.iv_dot.setVisibility(View.GONE); } Glide.with(context) .load(path) .placeholder(R.color.grey) .crossFade() .diskCacheStrategy(DiskCacheStrategy.ALL) .centerCrop() .into(holder.mIvPhoto); } @Override public int getItemCount() { return list.size(); } public static class ViewHolder extends RecyclerView.ViewHolder { ImageView mIvPhoto; ImageView iv_dot; public ViewHolder(View view) { super(view); mIvPhoto = (ImageView) view.findViewById(R.id.iv_photo); iv_dot = (ImageView) view.findViewById(R.id.iv_dot); } } }