mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 17:31:52 +01:00
Change recent chapters query, now it shows last month updates. Download manager now uses a thread pool.
This commit is contained in:
parent
e6a17e25a9
commit
fa71e906c9
@ -162,11 +162,11 @@ public class DatabaseHelper {
|
||||
.prepare();
|
||||
}
|
||||
|
||||
public PreparedGetListOfObjects<MangaChapter> getRecentChapters() {
|
||||
public PreparedGetListOfObjects<MangaChapter> getRecentChapters(Date date) {
|
||||
return db.get()
|
||||
.listOfObjects(MangaChapter.class)
|
||||
.withQuery(RawQuery.builder()
|
||||
.query(MangaChapterGetResolver.RECENT_CHAPTERS_QUERY)
|
||||
.query(MangaChapterGetResolver.getRecentChaptersQuery(date))
|
||||
.observesTables(ChapterTable.TABLE)
|
||||
.build())
|
||||
.withGetResolver(MangaChapterGetResolver.INSTANCE)
|
||||
|
@ -5,6 +5,8 @@ import android.support.annotation.NonNull;
|
||||
|
||||
import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter;
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterStorIOSQLiteGetResolver;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
@ -24,10 +26,12 @@ public class MangaChapterGetResolver extends DefaultGetResolver<MangaChapter> {
|
||||
MangaTable.COLUMN_ID,
|
||||
ChapterTable.COLUMN_MANGA_ID);
|
||||
|
||||
public static final String RECENT_CHAPTERS_QUERY = String.format(
|
||||
QUERY + " WHERE %1$s = 1 ORDER BY %2$s DESC LIMIT 100",
|
||||
MangaTable.COLUMN_FAVORITE,
|
||||
ChapterTable.COLUMN_DATE_UPLOAD);
|
||||
public static String getRecentChaptersQuery(Date date) {
|
||||
return QUERY + String.format(" WHERE %1$s = 1 AND %2$s > %3$d ORDER BY %2$s DESC",
|
||||
MangaTable.COLUMN_FAVORITE,
|
||||
ChapterTable.COLUMN_DATE_UPLOAD,
|
||||
date.getTime());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private final MangaStorIOSQLiteGetResolver mangaGetResolver;
|
||||
|
@ -15,6 +15,8 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
@ -48,6 +50,8 @@ public class DownloadManager {
|
||||
private DownloadQueue queue;
|
||||
private volatile boolean isRunning;
|
||||
|
||||
private ExecutorService threadPool;
|
||||
|
||||
public static final String PAGE_LIST_FILE = "index.json";
|
||||
|
||||
public DownloadManager(Context context, SourceManager sourceManager, PreferencesHelper preferences) {
|
||||
@ -66,10 +70,11 @@ public class DownloadManager {
|
||||
if (downloadsSubscription != null && !downloadsSubscription.isUnsubscribed())
|
||||
downloadsSubscription.unsubscribe();
|
||||
|
||||
threadPool = Executors.newFixedThreadPool(preferences.downloadThreads());
|
||||
|
||||
downloadsSubscription = downloadsQueueSubject
|
||||
.concatMap(downloads -> Observable.from(downloads)
|
||||
.flatMap(this::downloadChapter, preferences.downloadThreads()))
|
||||
.onBackpressureBuffer()
|
||||
.flatMap(Observable::from)
|
||||
.flatMap(c -> downloadChapter(c).subscribeOn(Schedulers.from(threadPool)))
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(download -> areAllDownloadsFinished())
|
||||
.subscribe(finished -> {
|
||||
@ -94,6 +99,10 @@ public class DownloadManager {
|
||||
downloadsSubscription.unsubscribe();
|
||||
downloadsSubscription = null;
|
||||
}
|
||||
|
||||
if (threadPool != null && !threadPool.isShutdown()) {
|
||||
threadPool.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a download object for every chapter in the event and add them to the downloads queue
|
||||
@ -181,8 +190,7 @@ public class DownloadManager {
|
||||
// Or if the page list already exists, start from the file
|
||||
Observable.just(download.pages);
|
||||
|
||||
return pageListObservable
|
||||
.subscribeOn(Schedulers.io())
|
||||
return Observable.defer(() -> pageListObservable
|
||||
.doOnNext(pages -> {
|
||||
download.downloadedImages = 0;
|
||||
download.setStatus(Download.DOWNLOADING);
|
||||
@ -199,7 +207,7 @@ public class DownloadManager {
|
||||
.onErrorResumeNext(error -> {
|
||||
download.setStatus(Download.ERROR);
|
||||
return Observable.just(download);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// Get the image from the filesystem if it exists or download from network
|
||||
|
@ -42,7 +42,11 @@ public class RecentChaptersPresenter extends BasePresenter<RecentChaptersFragmen
|
||||
}
|
||||
|
||||
private Observable<List<Object>> getRecentChaptersObservable() {
|
||||
return db.getRecentChapters().asRxObservable()
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.add(Calendar.MONTH, -1);
|
||||
|
||||
return db.getRecentChapters(cal.getTime()).asRxObservable()
|
||||
// group chapters by the date they were fetched on a ordered map
|
||||
.flatMap(recents -> Observable.from(recents)
|
||||
.toMultimap(
|
||||
|
Loading…
Reference in New Issue
Block a user