Download manager in Kotlin and fix another crash in reader

This commit is contained in:
len
2016-03-19 00:11:34 +01:00
parent 35748fc1f3
commit aaef738dda
11 changed files with 656 additions and 690 deletions

View File

@@ -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) }

View File

@@ -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()) {

View File

@@ -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())

View File

@@ -243,7 +243,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
}
@Suppress("UNUSED_PARAMETER")
fun onAdjacentChapters(previous: Chapter, next: Chapter) {
fun onAdjacentChapters(previous: Chapter?, next: Chapter?) {
setAdjacentChaptersVisibility()
}

View File

@@ -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) })
}