From 20a3406040eef163c52d8b6fb507d192afcf9b3e Mon Sep 17 00:00:00 2001 From: rhenwinch Date: Sat, 9 Nov 2024 00:38:01 +0800 Subject: [PATCH] fix(provider): fix incorrect download path for local updates Former-commit-id: a700c7a5f6aeb307965f994ca21b31825fbec313 --- .../data/provider/ProviderManager.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt b/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt index 58b3ce012..35571b784 100644 --- a/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt +++ b/data/provider/src/main/kotlin/com/flixclusive/data/provider/ProviderManager.kt @@ -260,13 +260,15 @@ class ProviderManager @Inject constructor( suspend fun loadProvider( providerData: ProviderData, - needsDownload: Boolean = false + needsDownload: Boolean = false, + filePath: String? = null ) { check(providerData.repositoryUrl != null) { "Repository URL must not be null if using this overloaded method." } - val file = context.provideValidProviderPath(providerData) + val file = filePath?.let { File(it) } + ?: context.provideValidProviderPath(providerData) if (needsDownload && !downloadProvider(file, providerData.buildUrl!!)) { throw IOException("Something went wrong trying to download the provider.") @@ -516,7 +518,7 @@ class ProviderManager @Inject constructor( private suspend fun reloadProviderOnSettings( oldProviderData: ProviderData, newProviderData: ProviderData - ) { + ): ProviderPreference { val oldOrderPosition = getPositionIndexFromSettings(oldProviderData.name) val oldPreference = appSettingsManager.cachedProviderSettings.providers[oldOrderPosition] @@ -525,14 +527,17 @@ class ProviderManager @Inject constructor( newProviderData, localPrefix = localPrefix ) + val newPreference = oldPreference.copy( + name = newProviderData.name, + filePath = newPath.absolutePath + ) loadProviderOnSettings( - provider = oldPreference.copy( - name = newProviderData.name, - filePath = newPath.absolutePath - ), + provider = newPreference, index = oldOrderPosition ) + + return newPreference } suspend fun reloadProvider( @@ -547,13 +552,14 @@ class ProviderManager @Inject constructor( unloadOnSettings = false ) - reloadProviderOnSettings( + val newProviderPreference = reloadProviderOnSettings( oldProviderData = oldProviderData, newProviderData = newProviderData ) loadProvider( providerData = newProviderData, + filePath = newProviderPreference.filePath, needsDownload = true ) }