From f4f89119220540ac158f5a018309992939acf730 Mon Sep 17 00:00:00 2001 From: X1nto Date: Tue, 24 Aug 2021 12:23:26 +0400 Subject: [PATCH] improved version selector --- .../com/vanced/manager/di/MapperModule.kt | 9 ++------- .../downloader/impl/MusicDownloader.kt | 9 +++++++-- .../downloader/impl/VancedDownloader.kt | 20 +++++++++++++++---- .../manager/network/model/AppDtoMapper.kt | 19 +++++++++++++----- .../java/com/vanced/manager/util/AppHelper.kt | 13 ++++++++++++ 5 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/com/vanced/manager/util/AppHelper.kt diff --git a/app/src/main/java/com/vanced/manager/di/MapperModule.kt b/app/src/main/java/com/vanced/manager/di/MapperModule.kt index c789da08..c55cc79b 100644 --- a/app/src/main/java/com/vanced/manager/di/MapperModule.kt +++ b/app/src/main/java/com/vanced/manager/di/MapperModule.kt @@ -1,17 +1,12 @@ package com.vanced.manager.di -import com.vanced.manager.domain.datasource.PackageInformationDataSource import com.vanced.manager.network.model.AppDtoMapper import com.vanced.manager.network.model.JsonDtoMapper import org.koin.dsl.module val mapperModule = module { - fun provideAppMapper( - packageInformationDataSource: PackageInformationDataSource, - ): AppDtoMapper = AppDtoMapper( - packageInformationDataSource = packageInformationDataSource - ) + fun provideAppMapper(): AppDtoMapper = AppDtoMapper() fun provideJsonMapper( appDtoMapper: AppDtoMapper @@ -19,6 +14,6 @@ val mapperModule = module { appDtoMapper = appDtoMapper ) - single { provideAppMapper(get()) } + single { provideAppMapper() } single { provideJsonMapper(get()) } } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/downloader/impl/MusicDownloader.kt b/app/src/main/java/com/vanced/manager/downloader/impl/MusicDownloader.kt index 35b6448d..9fbcb16c 100644 --- a/app/src/main/java/com/vanced/manager/downloader/impl/MusicDownloader.kt +++ b/app/src/main/java/com/vanced/manager/downloader/impl/MusicDownloader.kt @@ -7,6 +7,7 @@ import com.vanced.manager.installer.impl.MusicInstaller import com.vanced.manager.preferences.holder.managerVariantPref import com.vanced.manager.preferences.holder.musicVersionPref import com.vanced.manager.ui.viewmodel.MainViewModel +import com.vanced.manager.util.getLatestOrProvidedAppVersion class MusicDownloader( musicInstaller: MusicInstaller, @@ -23,16 +24,20 @@ class MusicDownloader( app: App, viewModel: MainViewModel ) { + val correctVersion = getLatestOrProvidedAppVersion( + version = version, + app = app + ) downloadFile( file = File( call = musicAPI.getFiles( - version = version, + version = correctVersion, variant = variant, ), fileName = "music.apk" ), viewModel = viewModel, - folderStructure = "$version/$variant" + folderStructure = "$correctVersion/$variant" ) } diff --git a/app/src/main/java/com/vanced/manager/downloader/impl/VancedDownloader.kt b/app/src/main/java/com/vanced/manager/downloader/impl/VancedDownloader.kt index e02989de..7e119808 100644 --- a/app/src/main/java/com/vanced/manager/downloader/impl/VancedDownloader.kt +++ b/app/src/main/java/com/vanced/manager/downloader/impl/VancedDownloader.kt @@ -10,6 +10,7 @@ import com.vanced.manager.preferences.holder.vancedThemePref import com.vanced.manager.preferences.holder.vancedVersionPref import com.vanced.manager.ui.viewmodel.MainViewModel import com.vanced.manager.util.arch +import com.vanced.manager.util.getLatestOrProvidedAppVersion import com.vanced.manager.util.log class VancedDownloader( @@ -29,22 +30,32 @@ class VancedDownloader( app: App, viewModel: MainViewModel ) { + val correctVersion = getLatestOrProvidedAppVersion( + version = version, + app = app + ) val files = listOf( getFile( type = "Theme", - apkName = "$theme.apk" + apkName = "$theme.apk", + version = correctVersion ), getFile( type = "Arch", - apkName = "split_config.$arch.apk" + apkName = "split_config.$arch.apk", + version = correctVersion ) ) + languages.map { language -> - getFile("Language", "split_config.$language.apk") + getFile( + type = "Language", + apkName = "split_config.$language.apk", + version = correctVersion + ) } downloadFiles( files = files, viewModel, - folderStructure = "$version/$variant", + folderStructure = "$correctVersion/$variant", onError = { log("error", it) } @@ -54,6 +65,7 @@ class VancedDownloader( private fun getFile( type: String, apkName: String, + version: String, ) = File( call = vancedAPI.getFiles( version = version, diff --git a/app/src/main/java/com/vanced/manager/network/model/AppDtoMapper.kt b/app/src/main/java/com/vanced/manager/network/model/AppDtoMapper.kt index f0f2102c..6c105ac4 100644 --- a/app/src/main/java/com/vanced/manager/network/model/AppDtoMapper.kt +++ b/app/src/main/java/com/vanced/manager/network/model/AppDtoMapper.kt @@ -1,5 +1,6 @@ package com.vanced.manager.network.model +import android.content.Context import com.vanced.manager.R import com.vanced.manager.domain.datasource.PackageInformationDataSource import com.vanced.manager.domain.model.App @@ -23,11 +24,19 @@ import com.vanced.manager.ui.widget.screens.home.installation.InstallationOption import com.vanced.manager.ui.widget.screens.home.installation.RadiobuttonInstallationOption import org.koin.core.component.KoinComponent import org.koin.core.component.get +import org.koin.core.component.inject import java.util.* -class AppDtoMapper( - private val packageInformationDataSource: PackageInformationDataSource -) : EntityMapper, KoinComponent { +class AppDtoMapper : EntityMapper, KoinComponent { + + private val packageInformationDataSource: PackageInformationDataSource by inject() + private val context: Context by inject() + + private val latestVersionRadioButton = + RadioButtonPreference( + title = context.getString(R.string.app_version_dialog_option_latest), + key = "latest" + ) override suspend fun mapToModel(entity: AppDto): App = with (entity) { @@ -90,7 +99,7 @@ class AppDtoMapper( title = it, key = it ) - } ?: emptyList() + }?.plus(latestVersionRadioButton)?.reversed() ?: emptyList() ), CheckboxInstallationOption( titleId = R.string.app_installation_options_language, @@ -112,7 +121,7 @@ class AppDtoMapper( title = it, key = it ) - } ?: emptyList() + }?.plus(latestVersionRadioButton)?.reversed() ?: emptyList() ), ) else -> null diff --git a/app/src/main/java/com/vanced/manager/util/AppHelper.kt b/app/src/main/java/com/vanced/manager/util/AppHelper.kt new file mode 100644 index 00000000..bd7abb3c --- /dev/null +++ b/app/src/main/java/com/vanced/manager/util/AppHelper.kt @@ -0,0 +1,13 @@ +package com.vanced.manager.util + +import com.vanced.manager.domain.model.App + +fun getLatestOrProvidedAppVersion( + version: String, + app: App +): String { + if (version == "latest") { + return app.versions?.last() ?: version + } + return version +} \ No newline at end of file