package com.marshalchen.common.commonUtils.urlUtils;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import com.marshalchen.common.R;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

/**
 * Get Config of UniversalImageLoader
 */
public class UniversalImageLoader {
    /**
     * The method is to get the Default UniversalImageLoader config
     *
     * @param context
     * @return ImageLoaderConfiguration
     */
    public static ImageLoaderConfiguration getDefaultImageLoaderConfiguration(Context context) {
        return getDefaultImageLoaderConfiguration(context, false);
    }

    public static ImageLoaderConfiguration getDefaultImageLoaderConfiguration(Context context, boolean isWriteLog) {
        File cacheDir = StorageUtils.getCacheDirectory(context);
        ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context)
//                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
//                .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 1) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
//                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
//                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .discCache(new UnlimitedDiscCache(cacheDir)) // default
//                .discCacheSize(50 * 1024 * 1024)
                .discCacheFileCount(1000)
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(context)) // default
                .imageDecoder(new BaseImageDecoder(false)) // default
                        //   .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .defaultDisplayImageOptions(getDefaultImageOptions());

        if (isWriteLog) {
            builder.writeDebugLogs();
        }
        ImageLoaderConfiguration config = builder.build();
        return config;
    }

    public static DisplayImageOptions getDefaultImageOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .resetViewBeforeLoading(false)  // default
                        //  .delayBeforeLoading(1000)
                .showImageOnLoading(R.drawable.titanic_wave_black)
                .considerExifParams(false) // default
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
                .bitmapConfig(Bitmap.Config.ARGB_8888) // default
                .displayer(new SimpleBitmapDisplayer()) // default
                .handler(new Handler()) // default
                .cacheInMemory(true)
                .cacheOnDisc(true)
                .build();
        return options;
    }
}

@@ -1439,32 +1439,410 @@
 n isWriteLog) %7B%0A
+        ImageLoaderConfiguration.Builder builder = getDefaultImageLoaderConfigurationBuilder(context);%0A        if (isWriteLog) %7B%0A            builder.writeDebugLogs();%0A        %7D%0A        ImageLoaderConfiguration config = builder.build();%0A        return config;%0A    %7D%0A%0A    public static ImageLoaderConfiguration.Builder getDefaultImageLoaderConfigurationBuilder(Context context) %7B%0A
         File cac
@@ -3166,25 +3166,24 @@
 ons());%0A
-%0A
         
 if (isWr
@@ -3178,123 +3178,182 @@
     
-if (isWriteLog) %7B
+return builder;
 %0A    
+%7D%0A%0A
     
-    builder.writeDebugLogs();%0A        %7D%0A        ImageLoaderConfiguration config = builder
+public static DisplayImageOptions getDefaultImageOptions() %7B%0A        DisplayImageOptions options = getDefaultImageOptionsBuilder()%0A                
 .bui
@@ -3365,38 +3365,39 @@
 %0A        return 
-config
+options
 ;%0A    %7D%0A%0A    pub
@@ -3418,32 +3418,40 @@
 playImageOptions
+.Builder
  getDefaultImage
@@ -3449,32 +3449,39 @@
 aultImageOptions
+Builder
 () %7B%0A        Dis
@@ -3496,24 +3496,32 @@
 eOptions
- options
+.Builder builder
  = new D
@@ -4122,33 +4122,8 @@
 rue)
-%0A                .build()
 ;%0A  
@@ -4127,33 +4127,33 @@
 %0A        return 
-options
+builder
 ;%0A    %7D%0A%7D%0A

add get builder in UniversalImageLoader