package com.dylanvann.fastimage;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;

class FastImageViewModule extends ReactContextBaseJavaModule {

    private static final String REACT_CLASS = "FastImageView";

    FastImageViewModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    private static Drawable TRANSPARENT_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);

    @ReactMethod
    public void preload(final ReadableArray sources) {
        final Activity activity = getCurrentActivity();
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < sources.size(); i++) {
                    final ReadableMap source = sources.getMap(i);
                    final GlideUrl glideUrl = FastImageViewConverter.glideUrl(source);
                    final Priority priority = FastImageViewConverter.priority(source);
                    Glide
                            .with(activity.getApplicationContext())
                            .load(glideUrl)
                            .priority(priority)
                            .placeholder(TRANSPARENT_DRAWABLE)
                            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                            .preload();
                }
            }
        });
    }
}

@@ -352,16 +352,66 @@
 ideUrl;%0A
+import com.bumptech.glide.request.RequestOptions;%0A
 import c
@@ -1580,32 +1580,33 @@
 iority(source);%0A
+%0A
                 
@@ -1613,124 +1613,191 @@
     
-Glide%0A                            .with(activity.getApplicationContext())%0A                            .load(glideUrl
+RequestOptions options = new RequestOptions()%0A                            .placeholder(TRANSPARENT_DRAWABLE)%0A                            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC
 )%0A  
@@ -1841,16 +1841,18 @@
 riority)
+;%0A
 %0A       
@@ -1848,32 +1848,46 @@
 );%0A%0A            
+        Glide%0A
                 
@@ -1890,114 +1890,167 @@
     
-.placeholder(TRANSPARENT_DRAWABLE)%0A                            .diskCacheStrategy(DiskCacheStrategy.SOURCE
+            .with(activity.getApplicationContext())%0A                            .applyDefaultRequestOptions(options)%0A                            .load(glideUrl
 )%0A  

Update fastimage module to use RequestOptions