From dbc4a28e089785121d2688c5ada06c8ae9ddfe2d Mon Sep 17 00:00:00 2001 From: lisonge Date: Mon, 19 Aug 2024 00:24:04 +0800 Subject: [PATCH] perf: rm hilt --- app/build.gradle.kts | 5 ---- app/src/main/kotlin/li/songe/gkd/App.kt | 2 -- .../main/kotlin/li/songe/gkd/MainActivity.kt | 5 ++-- .../kotlin/li/songe/gkd/ui/ActivityLogPage.kt | 4 ++-- .../kotlin/li/songe/gkd/ui/ActivityLogVm.kt | 6 +---- .../kotlin/li/songe/gkd/ui/AdvancedPage.kt | 4 ++-- .../main/kotlin/li/songe/gkd/ui/AdvancedVm.kt | 5 +--- .../kotlin/li/songe/gkd/ui/AppConfigPage.kt | 4 ++-- .../kotlin/li/songe/gkd/ui/AppConfigVm.kt | 5 +--- .../kotlin/li/songe/gkd/ui/AppItemPage.kt | 8 +++---- .../main/kotlin/li/songe/gkd/ui/AppItemVm.kt | 5 +--- .../kotlin/li/songe/gkd/ui/CategoryPage.kt | 4 ++-- .../main/kotlin/li/songe/gkd/ui/CategoryVm.kt | 5 +--- .../kotlin/li/songe/gkd/ui/ClickLogPage.kt | 4 ++-- .../main/kotlin/li/songe/gkd/ui/ClickLogVm.kt | 5 +--- .../li/songe/gkd/ui/GlobalRuleExcludePage.kt | 24 +++++++++---------- .../li/songe/gkd/ui/GlobalRuleExcludeVm.kt | 5 +--- .../kotlin/li/songe/gkd/ui/GlobalRulePage.kt | 8 +++---- .../kotlin/li/songe/gkd/ui/GlobalRuleVm.kt | 5 +--- .../kotlin/li/songe/gkd/ui/SnapshotPage.kt | 4 ++-- .../main/kotlin/li/songe/gkd/ui/SnapshotVm.kt | 6 +---- .../main/kotlin/li/songe/gkd/ui/SubsPage.kt | 6 ++--- app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt | 5 +--- .../li/songe/gkd/ui/home/AppListPage.kt | 4 ++-- .../li/songe/gkd/ui/home/ControlPage.kt | 4 ++-- .../kotlin/li/songe/gkd/ui/home/HomePage.kt | 4 ++-- .../kotlin/li/songe/gkd/ui/home/HomeVm.kt | 13 ++++++---- .../li/songe/gkd/ui/home/SettingsPage.kt | 4 ++-- .../li/songe/gkd/ui/home/SubsManagePage.kt | 4 ++-- build.gradle.kts | 1 - gradle/libs.versions.toml | 5 ---- 31 files changed, 65 insertions(+), 108 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 834d878..fcdbb07 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -44,7 +44,6 @@ plugins { alias(libs.plugins.kotlin.serialization) alias(libs.plugins.kotlin.compose) alias(libs.plugins.google.ksp) - alias(libs.plugins.google.hilt) alias(libs.plugins.rikka.refine) } @@ -243,10 +242,6 @@ dependencies { implementation(libs.destinations.core) ksp(libs.destinations.ksp) - implementation(libs.google.hilt.android) - ksp(libs.google.hilt.android.compiler) - implementation(libs.androidx.hilt.navigation.compose) - implementation(libs.reorderable) implementation(libs.androidx.splashscreen) diff --git a/app/src/main/kotlin/li/songe/gkd/App.kt b/app/src/main/kotlin/li/songe/gkd/App.kt index 9e3ee09..87ce962 100644 --- a/app/src/main/kotlin/li/songe/gkd/App.kt +++ b/app/src/main/kotlin/li/songe/gkd/App.kt @@ -8,7 +8,6 @@ import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.Utils import com.hjq.toast.Toaster import com.tencent.mmkv.MMKV -import dagger.hilt.android.HiltAndroidApp import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope import li.songe.gkd.debug.clearHttpSubs @@ -38,7 +37,6 @@ val applicationInfo by lazy { val channel by lazy { applicationInfo.metaData.getString("channel") } -@HiltAndroidApp class App : Application() { override fun attachBaseContext(base: Context?) { super.attachBaseContext(base) diff --git a/app/src/main/kotlin/li/songe/gkd/MainActivity.kt b/app/src/main/kotlin/li/songe/gkd/MainActivity.kt index 052ab68..fcd7304 100644 --- a/app/src/main/kotlin/li/songe/gkd/MainActivity.kt +++ b/app/src/main/kotlin/li/songe/gkd/MainActivity.kt @@ -14,7 +14,6 @@ import com.blankj.utilcode.util.ServiceUtils import com.dylanc.activityresult.launcher.PickContentLauncher import com.dylanc.activityresult.launcher.StartActivityLauncher import com.ramcosta.composedestinations.DestinationsNavHost -import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update @@ -42,7 +41,6 @@ import li.songe.gkd.util.launchTry import li.songe.gkd.util.map import li.songe.gkd.util.storeFlow -@AndroidEntryPoint class MainActivity : CompositionActivity({ this as MainActivity useLifeCycleLog() @@ -120,7 +118,8 @@ class MainActivity : CompositionActivity({ activityVisibleFlow.update { it - 1 } } - var lastBackPressedTime = 0L + private var lastBackPressedTime = 0L + @Suppress("OVERRIDE_DEPRECATION") override fun onBackPressed() { // onBackPressedDispatcher.addCallback is not work, it will be covered by compose navigation diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt index 290200f..8dd449b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogPage.kt @@ -29,8 +29,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import com.ramcosta.composedestinations.annotation.Destination @@ -52,7 +52,7 @@ import li.songe.gkd.util.throttle fun ActivityLogPage() { val context = LocalContext.current as MainActivity val mainVm = context.mainVm - val vm = hiltViewModel() + val vm = viewModel() val navController = LocalNavController.current val logCount by vm.logCountFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogVm.kt index a4e2c20..df056bb 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ActivityLogVm.kt @@ -1,19 +1,15 @@ package li.songe.gkd.ui -import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.cachedIn -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet -import javax.inject.Inject -@HiltViewModel -class ActivityLogVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class ActivityLogVm : ViewModel() { val pagingDataFlow = Pager(PagingConfig(pageSize = 100)) { DbSet.activityLogDao.pagingSource() } .flow.cachedIn(viewModelScope) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt index efab05b..08876fb 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AdvancedPage.kt @@ -52,8 +52,8 @@ import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.core.content.ContextCompat -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.LogUtils import com.dylanc.activityresult.launcher.launchForResult import com.ramcosta.composedestinations.annotation.Destination @@ -107,7 +107,7 @@ import rikka.shizuku.Shizuku @Composable fun AdvancedPage() { val context = LocalContext.current as MainActivity - val vm = hiltViewModel() + val vm = viewModel() val launcher = LocalLauncher.current val navController = LocalNavController.current val store by storeFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AdvancedVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/AdvancedVm.kt index fca08d1..dc88865 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AdvancedVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AdvancedVm.kt @@ -2,16 +2,13 @@ package li.songe.gkd.ui import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.UploadOptions -import javax.inject.Inject -@HiltViewModel -class AdvancedVm @Inject constructor() : ViewModel() { +class AdvancedVm : ViewModel() { val snapshotCountFlow = DbSet.snapshotDao.count().stateIn(viewModelScope, SharingStarted.Eagerly, 0) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt index 967fa43..afc888a 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt @@ -46,8 +46,8 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph import com.ramcosta.composedestinations.navigation.navigate @@ -80,7 +80,7 @@ import li.songe.gkd.util.throttle @Composable fun AppConfigPage(appId: String) { val navController = LocalNavController.current - val vm = hiltViewModel() + val vm = viewModel() val ruleSortType by vm.ruleSortTypeFlow.collectAsState() val appInfoCache by appInfoCacheFlow.collectAsState() val appInfo = appInfoCache[appId] diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt index c66889d..c9355d9 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigVm.kt @@ -3,7 +3,6 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine @@ -20,10 +19,8 @@ import li.songe.gkd.util.collator import li.songe.gkd.util.getGroupRawEnable import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow -import javax.inject.Inject -@HiltViewModel -class AppConfigVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class AppConfigVm (stateHandle: SavedStateHandle) : ViewModel() { private val args = AppConfigPageDestination.argsFrom(stateHandle) private val latestGlobalLogsFlow = DbSet.clickLogDao.queryAppLatest( diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt index 87dd14f..aa17f87 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt @@ -51,8 +51,8 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination @@ -75,7 +75,6 @@ import li.songe.gkd.util.LocalMainViewModel import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.appInfoCacheFlow -import li.songe.json5.encodeToJson5String import li.songe.gkd.util.getGroupRawEnable import li.songe.gkd.util.json import li.songe.gkd.util.launchAsFn @@ -84,6 +83,7 @@ import li.songe.gkd.util.throttle import li.songe.gkd.util.toast import li.songe.gkd.util.updateSubscription import li.songe.json5.Json5 +import li.songe.json5.encodeToJson5String @RootNavGraph @Destination(style = ProfileTransitions::class) @@ -95,7 +95,7 @@ fun AppItemPage( ) { val navController = LocalNavController.current val mainVm = LocalMainViewModel.current - val vm = hiltViewModel() + val vm = viewModel() val subsItem = vm.subsItemFlow.collectAsState().value val subsRaw = vm.subsRawFlow.collectAsState().value val subsConfigs by vm.subsConfigsFlow.collectAsState() @@ -285,7 +285,7 @@ fun AppItemPage( }, ) } - if (editable && subsRaw != null) { + if (editable && subsRaw != null && subsItem != null) { DropdownMenuItem( text = { Text(text = "删除", color = MaterialTheme.colorScheme.error) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt index 8a68807..40fc54f 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemVm.kt @@ -3,7 +3,6 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn @@ -13,10 +12,8 @@ import li.songe.gkd.ui.destinations.AppItemPageDestination import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow -import javax.inject.Inject -@HiltViewModel -class AppItemVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class AppItemVm (stateHandle: SavedStateHandle) : ViewModel() { private val args = AppItemPageDestination.argsFrom(stateHandle) val subsItemFlow = diff --git a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt index 886c3cf..80f6a82 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/CategoryPage.kt @@ -42,8 +42,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph import kotlinx.coroutines.Dispatchers @@ -72,7 +72,7 @@ fun CategoryPage(subsItemId: Long) { val navController = LocalNavController.current val mainVm = LocalMainViewModel.current - val vm = hiltViewModel() + val vm = viewModel() val subsItem by vm.subsItemFlow.collectAsState() val subsRaw by vm.subsRawFlow.collectAsState() val categoryConfigs by vm.categoryConfigsFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt index 5589cc0..831d7ab 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/CategoryVm.kt @@ -3,7 +3,6 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet @@ -11,10 +10,8 @@ import li.songe.gkd.ui.destinations.CategoryPageDestination import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow -import javax.inject.Inject -@HiltViewModel -class CategoryVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class CategoryVm (stateHandle: SavedStateHandle) : ViewModel() { private val args = CategoryPageDestination.argsFrom(stateHandle) val subsItemFlow = diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt index a82d15e..c8adbca 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogPage.kt @@ -38,8 +38,8 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import com.ramcosta.composedestinations.annotation.Destination @@ -78,7 +78,7 @@ fun ClickLogPage() { val context = LocalContext.current as MainActivity val mainVm = context.mainVm val navController = LocalNavController.current - val vm = hiltViewModel() + val vm = viewModel() val clickLogCount by vm.clickLogCountFlow.collectAsState() val clickDataItems = vm.pagingDataFlow.collectAsLazyPagingItems() val appInfoCache by appInfoCacheFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogVm.kt index 793886b..b9d400a 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/ClickLogVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/ClickLogVm.kt @@ -6,7 +6,6 @@ import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.cachedIn import androidx.paging.map -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn @@ -14,10 +13,8 @@ import li.songe.gkd.data.SubsConfig import li.songe.gkd.data.Tuple3 import li.songe.gkd.db.DbSet import li.songe.gkd.util.subsIdToRawFlow -import javax.inject.Inject -@HiltViewModel -class ClickLogVm @Inject constructor() : ViewModel() { +class ClickLogVm : ViewModel() { val pagingDataFlow = Pager(PagingConfig(pageSize = 100)) { DbSet.clickLogDao.pagingSource() } .flow.cachedIn(viewModelScope) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt index f760b9e..011097b 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt @@ -56,8 +56,8 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.google.accompanist.drawablepainter.rememberDrawablePainter import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph @@ -84,7 +84,7 @@ import li.songe.gkd.util.toast @Composable fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) { val navController = LocalNavController.current - val vm = hiltViewModel() + val vm = viewModel() val rawSubs = vm.rawSubsFlow.collectAsState().value val group = vm.groupFlow.collectAsState().value val excludeData = vm.excludeDataFlow.collectAsState().value @@ -221,17 +221,15 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) { ) DropdownMenuItem( text = { - Row( - verticalAlignment = Alignment.CenterVertically - ) { - Checkbox( - checked = showHiddenApp, - onCheckedChange = { - vm.showHiddenAppFlow.value = - !vm.showHiddenAppFlow.value - }) - Text("显示隐藏应用") - } + Text("显示隐藏应用") + }, + trailingIcon = { + Checkbox( + checked = showHiddenApp, + onCheckedChange = { + vm.showHiddenAppFlow.value = + !vm.showHiddenAppFlow.value + }) }, onClick = { vm.showHiddenAppFlow.value = !vm.showHiddenAppFlow.value diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt index e7129ea..3a39b90 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludeVm.kt @@ -3,7 +3,6 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine @@ -17,10 +16,8 @@ import li.songe.gkd.util.SortTypeOption import li.songe.gkd.util.map import li.songe.gkd.util.orderedAppInfosFlow import li.songe.gkd.util.subsIdToRawFlow -import javax.inject.Inject -@HiltViewModel -class GlobalRuleExcludeVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class GlobalRuleExcludeVm (stateHandle: SavedStateHandle) : ViewModel() { private val args = GlobalRuleExcludePageDestination.argsFrom(stateHandle) val rawSubsFlow = subsIdToRawFlow.map(viewModelScope) { it[args.subsItemId] } diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt index 396e89a..17685d5 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt @@ -52,8 +52,8 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination @@ -72,13 +72,13 @@ import li.songe.gkd.ui.style.itemPadding import li.songe.gkd.util.LocalMainViewModel import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions -import li.songe.json5.encodeToJson5String import li.songe.gkd.util.json import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.launchTry import li.songe.gkd.util.throttle import li.songe.gkd.util.toast import li.songe.gkd.util.updateSubscription +import li.songe.json5.encodeToJson5String @RootNavGraph @Destination(style = ProfileTransitions::class) @@ -86,7 +86,7 @@ import li.songe.gkd.util.updateSubscription fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { val navController = LocalNavController.current val mainVm = LocalMainViewModel.current - val vm = hiltViewModel() + val vm = viewModel() val subsItem by vm.subsItemFlow.collectAsState() val rawSubs = vm.subsRawFlow.collectAsState().value val subsConfigs by vm.subsConfigsFlow.collectAsState() @@ -246,7 +246,7 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { ) } ) - if (editable) { + if (editable && rawSubs != null) { DropdownMenuItem( text = { Text(text = "删除", color = MaterialTheme.colorScheme.error) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt index 728b09c..d6c18b0 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleVm.kt @@ -3,7 +3,6 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet @@ -11,10 +10,8 @@ import li.songe.gkd.ui.destinations.GlobalRulePageDestination import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow -import javax.inject.Inject -@HiltViewModel -class GlobalRuleVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class GlobalRuleVm (stateHandle: SavedStateHandle) : ViewModel() { private val args = GlobalRulePageDestination.argsFrom(stateHandle) val subsItemFlow = subsItemsFlow.map(viewModelScope) { s -> s.find { v -> v.id == args.subsItemId } } diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt index 8e7a119..50d0866 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotPage.kt @@ -38,8 +38,8 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.ClipboardUtils import com.blankj.utilcode.util.ImageUtils import com.blankj.utilcode.util.UriUtils @@ -80,7 +80,7 @@ fun SnapshotPage() { val pickContentLauncher = LocalPickContentLauncher.current - val vm = hiltViewModel() + val vm = viewModel() val snapshots by vm.snapshotsState.collectAsState() vm.uploadOptions.ShowDialog() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotVm.kt index cdb7615..c5eb2d5 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SnapshotVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SnapshotVm.kt @@ -2,17 +2,13 @@ package li.songe.gkd.ui import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn import li.songe.gkd.db.DbSet import li.songe.gkd.ui.component.UploadOptions import li.songe.gkd.util.IMPORT_BASE_URL -import javax.inject.Inject - -@HiltViewModel -class SnapshotVm @Inject constructor() : ViewModel() { +class SnapshotVm : ViewModel() { val snapshotsState = DbSet.snapshotDao.query() .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList()) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt index 3a2d3b0..c4ebfd5 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SubsPage.kt @@ -44,8 +44,8 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph @@ -65,13 +65,13 @@ import li.songe.gkd.util.LocalNavController import li.songe.gkd.util.ProfileTransitions import li.songe.gkd.util.SortTypeOption import li.songe.gkd.util.appInfoCacheFlow -import li.songe.json5.encodeToJson5String import li.songe.gkd.util.json import li.songe.gkd.util.launchAsFn import li.songe.gkd.util.launchTry import li.songe.gkd.util.throttle import li.songe.gkd.util.toast import li.songe.gkd.util.updateSubscription +import li.songe.json5.encodeToJson5String @RootNavGraph @@ -83,7 +83,7 @@ fun SubsPage( val navController = LocalNavController.current val mainVm = LocalMainViewModel.current - val vm = hiltViewModel() + val vm = viewModel() val subsItem = vm.subsItemFlow.collectAsState().value val appAndConfigs by vm.filterAppAndConfigsFlow.collectAsState() val searchStr by vm.searchStrFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt index e96b64f..d634070 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/SubsVm.kt @@ -3,7 +3,6 @@ package li.songe.gkd.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine @@ -22,10 +21,8 @@ import li.songe.gkd.util.getGroupRawEnable import li.songe.gkd.util.map import li.songe.gkd.util.subsIdToRawFlow import li.songe.gkd.util.subsItemsFlow -import javax.inject.Inject -@HiltViewModel -class SubsVm @Inject constructor(stateHandle: SavedStateHandle) : ViewModel() { +class SubsVm (stateHandle: SavedStateHandle) : ViewModel() { private val args = SubsPageDestination.argsFrom(stateHandle) val subsItemFlow = diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt index 481d336..20471bd 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/AppListPage.kt @@ -58,8 +58,8 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.KeyboardUtils import com.google.accompanist.drawablepainter.rememberDrawablePainter import com.ramcosta.composedestinations.navigation.navigate @@ -91,7 +91,7 @@ fun useAppListPage(): ScaffoldExt { val context = LocalContext.current as MainActivity val softwareKeyboardController = LocalSoftwareKeyboardController.current - val vm = hiltViewModel() + val vm = viewModel() val showSystemApp by vm.showSystemAppFlow.collectAsState() val showHiddenApp by vm.showHiddenAppFlow.collectAsState() val sortType by vm.sortTypeFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt index f78dc0d..d511234 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/ControlPage.kt @@ -26,8 +26,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.ramcosta.composedestinations.navigation.navigate import li.songe.gkd.MainActivity import li.songe.gkd.permission.notificationState @@ -57,7 +57,7 @@ val controlNav = BottomNavItem(label = "主页", icon = Icons.Outlined.Home) fun useControlPage(): ScaffoldExt { val context = LocalContext.current as MainActivity val navController = LocalNavController.current - val vm = hiltViewModel() + val vm = viewModel() val latestRecordDesc by vm.latestRecordDescFlow.collectAsState() val subsStatus by vm.subsStatusFlow.collectAsState() val store by storeFlow.collectAsState() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt index 755550a..8bdf8d2 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt @@ -12,8 +12,8 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalContext -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.blankj.utilcode.util.LogUtils import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph @@ -36,7 +36,7 @@ data class BottomNavItem( @Composable fun HomePage() { val context = LocalContext.current as MainActivity - val vm = hiltViewModel() + val vm = viewModel() val tab by vm.tabFlow.collectAsState() val controlPage = useControlPage() diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/HomeVm.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/HomeVm.kt index 1a53cfc..edc1566 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/HomeVm.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/HomeVm.kt @@ -1,10 +1,10 @@ package li.songe.gkd.ui.home import android.webkit.URLUtil +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.blankj.utilcode.util.LogUtils -import dagger.hilt.android.lifecycle.HiltViewModel import io.ktor.client.request.get import io.ktor.client.statement.bodyAsText import kotlinx.coroutines.Dispatchers @@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch import li.songe.gkd.appScope import li.songe.gkd.data.RawSubscription import li.songe.gkd.data.SubsItem @@ -33,10 +34,14 @@ import li.songe.gkd.util.subsItemsFlow import li.songe.gkd.util.subsRefreshingFlow import li.songe.gkd.util.toast import li.songe.gkd.util.updateSubscription -import javax.inject.Inject -@HiltViewModel -class HomeVm @Inject constructor() : ViewModel() { +class HomeVm(stateHandle: SavedStateHandle) : ViewModel() { + init { + viewModelScope.launch { + LogUtils.d(this, stateHandle) + } + } + val tabFlow = MutableStateFlow(controlNav) private val latestRecordFlow = diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt index ec12b27..e13fec3 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt @@ -35,8 +35,8 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.ramcosta.composedestinations.navigation.navigate import kotlinx.coroutines.flow.update import li.songe.gkd.BuildConfig @@ -73,7 +73,7 @@ fun useSettingsPage(): ScaffoldExt { val mainVm = LocalMainViewModel.current val navController = LocalNavController.current val store by storeFlow.collectAsState() - val vm = hiltViewModel() + val vm = viewModel() var showToastInputDlg by remember { mutableStateOf(false) diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt index abf92ad..19436bc 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt @@ -54,8 +54,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel import com.dylanc.activityresult.launcher.launchForResult import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.Dispatchers @@ -101,7 +101,7 @@ fun useSubsManagePage(): ScaffoldExt { val launcher = LocalLauncher.current val mainVm = LocalMainViewModel.current - val vm = hiltViewModel() + val vm = viewModel() val subItems by subsItemsFlow.collectAsState() val subsIdToRaw by subsIdToRawFlow.collectAsState() diff --git a/build.gradle.kts b/build.gradle.kts index 61106fa..ae7d81e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,6 @@ buildscript { plugins { alias(libs.plugins.google.ksp) apply false - alias(libs.plugins.google.hilt) apply false alias(libs.plugins.android.library) apply false alias(libs.plugins.android.application) apply false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2c90dc9..b26878f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,6 @@ rikka = "4.4.0" room = "2.6.1" paging = "3.3.2" ktor = "2.3.12" -hilt = "2.52" destinations = "1.10.2" coil = "2.7.0" @@ -57,9 +56,6 @@ ktor_client_content_negotiation = { module = "io.ktor:ktor-client-content-negoti ktor_serialization_kotlinx_json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } kotlinx_serialization_json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.7.1" } kotlinx_collections_immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version = "0.3.7" } -google_hilt_android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" } -google_hilt_android_compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" } -androidx_hilt_navigation_compose = { module = "androidx.hilt:hilt-navigation-compose", version = "1.2.0" } destinations_core = { module = "io.github.raamcosta.compose-destinations:core", version.ref = "destinations" } destinations_ksp = { module = "io.github.raamcosta.compose-destinations:ksp", version.ref = "destinations" } coil_compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" } @@ -80,5 +76,4 @@ kotlin_android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin_compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } rikka_refine = { id = "dev.rikka.tools.refine", version.ref = "rikka" } google_ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } -google_hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } androidx_room = { id = "androidx.room", version.ref = "room" }