mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 12:08:56 +01:00
Download manager in Kotlin and fix another crash in reader
This commit is contained in:
@@ -68,14 +68,14 @@ class DownloadPresenter : BasePresenter<DownloadFragment>() {
|
||||
override fun onTakeView(view: DownloadFragment) {
|
||||
super.onTakeView(view)
|
||||
|
||||
statusSubscription = downloadQueue.statusObservable
|
||||
.startWith(downloadQueue.activeDownloads)
|
||||
statusSubscription = downloadQueue.getStatusObservable()
|
||||
.startWith(downloadQueue.getActiveDownloads())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { processStatus(it, view) }
|
||||
|
||||
add(statusSubscription)
|
||||
|
||||
pageProgressSubscription = downloadQueue.progressObservable
|
||||
pageProgressSubscription = downloadQueue.getProgressObservable()
|
||||
.onBackpressureBuffer()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { view.onUpdateDownloadedPages(it) }
|
||||
|
||||
@@ -174,7 +174,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
}
|
||||
|
||||
if (prefFilterDownloaded) {
|
||||
val mangaDir = downloadManager.getAbsoluteMangaDirectory(sourceManager.get(manga.source), manga)
|
||||
val mangaDir = downloadManager.getAbsoluteMangaDirectory(sourceManager.get(manga.source)!!, manga)
|
||||
|
||||
if (mangaDir.exists()) {
|
||||
for (file in mangaDir.listFiles()) {
|
||||
|
||||
@@ -130,7 +130,7 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
|
||||
}
|
||||
|
||||
fun getChapterStatusObs(): Observable<Download> {
|
||||
return downloadManager.queue.statusObservable
|
||||
return downloadManager.queue.getStatusObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter { download -> download.manga.id == manga.id }
|
||||
.doOnNext { updateChapterStatus(it) }
|
||||
@@ -214,7 +214,7 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
|
||||
|
||||
fun deleteChapters(selectedChapters: Observable<Chapter>) {
|
||||
add(selectedChapters.subscribe(
|
||||
{ chapter -> downloadManager.queue.remove(chapter) },
|
||||
{ chapter -> downloadManager.queue.del(chapter) },
|
||||
{ error -> Timber.e(error.message) },
|
||||
{
|
||||
if (onlyDownloaded())
|
||||
|
||||
@@ -243,7 +243,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
fun onAdjacentChapters(previous: Chapter, next: Chapter) {
|
||||
fun onAdjacentChapters(previous: Chapter?, next: Chapter?) {
|
||||
setAdjacentChaptersVisibility()
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
||||
* @return download object containing download progress.
|
||||
*/
|
||||
private fun getChapterStatusObs(): Observable<Download> {
|
||||
return downloadManager.queue.statusObservable
|
||||
return downloadManager.queue.getStatusObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter { download: Download ->
|
||||
if (chapterIdEquals(download.chapter.id))
|
||||
@@ -188,7 +188,7 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
||||
}
|
||||
|
||||
// Get source of chapter
|
||||
val source = sourceManager.get(mangaChapter.manga.source)
|
||||
val source = sourceManager.get(mangaChapter.manga.source)!!
|
||||
|
||||
// Check if chapter is downloaded
|
||||
if (downloadManager.isChapterDownloaded(source, mangaChapter.manga, mangaChapter.chapter)) {
|
||||
@@ -271,7 +271,7 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
||||
* @param manga manga that belongs to chapter
|
||||
*/
|
||||
fun deleteChapter(chapter: Chapter, manga: Manga) {
|
||||
val source = sourceManager.get(manga.source)
|
||||
val source = sourceManager.get(manga.source)!!
|
||||
downloadManager.deleteChapter(source, manga, chapter)
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ class RecentChaptersPresenter : BasePresenter<RecentChaptersFragment>() {
|
||||
fun deleteChapters(selectedChapters: Observable<Chapter>) {
|
||||
add(selectedChapters
|
||||
.subscribe(
|
||||
{ chapter -> downloadManager.queue.remove(chapter) })
|
||||
{ chapter -> downloadManager.queue.del(chapter) })
|
||||
{ error -> Timber.e(error.message) })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user