package kr.co.hanwha.hifive.util;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import kr.co.hanwha.hifive.util.glide.RoundedCornersTransformation;

/**
 * Created by sanghoonkwon on 2018. 1. 12..
 */

public class GlideUtil {
    private static GlideUtil ourInstance;

    public static GlideUtil getInstance() {
        if (ourInstance == null) {
            ourInstance = new GlideUtil();
        }
        return ourInstance;
    }

    private GlideUtil() {
    }

    public void loadImageCircle(Context context, int resourceId, ImageView imageView) {
        Glide.with(context)
                .load(resourceId)
                .apply(RequestOptions.circleCropTransform())
                .into(imageView);
    }

    public void loadImageCircle(Context context, String url, ImageView imageView) {
        if (TextUtils.isEmpty(url) == false) {
            Glide.with(context)
                    .load(url)
                    .apply(RequestOptions.circleCropTransform())
                    .into(imageView);
        } else Log.e("GlideUtil", "URL is empty");
    }

    public void loadImageRoundedCorners(Context context, int resourceId, ImageView imageView) {
//        Glide.with(context).load(resourceId).bitmapTransform(new RoundedCornersTransformation(context, 15, 5)).into(imageView);
        Glide.with(context)
                .load(resourceId)
                .apply(new RequestOptions().transform(new RoundedCornersTransformation(context, 15, 5)))
                .into(imageView);
    }

    public void loadImageRoundedCorners(Context context, String url, ImageView imageView) {
        if (TextUtils.isEmpty(url) == false) {
//            Glide.with(context).load(url).bitmapTransform(new RoundedCornersTransformation(context, 15, 5)).into(imageView);
            Glide.with(context)
                    .load(url)
                    .apply(new RequestOptions().transform(new RoundedCornersTransformation(context, 15, 5)))
                    .into(imageView);
        } else Log.e("GlideUtil", "URL is empty");
    }


}
