Merge remote-tracking branch 'origin/main'

This commit is contained in:
CherretGit
2025-10-16 19:46:05 +07:00
4 changed files with 34 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.TextButton
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -45,7 +46,6 @@ import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.cherret.zaprett.R
import com.cherret.zaprett.byedpi.ByeDpiVpnService
import com.cherret.zaprett.ui.component.StrategySelectionItem
import com.cherret.zaprett.ui.viewmodel.StrategySelectionViewModel
import kotlinx.coroutines.launch
@@ -122,6 +122,7 @@ fun StrategySelectionScreen(navController: NavController, vpnLauncher: ActivityR
horizontalArrangement = Arrangement.Center
)
{
NoHostsCard(viewModel.noHostsCard)
FilledTonalButton(
onClick = {
viewModel.viewModelScope.launch {
@@ -175,3 +176,21 @@ fun InfoAlert(onDismiss: () -> Unit) {
)
}
@Composable
private fun NoHostsCard(noHostsCard: MutableState<Boolean>) {
if (noHostsCard.value) {
AlertDialog(
title = { Text(text = stringResource(R.string.selection_no_hosts_title)) },
text = { Text(text = stringResource(R.string.selection_no_hosts_message)) },
onDismissRequest = {
noHostsCard.value = false
},
confirmButton = {
TextButton(onClick = { noHostsCard.value = false }) {
Text(stringResource(R.string.btn_continue))
}
}
)
}
}

View File

@@ -5,6 +5,7 @@ import android.content.Context.MODE_PRIVATE
import android.content.Intent
import android.util.Log
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.core.content.ContextCompat
import androidx.lifecycle.AndroidViewModel
import com.cherret.zaprett.R
@@ -14,6 +15,7 @@ import com.cherret.zaprett.data.StrategyCheckResult
import com.cherret.zaprett.utils.disableStrategy
import com.cherret.zaprett.utils.enableStrategy
import com.cherret.zaprett.utils.getActiveLists
import com.cherret.zaprett.utils.getActiveStrategy
import com.cherret.zaprett.utils.getAllStrategies
import com.cherret.zaprett.utils.getStatus
import com.cherret.zaprett.utils.startService
@@ -41,9 +43,12 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
private val _requestVpnPermission = MutableStateFlow(false)
val requestVpnPermission = _requestVpnPermission.asStateFlow()
val strategyStates = mutableStateListOf<StrategyCheckResult>()
var noHostsCard = mutableStateOf(false)
private set
init {
loadStrategies()
checkHosts()
}
fun loadStrategies() {
@@ -155,6 +160,11 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
strategyStates.clear()
strategyStates.addAll(sorted)
}
fun checkHosts() {
if (getActiveLists(prefs).isEmpty()) noHostsCard.value = true
Log.d("getActiveLists.isEmpty", getActiveLists(prefs).isEmpty().toString())
}
fun startVpn() {
ContextCompat.startForegroundService(context, Intent(context, ByeDpiVpnService::class.java).apply { action = "START_VPN" })
}

View File

@@ -114,4 +114,6 @@
<string name="hint_enter_probe_timeout">Введите таймаут пробы</string>
<string name="strategy_selection_info_title">Информация</string>
<string name="strategy_selection_info_msg">"В этом разделе настроек приложения представлен перебор стратегий\n Подбор проходит среди скачанных стратегий, поэтому заранее скачайте из репозитория или добавьте из файловой системы интересующие вас стратегии для сравнения. \n Перед началом так же выберете один или несколько листов доменов на вкладке \"Листы\", затем нажмите на \"Начать подбор\". Не используйте для перебора списки с большим количеством доменов."</string>
<string name="selection_no_hosts_title">Нет активных листов</string>
<string name="selection_no_hosts_message">Не обнаружено активных списков хостов, включите один или несколько, иначе подбор не сработает</string>
</resources>

View File

@@ -119,4 +119,6 @@
<string name="hint_enter_probe_timeout">Enter probe timeout</string>
<string name="strategy_selection_info_title">Tip</string>
<string name="strategy_selection_info_msg">This section of the application settings allows you to iterate through strategies.\n The selection is based on downloaded strategies, so download the strategies you\'re interested in from the repository or add them from the file system for comparison.\n Before starting, select one or more domain lists in the \"Lists\" tab, then click \"Start selection\". Avoid using lists with a large number of domains.</string>
<string name="selection_no_hosts_title">No active hosts</string>
<string name="selection_no_hosts_message">No active host lists found, please enable one or more, otherwise the selection will not work</string>
</resources>