Refactoring

This commit is contained in:
shabinder 2021-08-23 22:51:27 +05:30
parent 59068c6c8b
commit bfb0f800ad
5 changed files with 27 additions and 20 deletions

View File

@ -81,6 +81,7 @@ class ForegroundService : LifecycleService() {
inner class DownloadServiceBinder : Binder() { inner class DownloadServiceBinder : Binder() {
val service get() = this@ForegroundService val service get() = this@ForegroundService
} }
private val myBinder: IBinder = DownloadServiceBinder() private val myBinder: IBinder = DownloadServiceBinder()
override fun onBind(intent: Intent): IBinder { override fun onBind(intent: Intent): IBinder {
@ -304,12 +305,16 @@ class ForegroundService : LifecycleService() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (isFinished) { killService() } if (isFinished) {
killService()
}
} }
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent) super.onTaskRemoved(rootIntent)
if (isFinished) { killService() } if (isFinished) {
killService()
}
} }
companion object { companion object {

View File

@ -22,12 +22,14 @@ import co.touchlab.kermit.Kermit
import com.mpatric.mp3agic.InvalidDataException import com.mpatric.mp3agic.InvalidDataException
import com.mpatric.mp3agic.Mp3File import com.mpatric.mp3agic.Mp3File
import com.shabinder.common.core_components.media_converter.MediaConverter import com.shabinder.common.core_components.media_converter.MediaConverter
import com.shabinder.common.core_components.parallel_executor.ParallelExecutor
import com.shabinder.common.core_components.picture.Picture import com.shabinder.common.core_components.picture.Picture
import com.shabinder.common.core_components.preference_manager.PreferenceManager import com.shabinder.common.core_components.preference_manager.PreferenceManager
import com.shabinder.common.core_components.removeAllTags import com.shabinder.common.core_components.removeAllTags
import com.shabinder.common.core_components.setId3v1Tags import com.shabinder.common.core_components.setId3v1Tags
import com.shabinder.common.core_components.setId3v2TagsAndSaveFile import com.shabinder.common.core_components.setId3v2TagsAndSaveFile
import com.shabinder.common.database.SpotiFlyerDatabase import com.shabinder.common.database.SpotiFlyerDatabase
import com.shabinder.common.models.DownloadStatus
import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.TrackDetails
import com.shabinder.common.models.dispatcherIO import com.shabinder.common.models.dispatcherIO
import com.shabinder.common.models.event.coroutines.SuspendableEvent import com.shabinder.common.models.event.coroutines.SuspendableEvent
@ -36,6 +38,7 @@ import com.shabinder.common.models.event.coroutines.map
import com.shabinder.database.Database import com.shabinder.database.Database
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.skija.Image import org.jetbrains.skija.Image
@ -50,10 +53,15 @@ import java.net.HttpURLConnection
import java.net.URL import java.net.URL
import javax.imageio.ImageIO import javax.imageio.ImageIO
actual internal fun fileManagerModule() = module { internal actual fun fileManagerModule() = module {
single { DesktopFileManager(get(), get(), get(), get()) } bind FileManager::class single { DesktopFileManager(get(), get(), get(), get()) } bind FileManager::class
} }
val DownloadProgressFlow: MutableSharedFlow<HashMap<String, DownloadStatus>> = MutableSharedFlow(1)
// Scope Allowing 4 Parallel Downloads
val DownloadScope = ParallelExecutor(Dispatchers.IO)
class DesktopFileManager( class DesktopFileManager(
override val logger: Kermit, override val logger: Kermit,
override val preferenceManager: PreferenceManager, override val preferenceManager: PreferenceManager,

View File

@ -17,9 +17,7 @@
package com.shabinder.common.core_components.file_manager package com.shabinder.common.core_components.file_manager
import co.touchlab.kermit.Kermit import co.touchlab.kermit.Kermit
import com.shabinder.common.core_components.DownloadProgressFlow
import com.shabinder.common.core_components.ID3Writer import com.shabinder.common.core_components.ID3Writer
import com.shabinder.common.core_components.allTracksStatus
import com.shabinder.common.core_components.media_converter.MediaConverter import com.shabinder.common.core_components.media_converter.MediaConverter
import com.shabinder.common.core_components.picture.Picture import com.shabinder.common.core_components.picture.Picture
import com.shabinder.common.core_components.preference_manager.PreferenceManager import com.shabinder.common.core_components.preference_manager.PreferenceManager
@ -34,6 +32,7 @@ import com.shabinder.common.utils.removeIllegalChars
import com.shabinder.database.Database import com.shabinder.database.Database
import kotlinext.js.Object import kotlinext.js.Object
import kotlinext.js.js import kotlinext.js.js
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.ArrayBuffer
import org.khronos.webgl.Int8Array import org.khronos.webgl.Int8Array
@ -142,3 +141,9 @@ class WebFileManager(
fun ByteArray.toArrayBuffer(): ArrayBuffer { fun ByteArray.toArrayBuffer(): ArrayBuffer {
return this.unsafeCast<Int8Array>().buffer return this.unsafeCast<Int8Array>().buffer
} }
val DownloadProgressFlow: MutableSharedFlow<HashMap<String, DownloadStatus>> = MutableSharedFlow(1)
// Error:https://github.com/Kotlin/kotlinx.atomicfu/issues/182
// val DownloadScope = ParallelExecutor(Dispatchers.Default) //Download Pool of 4 parallel
val allTracksStatus: HashMap<String, DownloadStatus> = hashMapOf()

View File

@ -16,22 +16,16 @@
package com.shabinder.common.providers package com.shabinder.common.providers
import com.shabinder.common.core_components.file_manager.DownloadProgressFlow
import com.shabinder.common.core_components.file_manager.DownloadScope
import com.shabinder.common.core_components.file_manager.FileManager import com.shabinder.common.core_components.file_manager.FileManager
import com.shabinder.common.core_components.file_manager.downloadFile import com.shabinder.common.core_components.file_manager.downloadFile
import com.shabinder.common.core_components.parallel_executor.ParallelExecutor
import com.shabinder.common.models.DownloadResult import com.shabinder.common.models.DownloadResult
import com.shabinder.common.models.DownloadStatus import com.shabinder.common.models.DownloadStatus
import com.shabinder.common.models.SpotiFlyerException import com.shabinder.common.models.SpotiFlyerException
import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.TrackDetails
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
val DownloadProgressFlow: MutableSharedFlow<HashMap<String, DownloadStatus>> = MutableSharedFlow(1)
// Scope Allowing 4 Parallel Downloads
val DownloadScope = ParallelExecutor(Dispatchers.IO)
actual suspend fun downloadTracks( actual suspend fun downloadTracks(
list: List<TrackDetails>, list: List<TrackDetails>,
fetcher: FetchPlatformQueryResult, fetcher: FetchPlatformQueryResult,

View File

@ -16,19 +16,14 @@
package com.shabinder.common.providers package com.shabinder.common.providers
import com.shabinder.common.core_components.file_manager.DownloadProgressFlow
import com.shabinder.common.core_components.file_manager.FileManager import com.shabinder.common.core_components.file_manager.FileManager
import com.shabinder.common.core_components.file_manager.allTracksStatus
import com.shabinder.common.core_components.file_manager.downloadFile import com.shabinder.common.core_components.file_manager.downloadFile
import com.shabinder.common.models.* import com.shabinder.common.models.*
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
val DownloadProgressFlow: MutableSharedFlow<HashMap<String, DownloadStatus>> = MutableSharedFlow(1)
// Error:https://github.com/Kotlin/kotlinx.atomicfu/issues/182
// val DownloadScope = ParallelExecutor(Dispatchers.Default) //Download Pool of 4 parallel
val allTracksStatus: HashMap<String, DownloadStatus> = hashMapOf()
actual suspend fun downloadTracks( actual suspend fun downloadTracks(
list: List<TrackDetails>, list: List<TrackDetails>,
fetcher: FetchPlatformQueryResult, fetcher: FetchPlatformQueryResult,