Last active
December 15, 2017 15:28
-
-
Save communikein/22fd2df5b7237e03741611c70b40b208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.support.v4.util.LruCache; | |
import com.android.volley.Cache; | |
import com.android.volley.Network; | |
import com.android.volley.RequestQueue; | |
import com.android.volley.toolbox.BasicNetwork; | |
import com.android.volley.toolbox.DiskBasedCache; | |
import com.android.volley.toolbox.HurlStack; | |
import com.android.volley.toolbox.ImageLoader; | |
public class ProfilePictureVolleyRequest { | |
private Context mContext; | |
private RequestQueue mRequestQueue; | |
private ImageLoader mImageLoader; | |
public ProfilePictureVolleyRequest(Context context, User user) { | |
this.mContext = context; | |
this.mRequestQueue = getRequestQueue(); | |
mImageLoader = new ProfilePictureLoader(user, mRequestQueue, new ImageLoader.ImageCache() { | |
private final LruCache<String, Bitmap> cache = new LruCache<>(20); | |
@Override | |
public Bitmap getBitmap(String url) { | |
return cache.get(url); | |
} | |
@Override | |
public void putBitmap(String url, Bitmap bitmap) { | |
cache.put(url, bitmap); | |
} | |
}); | |
} | |
private RequestQueue getRequestQueue() { | |
if (mRequestQueue == null) { | |
Cache cache = new DiskBasedCache(mContext.getCacheDir(), 10 * 1024 * 1024); | |
Network network = new BasicNetwork( | |
new HurlStack(null, S3Helper.getSocketFactory(mContext))); | |
mRequestQueue = new RequestQueue(cache, network); | |
mRequestQueue.start(); | |
} | |
return mRequestQueue; | |
} | |
public ImageLoader getImageLoader() { | |
return mImageLoader; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment