mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-23 13:23:28 +03:00
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:
parent
07ed2e2ebb
commit
11dc0d7e9e
5 changed files with 52 additions and 16 deletions
|
@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.data.source.base.Source;
|
|||
import eu.kanade.tachiyomi.data.source.model.Page;
|
||||
import eu.kanade.tachiyomi.event.DownloadChaptersEvent;
|
||||
import eu.kanade.tachiyomi.util.DiskUtils;
|
||||
import eu.kanade.tachiyomi.util.UrlUtil;
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
|
@ -279,6 +280,15 @@ public class DownloadManager {
|
|||
// Get the filename for an image given the page
|
||||
private String getImageFilename(Page page) {
|
||||
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.-]", "_");
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,7 @@ public class DownloadPresenter extends BasePresenter<DownloadFragment> {
|
|||
.flatMap(tick -> Observable.from(download.pages)
|
||||
.map(Page::getProgress)
|
||||
.reduce((x, y) -> x + y))
|
||||
.onBackpressureLatest()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(progress -> {
|
||||
if (download.totalProgress != progress) {
|
||||
|
|
|
@ -19,13 +19,13 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
|
|||
|
||||
@State Manga manga;
|
||||
|
||||
private static final int DB_MANGA = 1;
|
||||
private static final int GET_MANGA = 1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
|
||||
restartableLatestCache(DB_MANGA, this::getDbMangaObservable, MangaActivity::setManga);
|
||||
restartableLatestCache(GET_MANGA, this::getMangaObservable, MangaActivity::setManga);
|
||||
|
||||
if (savedState == null)
|
||||
registerForStickyEvents();
|
||||
|
@ -38,7 +38,7 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
|
|||
EventBus.getDefault().removeStickyEvent(MangaEvent.class);
|
||||
}
|
||||
|
||||
private Observable<Manga> getDbMangaObservable() {
|
||||
private Observable<Manga> getMangaObservable() {
|
||||
return Observable.just(manga)
|
||||
.doOnNext(manga -> EventBus.getDefault().postSticky(new MangaEvent(manga)));
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class MangaPresenter extends BasePresenter<MangaActivity> {
|
|||
EventBus.getDefault().removeStickyEvent(manga);
|
||||
unregisterForEvents();
|
||||
this.manga = manga;
|
||||
start(DB_MANGA);
|
||||
start(GET_MANGA);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,18 +103,6 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
observeChapterDownloadProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
unsubscribeChapterDownloadProgress();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public void onNextChapters(List<Chapter> chapters) {
|
||||
// If the list is empty, fetch chapters from source if the conditions are met
|
||||
// We use presenter chapters instead because they are always unfiltered
|
||||
|
|
|
@ -5,6 +5,10 @@ import java.net.URISyntaxException;
|
|||
|
||||
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) {
|
||||
try {
|
||||
URI uri = new URI(s);
|
||||
|
@ -18,4 +22,37 @@ public class UrlUtil {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue