0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-25 20:55:12 +00:00

improved version selector

This commit is contained in:
X1nto 2021-08-24 12:23:26 +04:00
parent 02a3bd87b3
commit f4f8911922
5 changed files with 52 additions and 18 deletions

View file

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

View file

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

View file

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

View file

@ -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<AppDto, App>, KoinComponent {
class AppDtoMapper : EntityMapper<AppDto, App>, 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

View file

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