mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +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();
|
.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedGetListOfObjects<MangaChapter> getRecentChapters() {
|
public PreparedGetListOfObjects<MangaChapter> getRecentChapters(Date date) {
|
||||||
return db.get()
|
return db.get()
|
||||||
.listOfObjects(MangaChapter.class)
|
.listOfObjects(MangaChapter.class)
|
||||||
.withQuery(RawQuery.builder()
|
.withQuery(RawQuery.builder()
|
||||||
.query(MangaChapterGetResolver.RECENT_CHAPTERS_QUERY)
|
.query(MangaChapterGetResolver.getRecentChaptersQuery(date))
|
||||||
.observesTables(ChapterTable.TABLE)
|
.observesTables(ChapterTable.TABLE)
|
||||||
.build())
|
.build())
|
||||||
.withGetResolver(MangaChapterGetResolver.INSTANCE)
|
.withGetResolver(MangaChapterGetResolver.INSTANCE)
|
||||||
|
@ -5,6 +5,8 @@ import android.support.annotation.NonNull;
|
|||||||
|
|
||||||
import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver;
|
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.Chapter;
|
||||||
import eu.kanade.tachiyomi.data.database.models.ChapterStorIOSQLiteGetResolver;
|
import eu.kanade.tachiyomi.data.database.models.ChapterStorIOSQLiteGetResolver;
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||||
@ -24,10 +26,12 @@ public class MangaChapterGetResolver extends DefaultGetResolver<MangaChapter> {
|
|||||||
MangaTable.COLUMN_ID,
|
MangaTable.COLUMN_ID,
|
||||||
ChapterTable.COLUMN_MANGA_ID);
|
ChapterTable.COLUMN_MANGA_ID);
|
||||||
|
|
||||||
public static final String RECENT_CHAPTERS_QUERY = String.format(
|
public static String getRecentChaptersQuery(Date date) {
|
||||||
QUERY + " WHERE %1$s = 1 ORDER BY %2$s DESC LIMIT 100",
|
return QUERY + String.format(" WHERE %1$s = 1 AND %2$s > %3$d ORDER BY %2$s DESC",
|
||||||
MangaTable.COLUMN_FAVORITE,
|
MangaTable.COLUMN_FAVORITE,
|
||||||
ChapterTable.COLUMN_DATE_UPLOAD);
|
ChapterTable.COLUMN_DATE_UPLOAD,
|
||||||
|
date.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final MangaStorIOSQLiteGetResolver mangaGetResolver;
|
private final MangaStorIOSQLiteGetResolver mangaGetResolver;
|
||||||
|
@ -15,6 +15,8 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.Chapter;
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||||
@ -48,6 +50,8 @@ public class DownloadManager {
|
|||||||
private DownloadQueue queue;
|
private DownloadQueue queue;
|
||||||
private volatile boolean isRunning;
|
private volatile boolean isRunning;
|
||||||
|
|
||||||
|
private ExecutorService threadPool;
|
||||||
|
|
||||||
public static final String PAGE_LIST_FILE = "index.json";
|
public static final String PAGE_LIST_FILE = "index.json";
|
||||||
|
|
||||||
public DownloadManager(Context context, SourceManager sourceManager, PreferencesHelper preferences) {
|
public DownloadManager(Context context, SourceManager sourceManager, PreferencesHelper preferences) {
|
||||||
@ -66,10 +70,11 @@ public class DownloadManager {
|
|||||||
if (downloadsSubscription != null && !downloadsSubscription.isUnsubscribed())
|
if (downloadsSubscription != null && !downloadsSubscription.isUnsubscribed())
|
||||||
downloadsSubscription.unsubscribe();
|
downloadsSubscription.unsubscribe();
|
||||||
|
|
||||||
|
threadPool = Executors.newFixedThreadPool(preferences.downloadThreads());
|
||||||
|
|
||||||
downloadsSubscription = downloadsQueueSubject
|
downloadsSubscription = downloadsQueueSubject
|
||||||
.concatMap(downloads -> Observable.from(downloads)
|
.flatMap(Observable::from)
|
||||||
.flatMap(this::downloadChapter, preferences.downloadThreads()))
|
.flatMap(c -> downloadChapter(c).subscribeOn(Schedulers.from(threadPool)))
|
||||||
.onBackpressureBuffer()
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map(download -> areAllDownloadsFinished())
|
.map(download -> areAllDownloadsFinished())
|
||||||
.subscribe(finished -> {
|
.subscribe(finished -> {
|
||||||
@ -94,6 +99,10 @@ public class DownloadManager {
|
|||||||
downloadsSubscription.unsubscribe();
|
downloadsSubscription.unsubscribe();
|
||||||
downloadsSubscription = null;
|
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
|
// 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
|
// Or if the page list already exists, start from the file
|
||||||
Observable.just(download.pages);
|
Observable.just(download.pages);
|
||||||
|
|
||||||
return pageListObservable
|
return Observable.defer(() -> pageListObservable
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.doOnNext(pages -> {
|
.doOnNext(pages -> {
|
||||||
download.downloadedImages = 0;
|
download.downloadedImages = 0;
|
||||||
download.setStatus(Download.DOWNLOADING);
|
download.setStatus(Download.DOWNLOADING);
|
||||||
@ -199,7 +207,7 @@ public class DownloadManager {
|
|||||||
.onErrorResumeNext(error -> {
|
.onErrorResumeNext(error -> {
|
||||||
download.setStatus(Download.ERROR);
|
download.setStatus(Download.ERROR);
|
||||||
return Observable.just(download);
|
return Observable.just(download);
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the image from the filesystem if it exists or download from network
|
// 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() {
|
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
|
// group chapters by the date they were fetched on a ordered map
|
||||||
.flatMap(recents -> Observable.from(recents)
|
.flatMap(recents -> Observable.from(recents)
|
||||||
.toMultimap(
|
.toMultimap(
|
||||||
|
Loading…
Reference in New Issue
Block a user