mirror of https://github.com/ThmmyNoLife/mTHMMY
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
66 lines
1.7 KiB
package gr.thmmy.mthmmy.utils;
|
|
|
|
import android.app.Application;
|
|
import android.text.TextUtils;
|
|
|
|
import com.android.volley.Request;
|
|
import com.android.volley.RequestQueue;
|
|
import com.android.volley.toolbox.ImageLoader;
|
|
import com.android.volley.toolbox.Volley;
|
|
|
|
public class ImageController extends Application {
|
|
|
|
private static final String TAG = ImageController.class.getSimpleName();
|
|
private static ImageController mInstance;
|
|
private RequestQueue mRequestQueue;
|
|
private ImageLoader mImageLoader;
|
|
|
|
public static synchronized ImageController getInstance() {
|
|
return mInstance;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
mInstance = this;
|
|
}
|
|
|
|
private RequestQueue getRequestQueue() {
|
|
if (mRequestQueue == null) {
|
|
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
|
|
}
|
|
|
|
return mRequestQueue;
|
|
}
|
|
|
|
public ImageLoader getImageLoader() {
|
|
getRequestQueue();
|
|
if (mImageLoader == null) {
|
|
mImageLoader = new ImageLoader(this.mRequestQueue,
|
|
new LruBitmapCache());
|
|
}
|
|
return this.mImageLoader;
|
|
}
|
|
|
|
public <T> void addToRequestQueue(Request<T> req, String tag) {
|
|
// set the default tag if tag is empty
|
|
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
|
|
getRequestQueue().add(req);
|
|
}
|
|
|
|
public <T> void addToRequestQueue(Request<T> req) {
|
|
req.setTag(TAG);
|
|
getRequestQueue().add(req);
|
|
}
|
|
|
|
public void cancelPendingRequests(){
|
|
mRequestQueue.cancelAll(new RequestQueue.RequestFilter() {
|
|
@Override
|
|
public boolean apply(Request<?> request) {
|
|
return true;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|