Change filename for downloaded chapters, using the last path from the url is not reliable. This will break compatibility with previously downloaded chapters, they have to be deleted and downloaded again.

Disable download progress in the chapters view, it will avoid some crashes.
This commit is contained in:
inorichi 2016-01-23 13:58:53 +01:00
parent 07ed2e2ebb
commit 11dc0d7e9e
5 changed files with 52 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.data.source.base.Source;
import eu.kanade.tachiyomi.data.source.model.Page; import eu.kanade.tachiyomi.data.source.model.Page;
import eu.kanade.tachiyomi.event.DownloadChaptersEvent; import eu.kanade.tachiyomi.event.DownloadChaptersEvent;
import eu.kanade.tachiyomi.util.DiskUtils; import eu.kanade.tachiyomi.util.DiskUtils;
import eu.kanade.tachiyomi.util.UrlUtil;
import rx.Observable; import rx.Observable;
import rx.Subscription; import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers; import rx.android.schedulers.AndroidSchedulers;
@ -279,6 +280,15 @@ public class DownloadManager {
// Get the filename for an image given the page // Get the filename for an image given the page
private String getImageFilename(Page page) { private String getImageFilename(Page page) {
String url = page.getImageUrl(); String url = page.getImageUrl();
int number = page.getPageNumber() + 1;
// Try to preserve file extension
if (UrlUtil.isJpg(url)) {
return number + ".jpg";
} else if (UrlUtil.isPng(url)) {
return number + ".png";
} else if (UrlUtil.isGif(url)) {
return number + ".gif";
}
return Uri.parse(url).getLastPathSegment().replaceAll("[^\\sa-zA-Z0-9.-]", "_"); return Uri.parse(url).getLastPathSegment().replaceAll("[^\\sa-zA-Z0-9.-]", "_");
} }

View File

@ -90,6 +90,7 @@ public class DownloadPresenter extends BasePresenter<DownloadFragment> {
.flatMap(tick -> Observable.from(download.pages) .flatMap(tick -> Observable.from(download.pages)
.map(Page::getProgress) .map(Page::getProgress)
.reduce((x, y) -> x + y)) .reduce((x, y) -> x + y))
.onBackpressureLatest()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(progress -> { .subscribe(progress -> {
if (download.totalProgress != progress) { if (download.totalProgress != progress) {

View File

@ -19,13 +19,13 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
@State Manga manga; @State Manga manga;
private static final int DB_MANGA = 1; private static final int GET_MANGA = 1;
@Override @Override
protected void onCreate(Bundle savedState) { protected void onCreate(Bundle savedState) {
super.onCreate(savedState); super.onCreate(savedState);
restartableLatestCache(DB_MANGA, this::getDbMangaObservable, MangaActivity::setManga); restartableLatestCache(GET_MANGA, this::getMangaObservable, MangaActivity::setManga);
if (savedState == null) if (savedState == null)
registerForStickyEvents(); registerForStickyEvents();
@ -38,7 +38,7 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
EventBus.getDefault().removeStickyEvent(MangaEvent.class); EventBus.getDefault().removeStickyEvent(MangaEvent.class);
} }
private Observable<Manga> getDbMangaObservable() { private Observable<Manga> getMangaObservable() {
return Observable.just(manga) return Observable.just(manga)
.doOnNext(manga -> EventBus.getDefault().postSticky(new MangaEvent(manga))); .doOnNext(manga -> EventBus.getDefault().postSticky(new MangaEvent(manga)));
} }
@ -48,7 +48,7 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
EventBus.getDefault().removeStickyEvent(manga); EventBus.getDefault().removeStickyEvent(manga);
unregisterForEvents(); unregisterForEvents();
this.manga = manga; this.manga = manga;
start(DB_MANGA); start(GET_MANGA);
} }
} }

View File

@ -103,18 +103,6 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
return view; return view;
} }
@Override
public void onResume() {
super.onResume();
observeChapterDownloadProgress();
}
@Override
public void onPause() {
unsubscribeChapterDownloadProgress();
super.onPause();
}
public void onNextChapters(List<Chapter> chapters) { public void onNextChapters(List<Chapter> chapters) {
// If the list is empty, fetch chapters from source if the conditions are met // If the list is empty, fetch chapters from source if the conditions are met
// We use presenter chapters instead because they are always unfiltered // We use presenter chapters instead because they are always unfiltered

View File

@ -5,6 +5,10 @@ import java.net.URISyntaxException;
public class UrlUtil { public class UrlUtil {
private static final String JPG = ".jpg";
private static final String PNG = ".png";
private static final String GIF = ".gif";
public static String getPath(String s) { public static String getPath(String s) {
try { try {
URI uri = new URI(s); URI uri = new URI(s);
@ -18,4 +22,37 @@ public class UrlUtil {
return s; return s;
} }
} }
public static boolean isJpg(String url) {
return containsIgnoreCase(url, JPG);
}
public static boolean isPng(String url) {
return containsIgnoreCase(url, PNG);
}
public static boolean isGif(String url) {
return containsIgnoreCase(url, GIF);
}
public static boolean containsIgnoreCase(String src, String what) {
final int length = what.length();
if (length == 0)
return true; // Empty string is contained
final char firstLo = Character.toLowerCase(what.charAt(0));
final char firstUp = Character.toUpperCase(what.charAt(0));
for (int i = src.length() - length; i >= 0; i--) {
// Quick check before calling the more expensive regionMatches() method:
final char ch = src.charAt(i);
if (ch != firstLo && ch != firstUp)
continue;
if (src.regionMatches(true, i, what, 0, length))
return true;
}
return false;
}
} }