Remove cache size setting. Add advanced settings section. Other minor changes.
This commit is contained in:
@@ -15,25 +15,25 @@ import java.io.OutputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
||||
import eu.kanade.mangafeed.data.source.model.Page;
|
||||
import eu.kanade.mangafeed.util.DiskUtils;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import rx.Observable;
|
||||
|
||||
public class CacheManager {
|
||||
public class ChapterCache {
|
||||
|
||||
private static final String PARAMETER_CACHE_DIRECTORY = "chapter_disk_cache";
|
||||
private static final int PARAMETER_APP_VERSION = 1;
|
||||
private static final int PARAMETER_VALUE_COUNT = 1;
|
||||
private static final int PARAMETER_CACHE_SIZE = 75 * 1024 * 1024;
|
||||
|
||||
private Context context;
|
||||
private Gson gson;
|
||||
|
||||
private DiskLruCache diskCache;
|
||||
|
||||
public CacheManager(Context context, PreferencesHelper preferences) {
|
||||
public ChapterCache(Context context) {
|
||||
this.context = context;
|
||||
gson = new Gson();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class CacheManager {
|
||||
new File(context.getCacheDir(), PARAMETER_CACHE_DIRECTORY),
|
||||
PARAMETER_APP_VERSION,
|
||||
PARAMETER_VALUE_COUNT,
|
||||
preferences.cacheSize() * 1024 * 1024
|
||||
PARAMETER_CACHE_SIZE
|
||||
);
|
||||
} catch (IOException e) {
|
||||
// Do Nothing.
|
||||
@@ -136,6 +136,16 @@ public class DatabaseHelper {
|
||||
.prepare();
|
||||
}
|
||||
|
||||
public PreparedDeleteByQuery deleteMangasNotInLibrary() {
|
||||
return db.delete()
|
||||
.byQuery(DeleteQuery.builder()
|
||||
.table(MangaTable.TABLE)
|
||||
.where(MangaTable.COLUMN_FAVORITE + "=?")
|
||||
.whereArgs(0)
|
||||
.build())
|
||||
.prepare();
|
||||
}
|
||||
|
||||
|
||||
// Chapters related queries
|
||||
|
||||
|
||||
@@ -56,10 +56,6 @@ public class PreferencesHelper {
|
||||
prefs.edit().clear().apply();
|
||||
}
|
||||
|
||||
public int cacheSize() {
|
||||
return prefs.getInt(getKey(R.string.pref_chapter_cache_size_key), 75);
|
||||
}
|
||||
|
||||
public Preference<Boolean> lockOrientation() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import eu.kanade.mangafeed.App;
|
||||
import eu.kanade.mangafeed.data.cache.CacheManager;
|
||||
import eu.kanade.mangafeed.data.cache.ChapterCache;
|
||||
import eu.kanade.mangafeed.data.database.models.Chapter;
|
||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||
import eu.kanade.mangafeed.data.network.NetworkHelper;
|
||||
@@ -29,7 +29,7 @@ import rx.schedulers.Schedulers;
|
||||
public abstract class Source extends BaseSource {
|
||||
|
||||
@Inject protected NetworkHelper networkService;
|
||||
@Inject protected CacheManager cacheManager;
|
||||
@Inject protected ChapterCache chapterCache;
|
||||
@Inject protected PreferencesHelper prefs;
|
||||
protected Headers requestHeaders;
|
||||
protected LazyHeaders glideHeaders;
|
||||
@@ -89,7 +89,7 @@ public abstract class Source extends BaseSource {
|
||||
}
|
||||
|
||||
public Observable<List<Page>> getCachedPageListOrPullFromNetwork(final String chapterUrl) {
|
||||
return cacheManager.getPageUrlsFromDiskCache(getChapterCacheKey(chapterUrl))
|
||||
return chapterCache.getPageUrlsFromDiskCache(getChapterCacheKey(chapterUrl))
|
||||
.onErrorResumeNext(throwable -> {
|
||||
return pullPageListFromNetwork(chapterUrl);
|
||||
})
|
||||
@@ -141,13 +141,13 @@ public abstract class Source extends BaseSource {
|
||||
|
||||
return pageObservable
|
||||
.flatMap(p -> {
|
||||
if (!cacheManager.isImageInCache(page.getImageUrl())) {
|
||||
if (!chapterCache.isImageInCache(page.getImageUrl())) {
|
||||
return cacheImage(page);
|
||||
}
|
||||
return Observable.just(page);
|
||||
})
|
||||
.flatMap(p -> {
|
||||
page.setImagePath(cacheManager.getImagePath(page.getImageUrl()));
|
||||
page.setImagePath(chapterCache.getImagePath(page.getImageUrl()));
|
||||
page.setStatus(Page.READY);
|
||||
return Observable.just(page);
|
||||
})
|
||||
@@ -162,7 +162,7 @@ public abstract class Source extends BaseSource {
|
||||
return getImageProgressResponse(page)
|
||||
.flatMap(resp -> {
|
||||
try {
|
||||
cacheManager.putImageToDiskCache(page.getImageUrl(), resp);
|
||||
chapterCache.putImageToDiskCache(page.getImageUrl(), resp);
|
||||
} catch (IOException e) {
|
||||
return Observable.error(e);
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public abstract class Source extends BaseSource {
|
||||
|
||||
public void savePageList(String chapterUrl, List<Page> pages) {
|
||||
if (pages != null)
|
||||
cacheManager.putPageUrlsToDiskCache(getChapterCacheKey(chapterUrl), pages);
|
||||
chapterCache.putPageUrlsToDiskCache(getChapterCacheKey(chapterUrl), pages);
|
||||
}
|
||||
|
||||
protected List<Page> convertToPages(List<String> pageUrls) {
|
||||
|
||||
Reference in New Issue
Block a user