mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Migrated of FetchDownload
This commit is contained in:
parent
1f97e09eb7
commit
7adb545c3e
@ -36,6 +36,7 @@ import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.StorageObserver
|
||||
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.LanguageRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
|
||||
@ -80,7 +81,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
|
||||
import javax.inject.Inject
|
||||
|
||||
class ZimManageViewModel @Inject constructor(
|
||||
private val downloadDao: FetchDownloadDao,
|
||||
private val downloadDao: FetchDownloadRoomDao,
|
||||
private val bookDao: NewBookDao,
|
||||
private val languageDao: LanguageRoomDao,
|
||||
private val storageObserver: StorageObserver,
|
||||
|
@ -23,13 +23,14 @@ import eu.mhutti1.utils.storage.Kb
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel
|
||||
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
||||
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem
|
||||
import javax.inject.Inject
|
||||
|
||||
class AvailableSpaceCalculator @Inject constructor(
|
||||
private val downloadDao: FetchDownloadDao,
|
||||
private val downloadDao: FetchDownloadRoomDao,
|
||||
private val storageCalculator: StorageCalculator
|
||||
) {
|
||||
fun hasAvailableSpaceFor(
|
||||
|
@ -22,6 +22,7 @@ import io.reactivex.Flowable
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileSearch
|
||||
@ -30,7 +31,7 @@ import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
class StorageObserver @Inject constructor(
|
||||
private val downloadDao: FetchDownloadDao,
|
||||
private val downloadDao: FetchDownloadRoomDao,
|
||||
private val fileSearch: FileSearch,
|
||||
private val zimReaderFactory: ZimFileReader.Factory
|
||||
) {
|
||||
|
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2023 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.TypeConverter
|
||||
import com.tonyodev.fetch2.Download
|
||||
import com.tonyodev.fetch2.Error
|
||||
import com.tonyodev.fetch2.Status
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Single
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.EnumConverter
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.downloader.DownloadRequester
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.DownloadRequest
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
|
||||
import javax.inject.Inject
|
||||
|
||||
@Dao
|
||||
abstract class FetchDownloadRoomDao {
|
||||
@Inject
|
||||
lateinit var newBookDao: NewBookDao
|
||||
|
||||
@Query("SELECT * FROM FetchDownloadRoomEntity")
|
||||
abstract fun downloadsAsEntity(): Flowable<List<FetchDownloadRoomEntity>>
|
||||
|
||||
@Query("SELECT * FROM FetchDownloadRoomEntity")
|
||||
abstract fun downloadsAsEntity2(): List<FetchDownloadRoomEntity>
|
||||
|
||||
@Query("SELECT * FROM FetchDownloadRoomEntity WHERE bookId LIKE :id")
|
||||
abstract fun getBook(id: String): FetchDownloadRoomEntity?
|
||||
|
||||
fun downloads(): Flowable<List<DownloadModel>> = downloadsAsEntity()
|
||||
.distinctUntilChanged()
|
||||
.doOnNext(::moveCompletedToBooksOnDiskDao)
|
||||
.map {
|
||||
it.map(::DownloadModel)
|
||||
}
|
||||
|
||||
fun allDownloads() = Single.fromCallable {
|
||||
downloadsAsEntity2().map(::DownloadModel)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun moveCompletedToBooksOnDiskDao(downloadEntities: List<FetchDownloadRoomEntity>) {
|
||||
downloadEntities.filter { it.status == Status.COMPLETED }.takeIf { it.isNotEmpty() }?.let {
|
||||
newBookDao.insert(it.map(BooksOnDiskListItem::BookOnDisk))
|
||||
it.forEach(::deleteAsEntity)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Delete
|
||||
abstract fun deleteAsEntity(downloadEntity: FetchDownloadRoomEntity)
|
||||
|
||||
@Query("DELETE FROM FetchDownloadRoomEntity WHERE downloadId LIKE :id")
|
||||
abstract fun delete(id: Int)
|
||||
|
||||
fun delete(download: Download) {
|
||||
delete(download.id)
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM FetchDownloadRoomEntity WHERE downloadId LIKE :id")
|
||||
abstract fun getEntityFor(id: Int): FetchDownloadRoomEntity?
|
||||
|
||||
fun getEntityFor(download: Download) = getEntityFor(download.id)
|
||||
|
||||
@Transaction
|
||||
open fun update(download: Download) {
|
||||
getEntityFor(download)?.let { dbEntity ->
|
||||
dbEntity.updateWith(download)
|
||||
.takeIf { updateEntity -> updateEntity != dbEntity }
|
||||
?.let(::insertFetchDownloadEntity)
|
||||
}
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun addIfDoesNotExist(
|
||||
url: String,
|
||||
book: LibraryNetworkEntity.Book,
|
||||
downloadRequester: DownloadRequester
|
||||
) {
|
||||
if (getBook(book.id) == null) {
|
||||
insert(downloadRequester.enqueue(DownloadRequest(url)), book)
|
||||
}
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open fun insert(downloadId: Long, book: LibraryNetworkEntity.Book) {
|
||||
val fetchDownloadRoomEntity = FetchDownloadRoomEntity(downloadId, book)
|
||||
insertFetchDownloadEntity(fetchDownloadRoomEntity)
|
||||
}
|
||||
|
||||
@Insert
|
||||
abstract fun insertFetchDownloadEntity(fetchDownloadRoomEntity: FetchDownloadRoomEntity)
|
||||
}
|
||||
|
||||
class StatusConverter : EnumConverter<Status>() {
|
||||
@TypeConverter
|
||||
override fun convertToEntityProperty(databaseValue: Int) = Status.valueOf(databaseValue)
|
||||
}
|
||||
|
||||
class ErrorConverter : EnumConverter<Error>() {
|
||||
@TypeConverter
|
||||
override fun convertToEntityProperty(databaseValue: Int) = Error.valueOf(databaseValue)
|
||||
}
|
||||
|
||||
abstract class BaseEnumConverter<E : Enum<E>> {
|
||||
@TypeConverter
|
||||
fun convertToEntityProperty(entityProperty: E): Int = entityProperty.ordinal
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2023 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.dao.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.tonyodev.fetch2.Download
|
||||
import com.tonyodev.fetch2.Error
|
||||
import com.tonyodev.fetch2.Status
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||
|
||||
@Entity
|
||||
data class FetchDownloadRoomEntity(
|
||||
@PrimaryKey var id: Long = 0,
|
||||
var downloadId: Long,
|
||||
val file: String? = null,
|
||||
val etaInMilliSeconds: Long = -1L,
|
||||
val bytesDownloaded: Long = -1L,
|
||||
val totalSizeOfDownload: Long = -1L,
|
||||
val status: Status = Status.NONE,
|
||||
val error: Error = Error.NONE,
|
||||
val progress: Int = -1,
|
||||
val bookId: String,
|
||||
val title: String,
|
||||
val description: String?,
|
||||
val language: String,
|
||||
val creator: String,
|
||||
val publisher: String,
|
||||
val date: String,
|
||||
val url: String?,
|
||||
val articleCount: String?,
|
||||
val mediaCount: String?,
|
||||
val size: String,
|
||||
val name: String?,
|
||||
val favIcon: String,
|
||||
val tags: String? = null
|
||||
) {
|
||||
constructor(downloadId: Long, book: LibraryNetworkEntity.Book) : this(
|
||||
downloadId = downloadId,
|
||||
bookId = book.id,
|
||||
title = book.title,
|
||||
description = book.description,
|
||||
language = book.language,
|
||||
creator = book.creator,
|
||||
publisher = book.publisher,
|
||||
date = book.date,
|
||||
url = book.url,
|
||||
articleCount = book.articleCount,
|
||||
mediaCount = book.mediaCount,
|
||||
size = book.size,
|
||||
name = book.bookName,
|
||||
favIcon = book.favicon,
|
||||
tags = book.tags
|
||||
)
|
||||
|
||||
fun toBook() = LibraryNetworkEntity.Book().apply {
|
||||
id = bookId
|
||||
title = this@FetchDownloadRoomEntity.title
|
||||
description = this@FetchDownloadRoomEntity.description
|
||||
language = this@FetchDownloadRoomEntity.language
|
||||
creator = this@FetchDownloadRoomEntity.creator
|
||||
publisher = this@FetchDownloadRoomEntity.publisher
|
||||
date = this@FetchDownloadRoomEntity.date
|
||||
url = this@FetchDownloadRoomEntity.url
|
||||
articleCount = this@FetchDownloadRoomEntity.articleCount
|
||||
mediaCount = this@FetchDownloadRoomEntity.mediaCount
|
||||
size = this@FetchDownloadRoomEntity.size
|
||||
bookName = name
|
||||
favicon = favIcon
|
||||
tags = this@FetchDownloadRoomEntity.tags
|
||||
}
|
||||
|
||||
fun updateWith(download: Download) = copy(
|
||||
file = download.file,
|
||||
etaInMilliSeconds = download.etaInMilliSeconds,
|
||||
bytesDownloaded = download.downloaded,
|
||||
totalSizeOfDownload = download.total,
|
||||
status = download.status,
|
||||
error = download.error,
|
||||
progress = download.progress
|
||||
)
|
||||
}
|
@ -29,24 +29,30 @@ import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import io.objectbox.BoxStore
|
||||
import io.objectbox.kotlin.boxFor
|
||||
import org.kiwix.kiwixmobile.core.dao.ErrorConverter
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.LanguageRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.StatusConverter
|
||||
import org.kiwix.kiwixmobile.core.dao.StringToLocalConverterDao
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.LanguageRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||
|
||||
@Suppress("UnnecessaryAbstractClass")
|
||||
@Database(
|
||||
entities = [RecentSearchRoomEntity::class, NotesRoomEntity::class, LanguageRoomEntity::class],
|
||||
entities = [RecentSearchRoomEntity::class, NotesRoomEntity::class, LanguageRoomEntity::class, FetchDownloadRoomEntity::class],
|
||||
version = 2
|
||||
)
|
||||
@TypeConverters(StringToLocalConverterDao::class)
|
||||
@TypeConverters(StringToLocalConverterDao::class, StatusConverter::class, ErrorConverter::class)
|
||||
abstract class KiwixRoomDatabase : RoomDatabase() {
|
||||
abstract fun newRecentSearchRoomDao(): NewRecentSearchRoomDao
|
||||
abstract fun noteRoomDao(): NotesRoomDao
|
||||
abstract fun languageRoomDao(): LanguageRoomDao
|
||||
abstract fun fetchDownloadRoomDao(): FetchDownloadRoomDao
|
||||
|
||||
companion object {
|
||||
private var db: KiwixRoomDatabase? = null
|
||||
|
@ -27,6 +27,7 @@ import eu.mhutti1.utils.storage.StorageSelectDialog
|
||||
import org.kiwix.kiwixmobile.core.CoreApp
|
||||
import org.kiwix.kiwixmobile.core.StorageObserver
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.HistoryDao
|
||||
import org.kiwix.kiwixmobile.core.dao.LanguageRoomDao
|
||||
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
||||
@ -93,6 +94,7 @@ interface CoreComponent {
|
||||
|
||||
// fun noteDao(): NewNoteDao
|
||||
fun languageRoomDao(): LanguageRoomDao
|
||||
fun fetchDownloadRoomDao(): FetchDownloadRoomDao
|
||||
fun newLanguagesDao(): NewLanguagesDao
|
||||
fun recentSearchDao(): NewRecentSearchDao
|
||||
fun recentSearchRoomDao(): NewRecentSearchRoomDao
|
||||
|
@ -96,4 +96,8 @@ open class DatabaseModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideLanguageRoomDao(db: KiwixRoomDatabase) = db.languageRoomDao()
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideFetchDownloadRoomDao(db: KiwixRoomDatabase) = db.fetchDownloadRoomDao()
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import dagger.Provides
|
||||
import okhttp3.OkHttpClient
|
||||
import org.kiwix.kiwixmobile.core.BuildConfig
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.data.remote.KiwixService
|
||||
import org.kiwix.kiwixmobile.core.downloader.DownloadRequester
|
||||
import org.kiwix.kiwixmobile.core.downloader.Downloader
|
||||
@ -46,7 +47,7 @@ object DownloaderModule {
|
||||
@Singleton
|
||||
fun providesDownloader(
|
||||
downloadRequester: DownloadRequester,
|
||||
downloadDao: FetchDownloadDao,
|
||||
downloadDao: FetchDownloadRoomDao,
|
||||
kiwixService: KiwixService
|
||||
): Downloader = DownloaderImpl(downloadRequester, downloadDao, kiwixService)
|
||||
|
||||
|
@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.downloader
|
||||
|
||||
import io.reactivex.Observable
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.data.remote.KiwixService
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
|
||||
@ -27,7 +28,7 @@ import javax.inject.Inject
|
||||
|
||||
class DownloaderImpl @Inject constructor(
|
||||
private val downloadRequester: DownloadRequester,
|
||||
private val downloadDao: FetchDownloadDao,
|
||||
private val downloadDao: FetchDownloadRoomDao,
|
||||
private val kiwixService: KiwixService
|
||||
) : Downloader {
|
||||
|
||||
|
@ -25,10 +25,14 @@ import com.tonyodev.fetch2core.DownloadBlock
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor
|
||||
import javax.inject.Inject
|
||||
|
||||
class FetchDownloadMonitor @Inject constructor(fetch: Fetch, fetchDownloadDao: FetchDownloadDao) :
|
||||
class FetchDownloadMonitor @Inject constructor(
|
||||
fetch: Fetch,
|
||||
fetchDownloadDao: FetchDownloadRoomDao
|
||||
) :
|
||||
DownloadMonitor {
|
||||
private val updater = PublishSubject.create<() -> Unit>()
|
||||
private val fetchListener = object : FetchListener {
|
||||
@ -95,11 +99,17 @@ class FetchDownloadMonitor @Inject constructor(fetch: Fetch, fetchDownloadDao: F
|
||||
}
|
||||
|
||||
private fun update(download: Download) {
|
||||
updater.onNext { fetchDownloadDao.update(download) }
|
||||
updater
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.computation())
|
||||
.doOnNext { fetchDownloadDao.update(download) }
|
||||
}
|
||||
|
||||
private fun delete(download: Download) {
|
||||
updater.onNext { fetchDownloadDao.delete(download) }
|
||||
updater
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.computation())
|
||||
.doOnNext { fetchDownloadDao.delete(download) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.downloader.model
|
||||
import com.tonyodev.fetch2.Error
|
||||
import com.tonyodev.fetch2.Status
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.core.utils.StorageUtils
|
||||
|
||||
@ -50,4 +51,17 @@ data class DownloadModel(
|
||||
downloadEntity.progress,
|
||||
downloadEntity.toBook()
|
||||
)
|
||||
|
||||
constructor(downloadEntity: FetchDownloadRoomEntity) : this(
|
||||
downloadEntity.id,
|
||||
downloadEntity.downloadId,
|
||||
downloadEntity.file,
|
||||
downloadEntity.etaInMilliSeconds,
|
||||
downloadEntity.bytesDownloaded,
|
||||
downloadEntity.totalSizeOfDownload,
|
||||
downloadEntity.status,
|
||||
downloadEntity.error,
|
||||
downloadEntity.progress,
|
||||
downloadEntity.toBook()
|
||||
)
|
||||
}
|
||||
|
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.core.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.TypeConverter
|
||||
import org.simpleframework.xml.Attribute
|
||||
import org.simpleframework.xml.ElementList
|
||||
import org.simpleframework.xml.Root
|
||||
|
@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter
|
||||
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.BookOnDiskEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadEntity
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadRoomEntity
|
||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag
|
||||
@ -63,6 +64,11 @@ sealed class BooksOnDiskListItem {
|
||||
file = File(fetchDownloadEntity.file)
|
||||
)
|
||||
|
||||
constructor(fetchDownloadRoomEntity: FetchDownloadRoomEntity) : this(
|
||||
book = fetchDownloadRoomEntity.toBook(),
|
||||
file = File(fetchDownloadRoomEntity.file)
|
||||
)
|
||||
|
||||
constructor(file: File, zimFileReader: ZimFileReader) : this(
|
||||
book = zimFileReader.toBook(),
|
||||
file = file
|
||||
|
@ -24,6 +24,7 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.processors.PublishProcessor
|
||||
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
|
||||
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.DownloadState.Failed
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload
|
||||
@ -39,7 +40,7 @@ import org.kiwix.kiwixmobile.custom.download.effects.SetPreferredStorageWithMost
|
||||
import javax.inject.Inject
|
||||
|
||||
class CustomDownloadViewModel @Inject constructor(
|
||||
downloadDao: FetchDownloadDao,
|
||||
downloadDao: FetchDownloadRoomDao,
|
||||
setPreferredStorageWithMostSpace: SetPreferredStorageWithMostSpace,
|
||||
private val downloadCustom: DownloadCustom,
|
||||
private val navigateToCustomReader: NavigateToCustomReader
|
||||
@ -63,7 +64,7 @@ class CustomDownloadViewModel @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.subscribe(state::postValue, Throwable::printStackTrace)
|
||||
|
||||
private fun downloadsAsActions(downloadDao: FetchDownloadDao) =
|
||||
private fun downloadsAsActions(downloadDao: FetchDownloadRoomDao) =
|
||||
downloadDao.downloads()
|
||||
.map { it.map(::DownloadItem) }
|
||||
.subscribe(
|
||||
|
Loading…
x
Reference in New Issue
Block a user