From 7adb545c3e0cd5249dbabf5c3cc0f3ffcad72ba7 Mon Sep 17 00:00:00 2001 From: Gouri Panda Date: Tue, 3 Jan 2023 15:08:50 +0530 Subject: [PATCH] Migrated of FetchDownload --- .../zimManager/ZimManageViewModel.kt | 3 +- .../libraryView/AvailableSpaceCalculator.kt | 3 +- .../kiwix/kiwixmobile/core/StorageObserver.kt | 3 +- .../core/dao/FetchDownloadRoomDao.kt | 134 ++++++++++++++++++ .../dao/entities/FetchDownloadRoomEntity.kt | 98 +++++++++++++ .../core/data/local/KiwixRoomDatabase.kt | 10 +- .../core/di/components/CoreComponent.kt | 2 + .../core/di/modules/DatabaseModule.kt | 4 + .../core/di/modules/DownloaderModule.kt | 3 +- .../core/downloader/DownloaderImpl.kt | 3 +- .../downloader/fetch/FetchDownloadMonitor.kt | 16 ++- .../core/downloader/model/DownloadModel.kt | 14 ++ .../core/entity/LibraryNetworkEntity.kt | 3 + .../adapter/BooksOnDiskListItem.kt | 6 + .../download/CustomDownloadViewModel.kt | 5 +- 15 files changed, 295 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/dao/FetchDownloadRoomDao.kt create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadRoomEntity.kt diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt index bd9a84a06..c5c3bad49 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt @@ -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, diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt index 1c466ef14..913178d04 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/libraryView/AvailableSpaceCalculator.kt @@ -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( diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt index a92a178aa..ec6246402 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt @@ -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 ) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/FetchDownloadRoomDao.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/FetchDownloadRoomDao.kt new file mode 100644 index 000000000..37b1fb680 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/FetchDownloadRoomDao.kt @@ -0,0 +1,134 @@ +/* + * Kiwix Android + * Copyright (c) 2023 Kiwix + * 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 . + * + */ + +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> + + @Query("SELECT * FROM FetchDownloadRoomEntity") + abstract fun downloadsAsEntity2(): List + + @Query("SELECT * FROM FetchDownloadRoomEntity WHERE bookId LIKE :id") + abstract fun getBook(id: String): FetchDownloadRoomEntity? + + fun downloads(): Flowable> = downloadsAsEntity() + .distinctUntilChanged() + .doOnNext(::moveCompletedToBooksOnDiskDao) + .map { + it.map(::DownloadModel) + } + + fun allDownloads() = Single.fromCallable { + downloadsAsEntity2().map(::DownloadModel) + } + + @Transaction + open fun moveCompletedToBooksOnDiskDao(downloadEntities: List) { + 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() { + @TypeConverter + override fun convertToEntityProperty(databaseValue: Int) = Status.valueOf(databaseValue) +} + +class ErrorConverter : EnumConverter() { + @TypeConverter + override fun convertToEntityProperty(databaseValue: Int) = Error.valueOf(databaseValue) +} + +abstract class BaseEnumConverter> { + @TypeConverter + fun convertToEntityProperty(entityProperty: E): Int = entityProperty.ordinal +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadRoomEntity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadRoomEntity.kt new file mode 100644 index 000000000..57a08fb74 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/FetchDownloadRoomEntity.kt @@ -0,0 +1,98 @@ +/* + * Kiwix Android + * Copyright (c) 2023 Kiwix + * 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 . + * + */ + +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 + ) +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt index 22067f54d..fe6f20c1a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/data/local/KiwixRoomDatabase.kt @@ -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 diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt index 5cf11ee4f..870b80cab 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt @@ -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 diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt index b9d8d0a64..120488913 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt @@ -96,4 +96,8 @@ open class DatabaseModule { @Singleton @Provides fun provideLanguageRoomDao(db: KiwixRoomDatabase) = db.languageRoomDao() + + @Singleton + @Provides + fun provideFetchDownloadRoomDao(db: KiwixRoomDatabase) = db.fetchDownloadRoomDao() } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt index 29b26fc56..b5bc210bb 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt @@ -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) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt index 908b91817..3d7d42ce8 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt @@ -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 { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt index 1bf34b1fa..34d13285b 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadMonitor.kt @@ -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) } } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadModel.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadModel.kt index a1261029a..b2c708b74 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadModel.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/model/DownloadModel.kt @@ -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() + ) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt index 0f894e138..fc275d6bf 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/entity/LibraryNetworkEntity.kt @@ -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 diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/adapter/BooksOnDiskListItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/adapter/BooksOnDiskListItem.kt index 73ce4cc03..41fb7cea2 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/adapter/BooksOnDiskListItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/adapter/BooksOnDiskListItem.kt @@ -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 diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt index 5920ec6bc..a8dc0203c 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/download/CustomDownloadViewModel.kt @@ -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(