From b9ab10253ab04bacd7d27ab7a7aecd561f7efbc2 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 19 Mar 2014 18:01:55 +0100 Subject: Prevent images from being loaded multiple times (copied from AntennaPodSP) --- .../danoeh/antennapod/asynctask/ImageLoader.java | 436 +++++++++++---------- 1 file changed, 222 insertions(+), 214 deletions(-) (limited to 'src/de/danoeh/antennapod/asynctask') diff --git a/src/de/danoeh/antennapod/asynctask/ImageLoader.java b/src/de/danoeh/antennapod/asynctask/ImageLoader.java index a4a9bc823..c49d7549b 100644 --- a/src/de/danoeh/antennapod/asynctask/ImageLoader.java +++ b/src/de/danoeh/antennapod/asynctask/ImageLoader.java @@ -1,14 +1,8 @@ package de.danoeh.antennapod.asynctask; -import java.io.InputStream; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; - import android.annotation.SuppressLint; import android.app.ActivityManager; import android.content.Context; -import android.content.res.TypedArray; import android.os.Handler; import android.support.v4.util.LruCache; import android.util.Log; @@ -17,214 +11,228 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; -/** Caches and loads FeedImage bitmaps in the background */ +import java.io.InputStream; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +/** + * Caches and loads FeedImage bitmaps in the background + */ public class ImageLoader { - private static final String TAG = "ImageLoader"; - private static ImageLoader singleton; - - public static final int IMAGE_TYPE_THUMBNAIL = 0; - public static final int IMAGE_TYPE_COVER = 1; - - private Handler handler; - private ExecutorService executor; - - /** - * Stores references to loaded bitmaps. Bitmaps can be accessed by the id of - * the FeedImage the bitmap belongs to. - */ - - final int memClass = ((ActivityManager) PodcastApp.getInstance() - .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); - - // Use 1/8th of the available memory for this memory cache. - final int thumbnailCacheSize = 1024 * 1024 * memClass / 8; - - private LruCache coverCache; - private LruCache thumbnailCache; - - private ImageLoader() { - handler = new Handler(); - executor = createExecutor(); - - coverCache = new LruCache(1); - - thumbnailCache = new LruCache(thumbnailCacheSize) { - - @SuppressLint("NewApi") - @Override - protected int sizeOf(String key, CachedBitmap value) { - if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 12) - return value.getBitmap().getByteCount(); - else - return (value.getBitmap().getRowBytes() * value.getBitmap() - .getHeight()); - - } - - }; - } - - private ExecutorService createExecutor() { - return Executors.newFixedThreadPool(Runtime.getRuntime() - .availableProcessors(), new ThreadFactory() { - - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - t.setPriority(Thread.MIN_PRIORITY); - return t; - } - }); - } - - public static synchronized ImageLoader getInstance() { - if (singleton == null) { - singleton = new ImageLoader(); - } - return singleton; - } - - /** - * Load a bitmap from the cover cache. If the bitmap is not in the cache, it - * will be loaded from the disk. This method should either be called if the - * ImageView's size has already been set or inside a Runnable which is - * posted to the ImageView's message queue. - */ - public void loadCoverBitmap(ImageWorkerTaskResource source, ImageView target) { - loadCoverBitmap(source, target, target.getHeight()); - } - - /** - * Load a bitmap from the cover cache. If the bitmap is not in the cache, it - * will be loaded from the disk. This method should either be called if the - * ImageView's size has already been set or inside a Runnable which is - * posted to the ImageView's message queue. - */ - public void loadCoverBitmap(ImageWorkerTaskResource source, - ImageView target, int length) { - final int defaultCoverResource = getDefaultCoverResource(target - .getContext()); - - if (source != null && source.getImageLoaderCacheKey() != null) { - target.setTag(R.id.imageloader_key, source.getImageLoaderCacheKey()); - CachedBitmap cBitmap = getBitmapFromCoverCache(source.getImageLoaderCacheKey()); - if (cBitmap != null && cBitmap.getLength() >= length) { - target.setImageBitmap(cBitmap.getBitmap()); - } else { - target.setImageResource(defaultCoverResource); - BitmapDecodeWorkerTask worker = new BitmapDecodeWorkerTask( - handler, target, source, length, IMAGE_TYPE_COVER); - executor.submit(worker); - } - } else { - target.setImageResource(defaultCoverResource); - } - } - - /** - * Load a bitmap from the thumbnail cache. If the bitmap is not in the - * cache, it will be loaded from the disk. This method should either be - * called if the ImageView's size has already been set or inside a Runnable - * which is posted to the ImageView's message queue. - */ - public void loadThumbnailBitmap(ImageWorkerTaskResource source, - ImageView target) { - loadThumbnailBitmap(source, target, target.getHeight()); - } - - /** - * Load a bitmap from the thumbnail cache. If the bitmap is not in the - * cache, it will be loaded from the disk. This method should either be - * called if the ImageView's size has already been set or inside a Runnable - * which is posted to the ImageView's message queue. - */ - public void loadThumbnailBitmap(ImageWorkerTaskResource source, - ImageView target, int length) { - final int defaultCoverResource = getDefaultCoverResource(target - .getContext()); - - if (source != null && source.getImageLoaderCacheKey() != null) { - target.setTag(R.id.imageloader_key, source.getImageLoaderCacheKey()); - CachedBitmap cBitmap = getBitmapFromThumbnailCache(source.getImageLoaderCacheKey()); - if (cBitmap != null && cBitmap.getLength() >= length) { - target.setImageBitmap(cBitmap.getBitmap()); - } else { - target.setImageResource(defaultCoverResource); - BitmapDecodeWorkerTask worker = new BitmapDecodeWorkerTask( - handler, target, source, length, IMAGE_TYPE_THUMBNAIL); - executor.submit(worker); - } - } else { - target.setImageResource(defaultCoverResource); - } - } - - public void clearExecutorQueue() { - executor.shutdownNow(); - if (AppConfig.DEBUG) - Log.d(TAG, "Executor was shut down."); - executor = createExecutor(); - - } - - public void wipeImageCache() { - coverCache.evictAll(); - thumbnailCache.evictAll(); - } - - public boolean isInThumbnailCache(String fileUrl) { - return thumbnailCache.get(fileUrl) != null; - } - - private CachedBitmap getBitmapFromThumbnailCache(String key) { - return thumbnailCache.get(key); - } - - public void addBitmapToThumbnailCache(String key, CachedBitmap bitmap) { - thumbnailCache.put(key, bitmap); - } - - public boolean isInCoverCache(String fileUrl) { - return coverCache.get(fileUrl) != null; - } - - private CachedBitmap getBitmapFromCoverCache(String key) { - return coverCache.get(key); - } - - public void addBitmapToCoverCache(String key, CachedBitmap bitmap) { - coverCache.put(key, bitmap); - } - - private int getDefaultCoverResource(Context context) { - return android.R.color.transparent; - } - - /** - * Used by the BitmapDecodeWorker task to retrieve the source of the bitmap. - */ - public interface ImageWorkerTaskResource { - /** - * Opens a new InputStream that can be decoded as a bitmap by the - * BitmapFactory. - */ - public InputStream openImageInputStream(); - - /** - * Returns an InputStream that points to the beginning of the image - * resource. Implementations can either create a new InputStream or - * reset the existing one, depending on their implementation of - * openInputStream. If a new InputStream is returned, the one given as a - * parameter MUST be closed. - * @param input The input stream that was returned by openImageInputStream() - * */ - public InputStream reopenImageInputStream(InputStream input); - - /** - * Returns a string that identifies the image resource. Example: file - * path of an image - */ - public String getImageLoaderCacheKey(); - } + private static final String TAG = "ImageLoader"; + private static ImageLoader singleton; + + public static final int IMAGE_TYPE_THUMBNAIL = 0; + public static final int IMAGE_TYPE_COVER = 1; + + private Handler handler; + private ExecutorService executor; + + /** + * Stores references to loaded bitmaps. Bitmaps can be accessed by the id of + * the FeedImage the bitmap belongs to. + */ + + final int memClass = ((ActivityManager) PodcastApp.getInstance() + .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); + + // Use 1/8th of the available memory for this memory cache. + final int thumbnailCacheSize = 1024 * 1024 * memClass / 8; + + private LruCache coverCache; + private LruCache thumbnailCache; + + private ImageLoader() { + handler = new Handler(); + executor = createExecutor(); + + coverCache = new LruCache(1); + + thumbnailCache = new LruCache(thumbnailCacheSize) { + + @SuppressLint("NewApi") + @Override + protected int sizeOf(String key, CachedBitmap value) { + if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 12) + return value.getBitmap().getByteCount(); + else + return (value.getBitmap().getRowBytes() * value.getBitmap() + .getHeight()); + + } + + }; + } + + private ExecutorService createExecutor() { + return Executors.newFixedThreadPool(Runtime.getRuntime() + .availableProcessors(), new ThreadFactory() { + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setPriority(Thread.MIN_PRIORITY); + return t; + } + }); + } + + public static synchronized ImageLoader getInstance() { + if (singleton == null) { + singleton = new ImageLoader(); + } + return singleton; + } + + /** + * Load a bitmap from the cover cache. If the bitmap is not in the cache, it + * will be loaded from the disk. This method should either be called if the + * ImageView's size has already been set or inside a Runnable which is + * posted to the ImageView's message queue. + */ + public void loadCoverBitmap(ImageWorkerTaskResource source, ImageView target) { + loadCoverBitmap(source, target, target.getHeight()); + } + + /** + * Load a bitmap from the cover cache. If the bitmap is not in the cache, it + * will be loaded from the disk. This method should either be called if the + * ImageView's size has already been set or inside a Runnable which is + * posted to the ImageView's message queue. + */ + public void loadCoverBitmap(ImageWorkerTaskResource source, + ImageView target, int length) { + final int defaultCoverResource = getDefaultCoverResource(target + .getContext()); + final String cacheKey; + if (source != null && (cacheKey = source.getImageLoaderCacheKey()) != null) { + final Object currentTag = target.getTag(R.id.imageloader_key); + if (currentTag == null || !cacheKey.equals(currentTag)) { + target.setTag(R.id.imageloader_key, cacheKey); + CachedBitmap cBitmap = getBitmapFromCoverCache(cacheKey); + if (cBitmap != null && cBitmap.getLength() >= length) { + target.setImageBitmap(cBitmap.getBitmap()); + } else { + target.setImageResource(defaultCoverResource); + BitmapDecodeWorkerTask worker = new BitmapDecodeWorkerTask( + handler, target, source, length, IMAGE_TYPE_COVER); + executor.submit(worker); + } + } + } else { + target.setImageResource(defaultCoverResource); + } + } + + /** + * Load a bitmap from the thumbnail cache. If the bitmap is not in the + * cache, it will be loaded from the disk. This method should either be + * called if the ImageView's size has already been set or inside a Runnable + * which is posted to the ImageView's message queue. + */ + public void loadThumbnailBitmap(ImageWorkerTaskResource source, + ImageView target) { + loadThumbnailBitmap(source, target, target.getHeight()); + } + + /** + * Load a bitmap from the thumbnail cache. If the bitmap is not in the + * cache, it will be loaded from the disk. This method should either be + * called if the ImageView's size has already been set or inside a Runnable + * which is posted to the ImageView's message queue. + */ + public void loadThumbnailBitmap(ImageWorkerTaskResource source, + ImageView target, int length) { + final int defaultCoverResource = getDefaultCoverResource(target + .getContext()); + final String cacheKey; + if (source != null && (cacheKey = source.getImageLoaderCacheKey()) != null) { + final Object currentTag = target.getTag(R.id.imageloader_key); + if (currentTag == null || !cacheKey.equals(currentTag)) { + target.setTag(R.id.imageloader_key, cacheKey); + CachedBitmap cBitmap = getBitmapFromThumbnailCache(cacheKey); + if (cBitmap != null && cBitmap.getLength() >= length) { + target.setImageBitmap(cBitmap.getBitmap()); + } else { + target.setImageResource(defaultCoverResource); + BitmapDecodeWorkerTask worker = new BitmapDecodeWorkerTask( + handler, target, source, length, IMAGE_TYPE_THUMBNAIL); + executor.submit(worker); + } + } + } else { + target.setImageResource(defaultCoverResource); + } + } + + public void clearExecutorQueue() { + executor.shutdownNow(); + if (AppConfig.DEBUG) + Log.d(TAG, "Executor was shut down."); + executor = createExecutor(); + + } + + public void wipeImageCache() { + coverCache.evictAll(); + thumbnailCache.evictAll(); + } + + public boolean isInThumbnailCache(String fileUrl) { + return thumbnailCache.get(fileUrl) != null; + } + + private CachedBitmap getBitmapFromThumbnailCache(String key) { + return thumbnailCache.get(key); + } + + public void addBitmapToThumbnailCache(String key, CachedBitmap bitmap) { + thumbnailCache.put(key, bitmap); + } + + public boolean isInCoverCache(String fileUrl) { + return coverCache.get(fileUrl) != null; + } + + private CachedBitmap getBitmapFromCoverCache(String key) { + return coverCache.get(key); + } + + public void addBitmapToCoverCache(String key, CachedBitmap bitmap) { + coverCache.put(key, bitmap); + } + + private int getDefaultCoverResource(Context context) { + return android.R.color.transparent; + } + + /** + * Used by the BitmapDecodeWorker task to retrieve the source of the bitmap. + */ + public interface ImageWorkerTaskResource { + /** + * Opens a new InputStream that can be decoded as a bitmap by the + * BitmapFactory. + */ + public InputStream openImageInputStream(); + + /** + * Returns an InputStream that points to the beginning of the image + * resource. Implementations can either create a new InputStream or + * reset the existing one, depending on their implementation of + * openInputStream. If a new InputStream is returned, the one given as a + * parameter MUST be closed. + * + * @param input The input stream that was returned by openImageInputStream() + */ + public InputStream reopenImageInputStream(InputStream input); + + /** + * Returns a string that identifies the image resource. Example: file + * path of an image + */ + public String getImageLoaderCacheKey(); + } } -- cgit v1.2.3 From ae09dbffb6746641a5658750085af08f5ff60e47 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 28 Mar 2014 20:17:15 +0100 Subject: Fixed image loading bugs - If a feed contained items with non-unique image URLs, those images were not displayed - Images in a list were not loaded correctly if the list contained entries without an image --- src/de/danoeh/antennapod/asynctask/ImageLoader.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/de/danoeh/antennapod/asynctask') diff --git a/src/de/danoeh/antennapod/asynctask/ImageLoader.java b/src/de/danoeh/antennapod/asynctask/ImageLoader.java index c49d7549b..b50502ea8 100644 --- a/src/de/danoeh/antennapod/asynctask/ImageLoader.java +++ b/src/de/danoeh/antennapod/asynctask/ImageLoader.java @@ -26,6 +26,12 @@ public class ImageLoader { public static final int IMAGE_TYPE_THUMBNAIL = 0; public static final int IMAGE_TYPE_COVER = 1; + /** + * Used by loadThumbnailBitmap and loadCoverBitmap to denote an ImageView that displays the default image resource. + * This is the case if the given source to load the image from was null or did not return any image data. + */ + private static final Object DEFAULT_IMAGE_RESOURCE_TAG = new Object(); + private Handler handler; private ExecutorService executor; @@ -122,6 +128,7 @@ public class ImageLoader { } } else { target.setImageResource(defaultCoverResource); + target.setTag(R.id.imageloader_key, DEFAULT_IMAGE_RESOURCE_TAG); } } @@ -163,6 +170,7 @@ public class ImageLoader { } } else { target.setImageResource(defaultCoverResource); + target.setTag(R.id.imageloader_key, DEFAULT_IMAGE_RESOURCE_TAG); } } -- cgit v1.2.3 From b2de7512f4c871e882760bfe8bffa27d10c1c68a Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 28 Mar 2014 21:16:27 +0100 Subject: Replaced AppConfig.DEBUG with BuildConfig.DEBUG --- .../antennapod/asynctask/BitmapDecodeWorkerTask.java | 7 +++---- .../danoeh/antennapod/asynctask/DownloadObserver.java | 8 ++++---- .../danoeh/antennapod/asynctask/FlattrClickWorker.java | 7 +++---- .../antennapod/asynctask/FlattrStatusFetcher.java | 6 +++--- .../danoeh/antennapod/asynctask/FlattrTokenFetcher.java | 11 +++++------ src/de/danoeh/antennapod/asynctask/ImageDiskCache.java | 8 ++++---- src/de/danoeh/antennapod/asynctask/ImageLoader.java | 4 ++-- .../danoeh/antennapod/asynctask/OpmlExportWorker.java | 13 ++++++------- src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java | 6 +++--- .../danoeh/antennapod/asynctask/OpmlImportWorker.java | 17 ++++++++--------- 10 files changed, 41 insertions(+), 46 deletions(-) (limited to 'src/de/danoeh/antennapod/asynctask') diff --git a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java index ef70c1e64..43118c3af 100644 --- a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java +++ b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.asynctask; -import android.content.res.TypedArray; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -8,7 +7,7 @@ import android.graphics.drawable.TransitionDrawable; import android.os.Handler; import android.util.Log; import android.widget.ImageView; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.ImageLoader.ImageWorkerTaskResource; @@ -65,7 +64,7 @@ public class BitmapDecodeWorkerTask extends Thread { target.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(FADE_DURATION); } else { - if (AppConfig.DEBUG) + if (BuildConfig.DEBUG) Log.d(TAG, "Not displaying image"); } } @@ -82,7 +81,7 @@ public class BitmapDecodeWorkerTask extends Thread { target.getResources(), defaultCoverResource), PREFERRED_LENGTH); } - if (AppConfig.DEBUG) + if (BuildConfig.DEBUG) Log.d(TAG, "Finished loading bitmaps"); endBackgroundTask(); diff --git a/src/de/danoeh/antennapod/asynctask/DownloadObserver.java b/src/de/danoeh/antennapod/asynctask/DownloadObserver.java index 26e405615..40388cde5 100644 --- a/src/de/danoeh/antennapod/asynctask/DownloadObserver.java +++ b/src/de/danoeh/antennapod/asynctask/DownloadObserver.java @@ -5,7 +5,7 @@ import android.content.*; import android.os.Handler; import android.os.IBinder; import android.util.Log; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.service.download.DownloadService; import de.danoeh.antennapod.service.download.Downloader; @@ -55,13 +55,13 @@ public class DownloadObserver { } public void onResume() { - if (AppConfig.DEBUG) Log.d(TAG, "DownloadObserver resumed"); + if (BuildConfig.DEBUG) Log.d(TAG, "DownloadObserver resumed"); activity.registerReceiver(contentChangedReceiver, new IntentFilter(DownloadService.ACTION_DOWNLOADS_CONTENT_CHANGED)); activity.bindService(new Intent(activity, DownloadService.class), mConnection, 0); } public void onPause() { - if (AppConfig.DEBUG) Log.d(TAG, "DownloadObserver paused"); + if (BuildConfig.DEBUG) Log.d(TAG, "DownloadObserver paused"); activity.unregisterReceiver(contentChangedReceiver); activity.unbindService(mConnection); stopRefresher(); @@ -93,7 +93,7 @@ public class DownloadObserver { downloadService = ((DownloadService.LocalBinder) service) .getService(); mIsBound.set(true); - if (AppConfig.DEBUG) + if (BuildConfig.DEBUG) Log.d(TAG, "Connection to service established"); List downloaderList = downloadService.getDownloads(); if (downloaderList != null && !downloaderList.isEmpty()) { diff --git a/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java b/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java index 5f483625a..e9aa79ac1 100644 --- a/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java +++ b/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java @@ -13,7 +13,7 @@ import android.os.AsyncTask; import android.support.v4.app.NotificationCompat; import android.util.Log; import android.widget.Toast; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.storage.DBReader; @@ -23,7 +23,6 @@ import de.danoeh.antennapod.util.flattr.FlattrUtils; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executor; /** * Performs a click action in a background thread. @@ -200,7 +199,7 @@ public class FlattrClickWorker extends AsyncTask { @Override protected void onPostExecute(Void result) { - if (AppConfig.DEBUG) Log.d(TAG, "Exit code was " + exitCode); + if (BuildConfig.DEBUG) Log.d(TAG, "Exit code was " + exitCode); switch (exitCode) { case NO_TOKEN: @@ -234,7 +233,7 @@ public class FlattrClickWorker extends AsyncTask { @Override protected Void doInBackground(Void... params) { - if (AppConfig.DEBUG) Log.d(TAG, "Starting background work"); + if (BuildConfig.DEBUG) Log.d(TAG, "Starting background work"); exitCode = EXIT_DEFAULT; diff --git a/src/de/danoeh/antennapod/asynctask/FlattrStatusFetcher.java b/src/de/danoeh/antennapod/asynctask/FlattrStatusFetcher.java index 4974c6b56..04d349671 100644 --- a/src/de/danoeh/antennapod/asynctask/FlattrStatusFetcher.java +++ b/src/de/danoeh/antennapod/asynctask/FlattrStatusFetcher.java @@ -2,7 +2,7 @@ package de.danoeh.antennapod.asynctask; import android.content.Context; import android.util.Log; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.storage.DBWriter; import de.danoeh.antennapod.util.flattr.FlattrUtils; import org.shredzone.flattr4j.exception.FlattrException; @@ -26,7 +26,7 @@ public class FlattrStatusFetcher extends Thread { @Override public void run() { - if (AppConfig.DEBUG) Log.d(TAG, "Starting background work: Retrieving Flattr status"); + if (BuildConfig.DEBUG) Log.d(TAG, "Starting background work: Retrieving Flattr status"); Thread.currentThread().setPriority(Thread.MIN_PRIORITY); @@ -42,6 +42,6 @@ public class FlattrStatusFetcher extends Thread { e.printStackTrace(); } - if (AppConfig.DEBUG) Log.d(TAG, "Finished background work: Retrieved Flattr status"); + if (BuildConfig.DEBUG) Log.d(TAG, "Finished background work: Retrieved Flattr status"); } } diff --git a/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java b/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java index b56e83d25..0dcf832f7 100644 --- a/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java +++ b/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java @@ -1,20 +1,19 @@ package de.danoeh.antennapod.asynctask; -import org.shredzone.flattr4j.exception.FlattrException; -import org.shredzone.flattr4j.oauth.AccessToken; -import org.shredzone.flattr4j.oauth.AndroidAuthenticator; - import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.net.Uri; import android.os.AsyncTask; import android.util.Log; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.FlattrAuthActivity; import de.danoeh.antennapod.util.flattr.FlattrUtils; +import org.shredzone.flattr4j.exception.FlattrException; +import org.shredzone.flattr4j.oauth.AccessToken; +import org.shredzone.flattr4j.oauth.AndroidAuthenticator; /** Fetches the access token in the background in order to avoid networkOnMainThread exception. */ @@ -76,7 +75,7 @@ public class FlattrTokenFetcher extends AsyncTask { return null; } if (token != null) { - if (AppConfig.DEBUG) Log.d(TAG, "Successfully got token"); + if (BuildConfig.DEBUG) Log.d(TAG, "Successfully got token"); return token; } else { Log.w(TAG, "Flattr token was null"); diff --git a/src/de/danoeh/antennapod/asynctask/ImageDiskCache.java b/src/de/danoeh/antennapod/asynctask/ImageDiskCache.java index ae8bf8b87..b90d78c14 100644 --- a/src/de/danoeh/antennapod/asynctask/ImageDiskCache.java +++ b/src/de/danoeh/antennapod/asynctask/ImageDiskCache.java @@ -4,7 +4,7 @@ import android.os.Handler; import android.util.Log; import android.util.Pair; import android.widget.ImageView; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; import de.danoeh.antennapod.service.download.DownloadRequest; @@ -89,7 +89,7 @@ public class ImageDiskCache { private synchronized void initCacheFolder() { if (diskCache == null) { - if (AppConfig.DEBUG) Log.d(TAG, "Initializing cache folder"); + if (BuildConfig.DEBUG) Log.d(TAG, "Initializing cache folder"); File cacheFile = new File(cacheFolder, CACHE_FILE_NAME); if (cacheFile.exists()) { try { @@ -242,7 +242,7 @@ public class ImageDiskCache { if (diskCache == null) { initCacheFolder(); } - if (AppConfig.DEBUG) Log.d(TAG, "Adding new image to disk cache: " + url); + if (BuildConfig.DEBUG) Log.d(TAG, "Adding new image to disk cache: " + url); diskCache.put(url, obj); cacheSize += obj.size; if (cacheSize > maxCacheSize) { @@ -313,7 +313,7 @@ public class ImageDiskCache { dco = new DiskCacheObject(newFile.getAbsolutePath(), size); addToDiskCache(downloadUrl, dco); - if (AppConfig.DEBUG) Log.d(TAG, "Image was downloaded"); + if (BuildConfig.DEBUG) Log.d(TAG, "Image was downloaded"); } else { Log.w(TAG, "Download of url " + downloadUrl + " failed. Reason: " + result.getResult().getReasonDetailed() + "(" + result.getResult().getReason() + ")"); } diff --git a/src/de/danoeh/antennapod/asynctask/ImageLoader.java b/src/de/danoeh/antennapod/asynctask/ImageLoader.java index b50502ea8..6c60b7b1f 100644 --- a/src/de/danoeh/antennapod/asynctask/ImageLoader.java +++ b/src/de/danoeh/antennapod/asynctask/ImageLoader.java @@ -7,7 +7,7 @@ import android.os.Handler; import android.support.v4.util.LruCache; import android.util.Log; import android.widget.ImageView; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; @@ -176,7 +176,7 @@ public class ImageLoader { public void clearExecutorQueue() { executor.shutdownNow(); - if (AppConfig.DEBUG) + if (BuildConfig.DEBUG) Log.d(TAG, "Executor was shut down."); executor = createExecutor(); diff --git a/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java b/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java index 745bc7079..4abb1a67d 100644 --- a/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java +++ b/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java @@ -1,11 +1,5 @@ package de.danoeh.antennapod.asynctask; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.Arrays; - import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -17,8 +11,13 @@ import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; import de.danoeh.antennapod.opml.OpmlWriter; import de.danoeh.antennapod.preferences.UserPreferences; -import de.danoeh.antennapod.util.LangUtils; import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.util.LangUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; /** Writes an OPML file into the export directory in the background. */ public class OpmlExportWorker extends AsyncTask { diff --git a/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java b/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java index 64e678086..038b8dcc5 100644 --- a/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java +++ b/src/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java @@ -1,8 +1,5 @@ package de.danoeh.antennapod.asynctask; -import java.util.Arrays; -import java.util.Date; - import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; @@ -14,6 +11,9 @@ import de.danoeh.antennapod.opml.OpmlElement; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.storage.DownloadRequester; +import java.util.Arrays; +import java.util.Date; + /** Queues items for download in the background. */ public class OpmlFeedQueuer extends AsyncTask { private Context context; diff --git a/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java b/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java index 4816c25ab..13534fa64 100644 --- a/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java +++ b/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java @@ -1,11 +1,5 @@ package de.danoeh.antennapod.asynctask; -import java.io.IOException; -import java.io.Reader; -import java.util.ArrayList; - -import org.xmlpull.v1.XmlPullParserException; - import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -14,10 +8,15 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.AsyncTask; import android.util.Log; -import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.opml.OpmlElement; import de.danoeh.antennapod.opml.OpmlReader; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; public class OpmlImportWorker extends AsyncTask> { @@ -38,7 +37,7 @@ public class OpmlImportWorker extends @Override protected ArrayList doInBackground(Void... params) { - if (AppConfig.DEBUG) + if (BuildConfig.DEBUG) Log.d(TAG, "Starting background work"); if (mReader==null) { @@ -73,7 +72,7 @@ public class OpmlImportWorker extends } progDialog.dismiss(); if (exception != null) { - if (AppConfig.DEBUG) + if (BuildConfig.DEBUG) Log.d(TAG, "An error occured while trying to parse the opml document"); AlertDialog.Builder alert = new AlertDialog.Builder(context); -- cgit v1.2.3