Created
November 30, 2013 19:52
-
-
Save brk3/7723643 to your computer and use it in GitHub Desktop.
Singleton to manage and access Picasso cache
This file contains hidden or 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
package com.bourke.glimmr.common; | |
import android.content.Context; | |
import com.squareup.picasso.LruCache; | |
import com.squareup.picasso.Picasso; | |
public class PicassoHelper { | |
private static final String TAG = "Glimmr/PicassoHelper"; | |
private static PicassoHelper singleton; | |
private Picasso mPicasso; | |
private LruCache mCache; | |
private PicassoHelper() { | |
} | |
public static PicassoHelper getInstance(Context context) { | |
if (singleton == null) { | |
singleton = new PicassoHelper(); | |
LruCache cache = new LruCache(context); | |
singleton.mCache = cache; | |
singleton.mPicasso = new Picasso.Builder(context) | |
.memoryCache(cache).debugging(true) | |
.build(); | |
} | |
return singleton; | |
} | |
public Picasso getPicasso() { | |
return mPicasso; | |
} | |
public LruCache getCache() { | |
return mCache; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment