From e088d053abb38b0409734c2828ab7b2a58974541 Mon Sep 17 00:00:00 2001 From: CnC-Robert Date: Sat, 3 Jun 2023 23:27:01 +0200 Subject: [PATCH] feat: rename ViewModels for consistency --- .../java/app/revanced/manager/compose/di/ViewModelModule.kt | 4 ++-- .../manager/compose/ui/component/sources/SourceItem.kt | 4 ++-- .../revanced/manager/compose/ui/screen/InstallerScreen.kt | 4 ++-- .../app/revanced/manager/compose/ui/screen/SourcesScreen.kt | 6 +++--- .../{InstallerScreenViewModel.kt => InstallerViewModel.kt} | 3 +-- .../{SourcesScreenViewModel.kt => SourcesViewModel.kt} | 5 +---- 6 files changed, 11 insertions(+), 15 deletions(-) rename app/src/main/java/app/revanced/manager/compose/ui/viewmodel/{InstallerScreenViewModel.kt => InstallerViewModel.kt} (98%) rename app/src/main/java/app/revanced/manager/compose/ui/viewmodel/{SourcesScreenViewModel.kt => SourcesViewModel.kt} (86%) diff --git a/app/src/main/java/app/revanced/manager/compose/di/ViewModelModule.kt b/app/src/main/java/app/revanced/manager/compose/di/ViewModelModule.kt index db485ac6..d4327d63 100644 --- a/app/src/main/java/app/revanced/manager/compose/di/ViewModelModule.kt +++ b/app/src/main/java/app/revanced/manager/compose/di/ViewModelModule.kt @@ -9,7 +9,7 @@ val viewModelModule = module { viewModelOf(::PatchesSelectorViewModel) viewModelOf(::SettingsViewModel) viewModelOf(::AppSelectorViewModel) - viewModelOf(::SourcesScreenViewModel) - viewModelOf(::InstallerScreenViewModel) + viewModelOf(::SourcesViewModel) + viewModelOf(::InstallerViewModel) viewModelOf(::UpdateSettingsViewModel) } diff --git a/app/src/main/java/app/revanced/manager/compose/ui/component/sources/SourceItem.kt b/app/src/main/java/app/revanced/manager/compose/ui/component/sources/SourceItem.kt index 3df4d285..e1bf2d35 100644 --- a/app/src/main/java/app/revanced/manager/compose/ui/component/sources/SourceItem.kt +++ b/app/src/main/java/app/revanced/manager/compose/ui/component/sources/SourceItem.kt @@ -17,7 +17,7 @@ import app.revanced.manager.compose.R import app.revanced.manager.compose.domain.sources.LocalSource import app.revanced.manager.compose.domain.sources.RemoteSource import app.revanced.manager.compose.domain.sources.Source -import app.revanced.manager.compose.ui.viewmodel.SourcesScreenViewModel +import app.revanced.manager.compose.ui.viewmodel.SourcesViewModel import app.revanced.manager.compose.util.uiSafe import kotlinx.coroutines.launch import java.io.InputStream @@ -108,7 +108,7 @@ private fun RemoteSourceItem(source: RemoteSource) { Button(onClick = { coroutineScope.launch { - uiSafe(androidContext, R.string.source_download_fail, SourcesScreenViewModel.failLogMsg) { + uiSafe(androidContext, R.string.source_download_fail, SourcesViewModel.failLogMsg) { source.update() } } diff --git a/app/src/main/java/app/revanced/manager/compose/ui/screen/InstallerScreen.kt b/app/src/main/java/app/revanced/manager/compose/ui/screen/InstallerScreen.kt index fb24c018..678b2e1f 100644 --- a/app/src/main/java/app/revanced/manager/compose/ui/screen/InstallerScreen.kt +++ b/app/src/main/java/app/revanced/manager/compose/ui/screen/InstallerScreen.kt @@ -33,7 +33,7 @@ import app.revanced.manager.compose.patcher.worker.StepGroup import app.revanced.manager.compose.patcher.worker.StepStatus import app.revanced.manager.compose.ui.component.AppScaffold import app.revanced.manager.compose.ui.component.AppTopBar -import app.revanced.manager.compose.ui.viewmodel.InstallerScreenViewModel +import app.revanced.manager.compose.ui.viewmodel.InstallerViewModel import app.revanced.manager.compose.util.APK_MIMETYPE import kotlin.math.floor @@ -41,7 +41,7 @@ import kotlin.math.floor @Composable fun InstallerScreen( onBackClick: () -> Unit, - vm: InstallerScreenViewModel + vm: InstallerViewModel ) { val exportApkLauncher = rememberLauncherForActivityResult(CreateDocument(APK_MIMETYPE), vm::export) diff --git a/app/src/main/java/app/revanced/manager/compose/ui/screen/SourcesScreen.kt b/app/src/main/java/app/revanced/manager/compose/ui/screen/SourcesScreen.kt index 5d5a4215..89b51a1c 100644 --- a/app/src/main/java/app/revanced/manager/compose/ui/screen/SourcesScreen.kt +++ b/app/src/main/java/app/revanced/manager/compose/ui/screen/SourcesScreen.kt @@ -10,12 +10,12 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import app.revanced.manager.compose.R import app.revanced.manager.compose.ui.component.sources.NewSourceDialog import app.revanced.manager.compose.ui.component.sources.SourceItem -import app.revanced.manager.compose.ui.viewmodel.SourcesScreenViewModel +import app.revanced.manager.compose.ui.viewmodel.SourcesViewModel import kotlinx.coroutines.launch import org.koin.androidx.compose.getViewModel @Composable -fun SourcesScreen(vm: SourcesScreenViewModel = getViewModel()) { +fun SourcesScreen(vm: SourcesViewModel = getViewModel()) { var showNewSourceDialog by rememberSaveable { mutableStateOf(false) } val scope = rememberCoroutineScope() @@ -39,7 +39,7 @@ fun SourcesScreen(vm: SourcesScreenViewModel = getViewModel()) { Column( modifier = Modifier - .fillMaxWidth(), + .fillMaxSize(), ) { sources.forEach { (name, source) -> SourceItem( diff --git a/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/InstallerScreenViewModel.kt b/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/InstallerViewModel.kt similarity index 98% rename from app/src/main/java/app/revanced/manager/compose/ui/viewmodel/InstallerScreenViewModel.kt rename to app/src/main/java/app/revanced/manager/compose/ui/viewmodel/InstallerViewModel.kt index deb43afd..b0ad5a1f 100644 --- a/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/InstallerScreenViewModel.kt +++ b/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/InstallerViewModel.kt @@ -5,7 +5,6 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter -import android.content.pm.PackageInfo import android.content.pm.PackageInstaller import android.net.Uri import androidx.compose.runtime.derivedStateOf @@ -33,7 +32,7 @@ import org.koin.core.component.inject import java.io.File import java.nio.file.Files -class InstallerScreenViewModel( +class InstallerViewModel( input: AppInfo, selectedPatches: PatchesSelection ) : ViewModel(), KoinComponent { diff --git a/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/SourcesScreenViewModel.kt b/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/SourcesViewModel.kt similarity index 86% rename from app/src/main/java/app/revanced/manager/compose/ui/viewmodel/SourcesScreenViewModel.kt rename to app/src/main/java/app/revanced/manager/compose/ui/viewmodel/SourcesViewModel.kt index 1d7fe50b..114a505a 100644 --- a/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/SourcesScreenViewModel.kt +++ b/app/src/main/java/app/revanced/manager/compose/ui/viewmodel/SourcesViewModel.kt @@ -3,9 +3,6 @@ package app.revanced.manager.compose.ui.viewmodel import android.app.Application import android.content.ContentResolver import android.net.Uri -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import app.revanced.manager.compose.R @@ -15,7 +12,7 @@ import app.revanced.manager.compose.util.uiSafe import io.ktor.http.* import kotlinx.coroutines.launch -class SourcesScreenViewModel(private val app: Application, private val sourceRepository: SourceRepository) : ViewModel() { +class SourcesViewModel(private val app: Application, private val sourceRepository: SourceRepository) : ViewModel() { val sources = sourceRepository.sources private val contentResolver: ContentResolver = app.contentResolver