optimise sum imports, fix two active strategies

This commit is contained in:
white
2025-10-12 19:48:44 +03:00
parent 0b69d2bf4d
commit 4786ef8faf
3 changed files with 4 additions and 17 deletions

View File

@@ -38,7 +38,9 @@ import com.cherret.zaprett.R
import com.cherret.zaprett.data.StrategyCheckResult import com.cherret.zaprett.data.StrategyCheckResult
import com.cherret.zaprett.ui.viewmodel.BaseRepoViewModel import com.cherret.zaprett.ui.viewmodel.BaseRepoViewModel
import com.cherret.zaprett.utils.RepoItemInfo import com.cherret.zaprett.utils.RepoItemInfo
import com.cherret.zaprett.utils.disableStrategy
import com.cherret.zaprett.utils.enableStrategy import com.cherret.zaprett.utils.enableStrategy
import com.cherret.zaprett.utils.getActiveStrategy
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
@@ -203,6 +205,7 @@ fun StrategySelectionItem(strategy : StrategyCheckResult, prefs : SharedPreferen
) )
FilledTonalIconButton( FilledTonalIconButton(
onClick = { onClick = {
disableStrategy(getActiveStrategy(prefs)[0], prefs)
enableStrategy(strategy.path, prefs) enableStrategy(strategy.path, prefs)
scope.launch { scope.launch {
snackbarHostState.showSnackbar( snackbarHostState.showSnackbar(

View File

@@ -1,17 +1,13 @@
package com.cherret.zaprett.ui.screen package com.cherret.zaprett.ui.screen
import android.content.Context.MODE_PRIVATE import android.content.Context.MODE_PRIVATE
import android.util.Log
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHost
@@ -33,15 +29,12 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Info import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.FilledIconButton
import androidx.compose.material3.FilledTonalButton import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController import androidx.navigation.NavController

View File

@@ -5,11 +5,7 @@ import android.content.Context.MODE_PRIVATE
import android.content.Intent import android.content.Intent
import android.util.Log import android.util.Log
import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.cherret.zaprett.R import com.cherret.zaprett.R
import com.cherret.zaprett.byedpi.ByeDpiVpnService import com.cherret.zaprett.byedpi.ByeDpiVpnService
import com.cherret.zaprett.data.ServiceStatus import com.cherret.zaprett.data.ServiceStatus
@@ -17,8 +13,6 @@ import com.cherret.zaprett.data.StrategyCheckResult
import com.cherret.zaprett.utils.disableStrategy import com.cherret.zaprett.utils.disableStrategy
import com.cherret.zaprett.utils.enableStrategy import com.cherret.zaprett.utils.enableStrategy
import com.cherret.zaprett.utils.getActiveLists import com.cherret.zaprett.utils.getActiveLists
import com.cherret.zaprett.utils.getActiveStrategy
import com.cherret.zaprett.utils.getAllNfqwsStrategies
import com.cherret.zaprett.utils.getAllStrategies import com.cherret.zaprett.utils.getAllStrategies
import com.cherret.zaprett.utils.getStatus import com.cherret.zaprett.utils.getStatus
import com.cherret.zaprett.utils.startService import com.cherret.zaprett.utils.startService
@@ -28,7 +22,6 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.withTimeoutOrNull
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
@@ -86,7 +79,6 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
suspend fun readActiveListsLines(): List<String> = withContext(Dispatchers.IO) { suspend fun readActiveListsLines(): List<String> = withContext(Dispatchers.IO) {
val result = mutableListOf<String>() val result = mutableListOf<String>()
getActiveLists(prefs).forEach { path -> getActiveLists(prefs).forEach { path ->
runCatching { runCatching {
File(path).useLines { lines -> File(path).useLines { lines ->
@@ -106,7 +98,6 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
for (index in strategyStates.indices) { for (index in strategyStates.indices) {
val current = strategyStates[index] val current = strategyStates[index]
strategyStates[index] = current.copy(status = R.string.strategy_status_testing) strategyStates[index] = current.copy(status = R.string.strategy_status_testing)
enableStrategy(current.path, prefs) enableStrategy(current.path, prefs)
if (prefs.getBoolean("use_module", false)) { if (prefs.getBoolean("use_module", false)) {
@@ -147,8 +138,8 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
if (connected) delay(150L) if (connected) delay(150L)
try { try {
val progress = countReachable(targets) val progress = countReachable(targets)
val old = strategyStates[index] val old = strategyStates[index]
strategyStates[index] = old.copy( strategyStates[index] = old.copy(
progress = progress, progress = progress,
status = R.string.strategy_status_tested status = R.string.strategy_status_tested