Migrated of FetchDownload

This commit is contained in:
Gouri Panda 2023-01-03 15:08:50 +05:30
parent 1f97e09eb7
commit 7adb545c3e
15 changed files with 295 additions and 12 deletions

View File

@ -36,6 +36,7 @@ import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.StorageObserver import org.kiwix.kiwixmobile.core.StorageObserver
import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.LanguageRoomDao
import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewBookDao
import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
@ -80,7 +81,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject import javax.inject.Inject
class ZimManageViewModel @Inject constructor( class ZimManageViewModel @Inject constructor(
private val downloadDao: FetchDownloadDao, private val downloadDao: FetchDownloadRoomDao,
private val bookDao: NewBookDao, private val bookDao: NewBookDao,
private val languageDao: LanguageRoomDao, private val languageDao: LanguageRoomDao,
private val storageObserver: StorageObserver, private val storageObserver: StorageObserver,

View File

@ -23,13 +23,14 @@ import eu.mhutti1.utils.storage.Kb
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.downloader.model.DownloadModel
import org.kiwix.kiwixmobile.core.settings.StorageCalculator import org.kiwix.kiwixmobile.core.settings.StorageCalculator
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem
import javax.inject.Inject import javax.inject.Inject
class AvailableSpaceCalculator @Inject constructor( class AvailableSpaceCalculator @Inject constructor(
private val downloadDao: FetchDownloadDao, private val downloadDao: FetchDownloadRoomDao,
private val storageCalculator: StorageCalculator private val storageCalculator: StorageCalculator
) { ) {
fun hasAvailableSpaceFor( fun hasAvailableSpaceFor(

View File

@ -22,6 +22,7 @@ import io.reactivex.Flowable
import io.reactivex.functions.BiFunction import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.downloader.model.DownloadModel
import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.utils.files.FileSearch import org.kiwix.kiwixmobile.core.utils.files.FileSearch
@ -30,7 +31,7 @@ import java.io.File
import javax.inject.Inject import javax.inject.Inject
class StorageObserver @Inject constructor( class StorageObserver @Inject constructor(
private val downloadDao: FetchDownloadDao, private val downloadDao: FetchDownloadRoomDao,
private val fileSearch: FileSearch, private val fileSearch: FileSearch,
private val zimReaderFactory: ZimFileReader.Factory private val zimReaderFactory: ZimFileReader.Factory
) { ) {

View File

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

View File

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

View File

@ -29,24 +29,30 @@ import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.SupportSQLiteDatabase
import io.objectbox.BoxStore import io.objectbox.BoxStore
import io.objectbox.kotlin.boxFor 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.LanguageRoomDao
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchRoomDao import org.kiwix.kiwixmobile.core.dao.NewRecentSearchRoomDao
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao 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.StringToLocalConverterDao
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadRoomEntity
import org.kiwix.kiwixmobile.core.dao.entities.LanguageRoomEntity import org.kiwix.kiwixmobile.core.dao.entities.LanguageRoomEntity
import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity
import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
@Suppress("UnnecessaryAbstractClass") @Suppress("UnnecessaryAbstractClass")
@Database( @Database(
entities = [RecentSearchRoomEntity::class, NotesRoomEntity::class, LanguageRoomEntity::class], entities = [RecentSearchRoomEntity::class, NotesRoomEntity::class, LanguageRoomEntity::class, FetchDownloadRoomEntity::class],
version = 2 version = 2
) )
@TypeConverters(StringToLocalConverterDao::class) @TypeConverters(StringToLocalConverterDao::class, StatusConverter::class, ErrorConverter::class)
abstract class KiwixRoomDatabase : RoomDatabase() { abstract class KiwixRoomDatabase : RoomDatabase() {
abstract fun newRecentSearchRoomDao(): NewRecentSearchRoomDao abstract fun newRecentSearchRoomDao(): NewRecentSearchRoomDao
abstract fun noteRoomDao(): NotesRoomDao abstract fun noteRoomDao(): NotesRoomDao
abstract fun languageRoomDao(): LanguageRoomDao abstract fun languageRoomDao(): LanguageRoomDao
abstract fun fetchDownloadRoomDao(): FetchDownloadRoomDao
companion object { companion object {
private var db: KiwixRoomDatabase? = null private var db: KiwixRoomDatabase? = null

View File

@ -27,6 +27,7 @@ import eu.mhutti1.utils.storage.StorageSelectDialog
import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.StorageObserver import org.kiwix.kiwixmobile.core.StorageObserver
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.HistoryDao
import org.kiwix.kiwixmobile.core.dao.LanguageRoomDao import org.kiwix.kiwixmobile.core.dao.LanguageRoomDao
import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewBookDao
@ -93,6 +94,7 @@ interface CoreComponent {
// fun noteDao(): NewNoteDao // fun noteDao(): NewNoteDao
fun languageRoomDao(): LanguageRoomDao fun languageRoomDao(): LanguageRoomDao
fun fetchDownloadRoomDao(): FetchDownloadRoomDao
fun newLanguagesDao(): NewLanguagesDao fun newLanguagesDao(): NewLanguagesDao
fun recentSearchDao(): NewRecentSearchDao fun recentSearchDao(): NewRecentSearchDao
fun recentSearchRoomDao(): NewRecentSearchRoomDao fun recentSearchRoomDao(): NewRecentSearchRoomDao

View File

@ -96,4 +96,8 @@ open class DatabaseModule {
@Singleton @Singleton
@Provides @Provides
fun provideLanguageRoomDao(db: KiwixRoomDatabase) = db.languageRoomDao() fun provideLanguageRoomDao(db: KiwixRoomDatabase) = db.languageRoomDao()
@Singleton
@Provides
fun provideFetchDownloadRoomDao(db: KiwixRoomDatabase) = db.fetchDownloadRoomDao()
} }

View File

@ -28,6 +28,7 @@ import dagger.Provides
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.kiwix.kiwixmobile.core.BuildConfig import org.kiwix.kiwixmobile.core.BuildConfig
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.data.remote.KiwixService
import org.kiwix.kiwixmobile.core.downloader.DownloadRequester import org.kiwix.kiwixmobile.core.downloader.DownloadRequester
import org.kiwix.kiwixmobile.core.downloader.Downloader import org.kiwix.kiwixmobile.core.downloader.Downloader
@ -46,7 +47,7 @@ object DownloaderModule {
@Singleton @Singleton
fun providesDownloader( fun providesDownloader(
downloadRequester: DownloadRequester, downloadRequester: DownloadRequester,
downloadDao: FetchDownloadDao, downloadDao: FetchDownloadRoomDao,
kiwixService: KiwixService kiwixService: KiwixService
): Downloader = DownloaderImpl(downloadRequester, downloadDao, kiwixService) ): Downloader = DownloaderImpl(downloadRequester, downloadDao, kiwixService)

View File

@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.downloader
import io.reactivex.Observable import io.reactivex.Observable
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.data.remote.KiwixService
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
@ -27,7 +28,7 @@ import javax.inject.Inject
class DownloaderImpl @Inject constructor( class DownloaderImpl @Inject constructor(
private val downloadRequester: DownloadRequester, private val downloadRequester: DownloadRequester,
private val downloadDao: FetchDownloadDao, private val downloadDao: FetchDownloadRoomDao,
private val kiwixService: KiwixService private val kiwixService: KiwixService
) : Downloader { ) : Downloader {

View File

@ -25,10 +25,14 @@ import com.tonyodev.fetch2core.DownloadBlock
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.PublishSubject
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao
import org.kiwix.kiwixmobile.core.dao.FetchDownloadRoomDao
import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor
import javax.inject.Inject import javax.inject.Inject
class FetchDownloadMonitor @Inject constructor(fetch: Fetch, fetchDownloadDao: FetchDownloadDao) : class FetchDownloadMonitor @Inject constructor(
fetch: Fetch,
fetchDownloadDao: FetchDownloadRoomDao
) :
DownloadMonitor { DownloadMonitor {
private val updater = PublishSubject.create<() -> Unit>() private val updater = PublishSubject.create<() -> Unit>()
private val fetchListener = object : FetchListener { private val fetchListener = object : FetchListener {
@ -95,11 +99,17 @@ class FetchDownloadMonitor @Inject constructor(fetch: Fetch, fetchDownloadDao: F
} }
private fun update(download: Download) { 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) { private fun delete(download: Download) {
updater.onNext { fetchDownloadDao.delete(download) } updater
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.doOnNext { fetchDownloadDao.delete(download) }
} }
} }

View File

@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.downloader.model
import com.tonyodev.fetch2.Error import com.tonyodev.fetch2.Error
import com.tonyodev.fetch2.Status import com.tonyodev.fetch2.Status
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadEntity 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.entity.LibraryNetworkEntity.Book
import org.kiwix.kiwixmobile.core.utils.StorageUtils import org.kiwix.kiwixmobile.core.utils.StorageUtils
@ -50,4 +51,17 @@ data class DownloadModel(
downloadEntity.progress, downloadEntity.progress,
downloadEntity.toBook() 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()
)
} }

View File

@ -17,6 +17,9 @@
*/ */
package org.kiwix.kiwixmobile.core.entity 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.Attribute
import org.simpleframework.xml.ElementList import org.simpleframework.xml.ElementList
import org.simpleframework.xml.Root import org.simpleframework.xml.Root

View File

@ -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.BookOnDiskEntity
import org.kiwix.kiwixmobile.core.dao.entities.FetchDownloadEntity 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.entity.LibraryNetworkEntity.Book
import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag
@ -63,6 +64,11 @@ sealed class BooksOnDiskListItem {
file = File(fetchDownloadEntity.file) file = File(fetchDownloadEntity.file)
) )
constructor(fetchDownloadRoomEntity: FetchDownloadRoomEntity) : this(
book = fetchDownloadRoomEntity.toBook(),
file = File(fetchDownloadRoomEntity.file)
)
constructor(file: File, zimFileReader: ZimFileReader) : this( constructor(file: File, zimFileReader: ZimFileReader) : this(
book = zimFileReader.toBook(), book = zimFileReader.toBook(),
file = file file = file

View File

@ -24,6 +24,7 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.processors.PublishProcessor import io.reactivex.processors.PublishProcessor
import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao 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.DownloadItem
import org.kiwix.kiwixmobile.core.downloader.model.DownloadState.Failed import org.kiwix.kiwixmobile.core.downloader.model.DownloadState.Failed
import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload
@ -39,7 +40,7 @@ import org.kiwix.kiwixmobile.custom.download.effects.SetPreferredStorageWithMost
import javax.inject.Inject import javax.inject.Inject
class CustomDownloadViewModel @Inject constructor( class CustomDownloadViewModel @Inject constructor(
downloadDao: FetchDownloadDao, downloadDao: FetchDownloadRoomDao,
setPreferredStorageWithMostSpace: SetPreferredStorageWithMostSpace, setPreferredStorageWithMostSpace: SetPreferredStorageWithMostSpace,
private val downloadCustom: DownloadCustom, private val downloadCustom: DownloadCustom,
private val navigateToCustomReader: NavigateToCustomReader private val navigateToCustomReader: NavigateToCustomReader
@ -63,7 +64,7 @@ class CustomDownloadViewModel @Inject constructor(
.distinctUntilChanged() .distinctUntilChanged()
.subscribe(state::postValue, Throwable::printStackTrace) .subscribe(state::postValue, Throwable::printStackTrace)
private fun downloadsAsActions(downloadDao: FetchDownloadDao) = private fun downloadsAsActions(downloadDao: FetchDownloadRoomDao) =
downloadDao.downloads() downloadDao.downloads()
.map { it.map(::DownloadItem) } .map { it.map(::DownloadItem) }
.subscribe( .subscribe(