package com.hanwha.morakmorak.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


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

class GlideUtil private constructor() {

    fun loadImageCircle(context: Context, resourceId: Int, imageView: ImageView) {
        Glide.with(context)
                .load(resourceId)
                .apply(RequestOptions.circleCropTransform())
                .into(imageView)
    }

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

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

//    fun loadImageRoundedCorners(context: Context, url: String, 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(RequestOptions().transform(RoundedCornersTransformation(context, 15, 5)))
//                    .into(imageView)
//        } else
//            Log.e("GlideUtil", "URL is empty")
//    }

    companion object {
        private var ourInstance: GlideUtil? = null

        val instance: GlideUtil
            get() {
                if (ourInstance == null) {
                    ourInstance = GlideUtil()
                }
                return ourInstance as GlideUtil
            }
    }


}
