18 Commits

Author SHA1 Message Date
zarazaex69 bea7c8a0d3 mv sub 2 down 2026-05-06 01:20:35 +03:00
zarazaex69 45779f0bce add material you color 2026-05-06 01:13:22 +03:00
zarazaex69 642bc7a437 fix server select 2026-05-06 01:03:50 +03:00
zarazaex69 74f6762cf6 fix icon bug 2026-05-06 00:46:34 +03:00
zarazaex69 8aa17ae4bd fix: крестик вместо кнопки Отмена в диалогах + правильная блокировка кнопок
- Все диалоги (обновление, страны) теперь имеют крестик (×) вверху справа вместо кнопки Отмена/Позже
- Добавлен layout dialog_title_with_close.xml с кастомным заголовком и кнопкой закрытия
- Исправлена блокировка кнопок: setButtonsEnabled теперь блокирует и btnSummaryLite тоже
- applyRunningState упрощён — при isRunning разблокирует через setButtonsEnabled
- Во время теста (isTesting): fab/меню блокируются, молния остаётся активной как стоп
- По завершении теста: всё разблокируется корректно
2026-05-06 00:20:21 +03:00
zarazaex69 9f5f3580e0 fix: множество исправлений UI и логики
- Адаптивная иконка: пересоздана с safe-zone отступами (62%) для всех плотностей — лого не обрезается кругом на Android 16
- Строгий таймаут 6 сек: measureOutboundDelayInternal теперь использует context с таймаутом — больше нет бесконечных зависаний пинга
- Индикатор теста: 'Проверено успешно: X / Y' вместо 'Number of running test tasks: left / total'
- Текст начала теста: 'Тестирование N серверов' вместо 'Testing N configs'
- Цвет прогресс-бара: адаптирован к теме (md_theme_primary) вместо оранжевого
- Все диалоги переведены на MaterialAlertDialogBuilder — скруглённые углы, Material3 стиль
- Кнопка FAB '>': блокирует ВСЕ кнопки сразу при нажатии (не только себя)
- Кнопка молнии: блокирует всё сразу при нажатии, а не после обновления списков
- 'Подключаемся к быстрейшему серверу': блокирует UI до завершения подключения
- sub_update кнопка: блокирует интерфейс на время обновления, разблокирует по завершении
- isRunning: applyRunningState теперь явно разблокирует/блокирует кнопки при любом переходе состояния
- Обновление подписок через VPN: при каждом подключении автоматически обновляем подписки через VPN-прокси (через 2 сек после старта)
2026-05-06 00:02:38 +03:00
zarazaex69 5123d996f4 style: update FAB colors and add ripple effect 2026-05-05 16:49:55 +03:00
zarazaex69 cb1ea3c3a3 feat(ui): enable edge-to-edge layout and fix status bar color 2026-05-04 19:03:12 +03:00
zarazaex69 9249ff9bce feat: sync status bar color with toolbar background 2026-05-04 15:05:29 +03:00
zarazaex69 b8cbcac477 refactor(ui): update icons and remove import/export proxy app menu items 2026-05-04 14:45:42 +03:00
zarazaex69 a4c4d764a0 fix: экзорцизм сабмодуля material-design-icons 2026-05-04 14:11:06 +03:00
zarazaex69 b6122866d5 fix: полное удаление сломанного сабмодуля material-design-icons 2026-05-04 14:08:21 +03:00
zarazaex69 b87a0e8a6e REMOVEE 2026-05-04 14:03:08 +03:00
zarazaex69 3ccd7493a2 feat: кнопки блокируются во время теста, молния останавливает скан
- Кнопки FAB и меню серые и недоступны пока идёт пинг-тест
- Нажатие на молнию во время теста — останавливает его (не перезапускает)
- Иконка молнии меняется на стоп пока идёт тест
- isTesting LiveData управляет состоянием UI
2026-05-04 08:26:12 +03:00
zarazaex69 60ce213f67 Replace delay test URL with api.ipify.org 2026-04-26 23:39:29 +03:00
zarazaex69 d0161826e2 Reduce MeasureDelay timeout from 12s to 6s and remove unnecessary delays 2026-04-26 23:14:39 +03:00
zarazaex69 641fcb943d feat: Parallelize config preparation for speed tests 2026-04-26 22:54:17 +03:00
zarazaex69 1fbb4f2bd3 feat: add copy server button to clipboard 2026-04-22 18:48:34 +03:00
55 changed files with 1349 additions and 367 deletions
+1
View File
@@ -65,3 +65,4 @@ Thumbs.db
.DS_Store
add_subscription_mmkv.py
.gitignore
material-design-icons
+12 -5
View File
@@ -50,6 +50,7 @@ type PingCallback interface {
OnResult(guid string, delay int64)
}
// CoreCallbackHandler defines interface for receiving callbacks and notifications from the core service
type CoreCallbackHandler interface {
Startup() int
@@ -159,10 +160,10 @@ func (x *CoreController) QueryStats(tag string, direct string) int64 {
}
// MeasureDelay measures network latency to a specified URL through the current core instance
// Uses a 12-second timeout context and returns the round-trip time in milliseconds
// Uses a 6-second timeout context and returns the round-trip time in milliseconds
// An error is returned if the connection fails or returns an unexpected status
func (x *CoreController) MeasureDelay(url string) (int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), 12*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Second)
defer cancel()
return measureInstDelay(ctx, x.coreInstance, url)
@@ -212,6 +213,12 @@ func MeasureOutboundDelayBatch(itemsJson string, url string, callback PingCallba
}
func measureOutboundDelayInternal(ConfigureFileContent string, url string) (int64, error) {
return measureOutboundDelayWithContext(ConfigureFileContent, url)
}
func measureOutboundDelayWithContext(ConfigureFileContent string, url string) (int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Second)
defer cancel()
config, err := coreserial.LoadJSONConfig(strings.NewReader(ConfigureFileContent))
if err != nil {
return -1, fmt.Errorf("config load error: %w", err)
@@ -238,7 +245,7 @@ func measureOutboundDelayInternal(ConfigureFileContent string, url string) (int6
return -1, fmt.Errorf("startup failed: %w", err)
}
defer inst.Close()
return measureInstDelay(context.Background(), inst, url)
return measureInstDelay(ctx, inst, url)
}
// CheckVersionX returns the library and Xray versions
@@ -307,11 +314,11 @@ func measureInstDelay(ctx context.Context, inst *core.Instance, url string) (int
client := &http.Client{
Transport: tr,
Timeout: 5 * time.Second,
Timeout: 6 * time.Second,
}
if url == "" {
url = "https://www.google.com/generate_204"
url = "https://api.ipify.org"
}
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
@@ -2,11 +2,13 @@ package xyz.zarazaex.olc
import android.app.Application
import android.content.Context
import android.os.Build
import androidx.work.Configuration
import androidx.work.WorkManager
import com.google.android.material.color.DynamicColors
import com.tencent.mmkv.MMKV
import xyz.zarazaex.olc.AppConfig.ANG_PACKAGE
import xyz.zarazaex.olc.handler.MmkvManager
import xyz.zarazaex.olc.handler.SettingsManager
class AngApplication : Application() {
@@ -32,8 +34,6 @@ class AngApplication : Application() {
*/
override fun onCreate() {
super.onCreate()
// Apply Material You dynamic colors (Android 12+)
DynamicColors.applyToActivitiesIfAvailable(this)
val mmkvDir = java.io.File(filesDir, "mmkv")
if (!java.io.File(mmkvDir, "MAIN").exists()) {
@@ -53,6 +53,11 @@ class AngApplication : Application() {
MMKV.initialize(this)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
MmkvManager.decodeSettingsBool(AppConfig.PREF_DYNAMIC_COLORS, false)) {
DynamicColors.applyToActivitiesIfAvailable(this)
}
// Initialize WorkManager with the custom configuration
WorkManager.initialize(this, workManagerConfiguration)
@@ -73,6 +73,9 @@ object AppConfig {
const val PREF_HEV_TUNNEL_LOGLEVEL = "pref_hev_tunnel_loglevel"
const val PREF_HEV_TUNNEL_RW_TIMEOUT = "pref_hev_tunnel_rw_timeout_v2"
const val PREF_AUTO_SORT_AFTER_TEST = "pref_auto_sort_after_test"
const val PREF_SHOW_COPY_BUTTON = "pref_show_copy_button"
const val PREF_DYNAMIC_COLORS = "pref_dynamic_colors"
const val PREF_SUBSCRIPTIONS_BOTTOM = "pref_subscriptions_bottom"
/** Cache keys. */
const val CACHE_SUBSCRIPTION_ID = "cache_subscription_id"
@@ -119,7 +122,7 @@ object AppConfig {
const val APP_PRIVACY_POLICY = "$GITHUB_RAW_URL/2dust/v2rayNG/master/CR.md"
const val APP_PROMOTION_URL = "aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw="
const val TG_CHANNEL_URL = "https://t.me/github_2dust"
const val DELAY_TEST_URL = "https://icanhazip.com"
const val DELAY_TEST_URL = "https://api.ipify.org"
const val DELAY_TEST_URL2 = "https://api64.ipify.org"
// const val IP_API_URL = "https://speed.cloudflare.com/meta"
const val IP_API_URL = "https://api.ip.sb/geoip"
@@ -10,4 +10,6 @@ interface MainAdapterListener :BaseAdapterListener {
fun onShare(guid: String, profile: ProfileItem, position: Int, more: Boolean)
fun onCopyToClipboard(guid: String)
}
@@ -26,6 +26,10 @@ import xyz.zarazaex.olc.util.JsonUtil
import xyz.zarazaex.olc.util.QRCodeDecoder
import xyz.zarazaex.olc.util.Utils
import java.net.URI
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
object AngConfigManager {
@@ -562,9 +566,13 @@ object AngConfigManager {
fun updateConfigViaSubAll(): SubscriptionUpdateResult {
return try {
val subscriptions = MmkvManager.decodeSubscriptions()
subscriptions.fold(SubscriptionUpdateResult()) { acc, subscription ->
acc + updateConfigViaSub(subscription)
// Parallel fetch — each sub downloads concurrently on IO pool
val results = runBlocking(Dispatchers.IO) {
subscriptions.map { sub ->
async { updateConfigViaSub(sub) }
}.awaitAll()
}
results.fold(SubscriptionUpdateResult()) { acc, r -> acc + r }
} catch (e: Exception) {
Log.e(AppConfig.TAG, "Failed to update config via all subscriptions", e)
SubscriptionUpdateResult()
@@ -604,7 +612,7 @@ object AngConfigManager {
Log.i(AppConfig.TAG, url)
val userAgent = it.subscription.userAgent
val timeout = if (url.startsWith("https://key.zarazaex.xyz/sub")) 3000 else 15000
val timeout = if (url.startsWith("https://key.zarazaex.xyz/sub")) 3000 else 6000
var configText = try {
val httpPort = SettingsManager.getHttpPort()
@@ -0,0 +1,196 @@
package xyz.zarazaex.olc.handler
import android.util.Log
import xyz.zarazaex.olc.AppConfig
import xyz.zarazaex.olc.util.HttpUtil
import xyz.zarazaex.olc.util.JsonUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import kotlinx.coroutines.withContext
object CountryDetector {
const val UNKNOWN = "??"
// ── Emoji flag → ISO 2-letter country code ────────────────────────────────
/** Extract first flag emoji found in [text] and return its ISO country code (e.g. "RU"). */
fun extractFlagCode(text: String): String? {
val codePoints = text.codePoints().toArray()
var i = 0
while (i < codePoints.size - 1) {
val cp1 = codePoints[i]
val cp2 = codePoints[i + 1]
if (cp1 in 0x1F1E6..0x1F1FF && cp2 in 0x1F1E6..0x1F1FF) {
val c1 = ('A'.code + (cp1 - 0x1F1E6)).toChar()
val c2 = ('A'.code + (cp2 - 0x1F1E6)).toChar()
return "$c1$c2"
}
i++
}
return null
}
/** Get best country code for a server (emoji first, then cache). */
fun getCountryCode(remarks: String, serverIp: String?): String {
extractFlagCode(remarks)?.let { return it }
if (!serverIp.isNullOrBlank() && !isPrivateIp(serverIp)) {
MmkvManager.getCountryCache(serverIp)?.let { return it }
}
return UNKNOWN
}
// ── Flag emoji rendering ──────────────────────────────────────────────────
/** ISO code → flag emoji string */
fun codeToFlag(code: String): String {
if (code.length != 2 || code == UNKNOWN) return "🌍"
return try {
val first = 0x1F1E6 + (code[0].uppercaseChar().code - 'A'.code)
val second = 0x1F1E6 + (code[1].uppercaseChar().code - 'A'.code)
String(intArrayOf(first, second), 0, 2)
} catch (e: Exception) { "🌍" }
}
/** ISO code → human-readable country name (or code if unknown) */
fun codeToName(code: String): String = COUNTRY_NAMES[code.uppercase()] ?: code
// ── Background lookup ─────────────────────────────────────────────────────
private val semaphore = Semaphore(5)
/**
* Looks up countries for all [ips] not yet cached via ip-api.com/batch.
* Saves results to MmkvManager cache. Called from IO coroutine.
*/
suspend fun lookupAndCacheAll(ips: List<String>) {
val uncached = ips
.filter { !it.isNullOrBlank() && !isPrivateIp(it) }
.distinct()
.filter { MmkvManager.getCountryCache(it) == null }
if (uncached.isEmpty()) return
// ip-api.com/batch: max 100 per request, returns [{query, countryCode}]
uncached.chunked(100).forEach { chunk ->
semaphore.withPermit {
try {
lookupBatch(chunk)
} catch (e: Exception) {
Log.w(AppConfig.TAG, "Country batch lookup failed: ${e.message}")
}
}
}
}
private data class IpApiRequest(val query: String, val fields: String = "countryCode")
private suspend fun lookupBatch(ips: List<String>) = withContext(Dispatchers.IO) {
val body = JsonUtil.toJson(ips.map { IpApiRequest(it) })
val response = HttpUtil.postJson("http://ip-api.com/batch", body, 10000) ?: return@withContext
try {
val arr = com.google.gson.JsonParser.parseString(response).asJsonArray
arr.forEach { el ->
val obj = el.asJsonObject
val ip = obj.get("query")?.asString ?: return@forEach
val code = obj.get("countryCode")?.asString?.uppercase()
?.takeIf { it.length == 2 } ?: return@forEach
MmkvManager.setCountryCache(ip, code)
}
} catch (e: Exception) {
Log.w(AppConfig.TAG, "Country batch parse failed: ${e.message}")
}
}
// ── Private IP check ─────────────────────────────────────────────────────
fun isPrivateIp(ip: String): Boolean {
if (ip.contains('.').not()) return false // IPv6 skip for now
return try {
val parts = ip.split('.').map { it.toInt() }
if (parts.size != 4) return false
val a = parts[0]; val b = parts[1]
a == 10 || a == 127 ||
(a == 172 && b in 16..31) ||
(a == 192 && b == 168) ||
(a == 100 && b in 64..127)
} catch (e: Exception) { false }
}
// ── Country names map ─────────────────────────────────────────────────────
val COUNTRY_NAMES: Map<String, String> = mapOf(
"AF" to "Афганистан", "AL" to "Албания", "DZ" to "Алжир",
"AD" to "Андорра", "AO" to "Ангола", "AG" to "Антигуа и Барбуда",
"AR" to "Аргентина", "AM" to "Армения", "AU" to "Австралия",
"AT" to "Австрия", "AZ" to "Азербайджан", "BS" to "Багамы",
"BH" to "Бахрейн", "BD" to "Бангладеш", "BB" to "Барбадос",
"BY" to "Беларусь", "BE" to "Бельгия", "BZ" to "Белиз",
"BJ" to "Бенин", "BT" to "Бутан", "BO" to "Боливия",
"BA" to "Босния и Герцеговина", "BW" to "Ботсвана",
"BR" to "Бразилия", "BN" to "Бруней", "BG" to "Болгария",
"BF" to "Буркина-Фасо", "BI" to "Бурунди", "CV" to "Кабо-Верде",
"KH" to "Камбоджа", "CM" to "Камерун", "CA" to "Канада",
"CF" to "ЦАР", "TD" to "Чад", "CL" to "Чили",
"CN" to "Китай", "CO" to "Колумбия", "KM" to "Коморы",
"CG" to "Конго", "CD" to "ДР Конго", "CR" to "Коста-Рика",
"HR" to "Хорватия", "CU" to "Куба", "CY" to "Кипр",
"CZ" to "Чехия", "DK" to "Дания", "DJ" to "Джибути",
"DM" to "Доминика", "DO" to "Доминикана", "EC" to "Эквадор",
"EG" to "Египет", "SV" to "Сальвадор", "GQ" to "Экв. Гвинея",
"ER" to "Эритрея", "EE" to "Эстония", "SZ" to "Эсватини",
"ET" to "Эфиопия", "FJ" to "Фиджи", "FI" to "Финляндия",
"FR" to "Франция", "GA" to "Габон", "GM" to "Гамбия",
"GE" to "Грузия", "DE" to "Германия", "GH" to "Гана",
"GR" to "Греция", "GD" to "Гренада", "GT" to "Гватемала",
"GN" to "Гвинея", "GW" to "Гвинея-Бисау", "GY" to "Гайана",
"HT" to "Гаити", "HN" to "Гондурас", "HU" to "Венгрия",
"IS" to "Исландия", "IN" to "Индия", "ID" to "Индонезия",
"IR" to "Иран", "IQ" to "Ирак", "IE" to "Ирландия",
"IL" to "Израиль", "IT" to "Италия", "JM" to "Ямайка",
"JP" to "Япония", "JO" to "Иордания", "KZ" to "Казахстан",
"KE" to "Кения", "KI" to "Кирибати", "KP" to "Сев. Корея",
"KR" to "Юж. Корея", "KW" to "Кувейт", "KG" to "Киргизия",
"LA" to "Лаос", "LV" to "Латвия", "LB" to "Ливан",
"LS" to "Лесото", "LR" to "Либерия", "LY" to "Ливия",
"LI" to "Лихтенштейн", "LT" to "Литва", "LU" to "Люксембург",
"MG" to "Мадагаскар", "MW" to "Малави", "MY" to "Малайзия",
"MV" to "Мальдивы", "ML" to "Мали", "MT" to "Мальта",
"MH" to "Маршалловы о-ва", "MR" to "Мавритания",
"MU" to "Маврикий", "MX" to "Мексика", "FM" to "Микронезия",
"MD" to "Молдова", "MC" to "Монако", "MN" to "Монголия",
"ME" to "Черногория", "MA" to "Марокко", "MZ" to "Мозамбик",
"MM" to "Мьянма", "NA" to "Намибия", "NR" to "Науру",
"NP" to "Непал", "NL" to "Нидерланды", "NZ" to "Нов. Зеландия",
"NI" to "Никарагуа", "NE" to "Нигер", "NG" to "Нигерия",
"MK" to "Сев. Македония", "NO" to "Норвегия", "OM" to "Оман",
"PK" to "Пакистан", "PW" to "Палау", "PA" to "Панама",
"PG" to "Папуа — Нов. Гвинея", "PY" to "Парагвай",
"PE" to "Перу", "PH" to "Филиппины", "PL" to "Польша",
"PT" to "Португалия", "QA" to "Катар", "RO" to "Румыния",
"RU" to "Россия", "RW" to "Руанда",
"KN" to "Сент-Китс и Невис", "LC" to "Сент-Люсия",
"VC" to "Сент-Винсент", "WS" to "Самоа",
"SM" to "Сан-Марино", "ST" to "Сан-Томе и Принсипи",
"SA" to "Саудовская Аравия", "SN" to "Сенегал",
"RS" to "Сербия", "SC" to "Сейшелы", "SL" to "Сьерра-Леоне",
"SG" to "Сингапур", "SK" to "Словакия", "SI" to "Словения",
"SB" to "Соломоновы о-ва", "SO" to "Сомали",
"ZA" to "ЮАР", "SS" to "Юж. Судан", "ES" to "Испания",
"LK" to "Шри-Ланка", "SD" to "Судан", "SR" to "Суринам",
"SE" to "Швеция", "CH" to "Швейцария", "SY" to "Сирия",
"TW" to "Тайвань", "TJ" to "Таджикистан", "TZ" to "Танзания",
"TH" to "Таиланд", "TL" to "Восточный Тимор", "TG" to "Того",
"TO" to "Тонга", "TT" to "Тринидад и Тобаго",
"TN" to "Тунис", "TR" to "Турция", "TM" to "Туркменистан",
"TV" to "Тувалу", "UG" to "Уганда", "UA" to "Украина",
"AE" to "ОАЭ", "GB" to "Великобритания", "US" to "США",
"UY" to "Уругвай", "UZ" to "Узбекистан", "VU" to "Вануату",
"VE" to "Венесуэла", "VN" to "Вьетнам", "YE" to "Йемен",
"ZM" to "Замбия", "ZW" to "Зимбабве",
"HK" to "Гонконг", "MO" to "Макао", "PS" to "Палестина",
"XK" to "Косово", "EU" to "Европейский союз",
"NL" to "Нидерланды"
)
}
@@ -26,6 +26,7 @@ object MmkvManager {
private const val ID_SUB = "SUB"
private const val ID_ASSET = "ASSET"
private const val ID_SETTING = "SETTING"
private const val ID_COUNTRY_CACHE = "COUNTRY_CACHE"
private const val KEY_SELECTED_SERVER = "SELECTED_SERVER"
private const val KEY_ANG_CONFIGS = "ANG_CONFIGS"
private const val KEY_SUB_SERVER_PREFIX = "SUB_SERVERS_"
@@ -39,6 +40,7 @@ object MmkvManager {
private val subStorage by lazy { MMKV.mmkvWithID(ID_SUB, MMKV.MULTI_PROCESS_MODE) }
private val assetStorage by lazy { MMKV.mmkvWithID(ID_ASSET, MMKV.MULTI_PROCESS_MODE) }
private val settingsStorage by lazy { MMKV.mmkvWithID(ID_SETTING, MMKV.MULTI_PROCESS_MODE) }
private val countryCacheStorage by lazy { MMKV.mmkvWithID(ID_COUNTRY_CACHE, MMKV.MULTI_PROCESS_MODE) }
//endregion
@@ -689,4 +691,23 @@ object MmkvManager {
}
//endregion
//region Country Cache
/** Returns cached ISO country code for [ip], or null if not cached. */
fun getCountryCache(ip: String): String? = countryCacheStorage.decodeString(ip)
/** Persists ISO country code for [ip]. */
fun setCountryCache(ip: String, code: String) { countryCacheStorage.encode(ip, code) }
/** Loads the user's country filter preference (set of ISO codes to SHOW, empty = show all). */
fun getCountryFilter(): Set<String> =
settingsStorage.decodeStringSet("pref_country_filter") ?: emptySet()
/** Saves the user's country filter preference. */
fun setCountryFilter(codes: Set<String>) {
settingsStorage.encode("pref_country_filter", codes)
}
//endregion
}
@@ -94,7 +94,7 @@ object SpeedtestManager {
var result: String
var elapsed = -1L
val testUrl = "https://icanhazip.com"
val testUrl = "https://api.ipify.org"
val conn = HttpUtil.createProxyConnection(testUrl, port, 15000, 15000) ?: return Pair(elapsed, "")
try {
val start = SystemClock.elapsedRealtime()
@@ -6,6 +6,8 @@ import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
@@ -55,19 +57,20 @@ class RealPingWorkerService(
scope.launch(Dispatchers.IO) {
try {
// Prepare configurations for batch test and shuffle for better async feel
val items =
guids.shuffled().mapNotNull { guid ->
val configResult =
V2rayConfigManager.getV2rayConfig4Speedtest(context, guid)
if (configResult.status) {
PingItem(guid, configResult.content)
} else {
// Notify failure immediately for invalid configs
reportResult(guid, -1L)
null
}
// Prepare configurations in parallel for faster startup
val shuffledGuids = guids.shuffled()
val deferredItems = shuffledGuids.map { guid ->
async(Dispatchers.IO) {
val configResult = V2rayConfigManager.getV2rayConfig4Speedtest(context, guid)
if (configResult.status) {
PingItem(guid, configResult.content)
} else {
reportResult(guid, -1L)
null
}
}
}
val items = deferredItems.awaitAll().filterNotNull()
if (items.isNotEmpty()) {
val configsJson = JsonUtil.toJson(items)
@@ -132,8 +135,7 @@ class RealPingWorkerService(
private fun sendBatchUpdate(update: PingProgressUpdate) {
MessageUtil.sendMsg2UI(context, AppConfig.MSG_MEASURE_CONFIG_BATCH, update)
val left = (update.total - update.finished).coerceAtLeast(0)
MessageUtil.sendMsg2UI(context, AppConfig.MSG_MEASURE_CONFIG_NOTIFY, "$left / ${update.total}")
MessageUtil.sendMsg2UI(context, AppConfig.MSG_MEASURE_CONFIG_NOTIFY, "${update.finished} / ${update.total}")
}
fun cancel() {
@@ -2,6 +2,7 @@ package xyz.zarazaex.olc.ui
import android.content.Context
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
@@ -10,6 +11,7 @@ import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.core.view.WindowCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
@@ -121,6 +123,7 @@ abstract class BaseActivity : AppCompatActivity() {
setSupportActionBar(it)
supportActionBar?.setDisplayHomeAsUpEnabled(showHomeAsUp)
title?.let { t -> this.title = t }
syncStatusBarWithToolbar(it)
}
progressBar = findViewById(R.id.progress_bar)
}
@@ -178,9 +181,18 @@ abstract class BaseActivity : AppCompatActivity() {
setSupportActionBar(it)
supportActionBar?.setDisplayHomeAsUpEnabled(showHomeAsUp)
title?.let { t -> supportActionBar?.title = t }
syncStatusBarWithToolbar(it)
}
}
private fun syncStatusBarWithToolbar(toolbar: Toolbar) {
val tv = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, tv, true)
val bgColor = tv.data
WindowCompat.getInsetsController(window, window.decorView)?.isAppearanceLightStatusBars =
ColorUtils.calculateLuminance(bgColor) > 0.5
}
/**
* Show the base layout's ProgressBar.
*
@@ -2,7 +2,8 @@ package xyz.zarazaex.olc.ui
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AlertDialog
import android.widget.TextView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.lifecycle.lifecycleScope
import xyz.zarazaex.olc.AppConfig
import xyz.zarazaex.olc.BuildConfig
@@ -12,9 +13,9 @@ import xyz.zarazaex.olc.dto.CheckUpdateResult
import xyz.zarazaex.olc.extension.toast
import xyz.zarazaex.olc.extension.toastError
import xyz.zarazaex.olc.extension.toastSuccess
import xyz.zarazaex.olc.handler.MmkvManager
import xyz.zarazaex.olc.handler.UpdateCheckerManager
import xyz.zarazaex.olc.handler.V2RayNativeManager
import xyz.zarazaex.olc.util.MarkdownUtil
import xyz.zarazaex.olc.util.Utils
import kotlinx.coroutines.launch
@@ -24,33 +25,29 @@ class CheckUpdateActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//setContentView(binding.root)
setContentViewWithToolbar(binding.root, showHomeAsUp = true, title = getString(R.string.update_check_for_update))
binding.layoutCheckUpdate.setOnClickListener {
checkForUpdates(binding.checkPreRelease.isChecked)
checkForUpdates()
}
binding.checkPreRelease.setOnCheckedChangeListener { _, isChecked ->
MmkvManager.encodeSettings(AppConfig.PREF_CHECK_UPDATE_PRE_RELEASE, isChecked)
}
binding.checkPreRelease.isChecked = true
MmkvManager.encodeSettings(AppConfig.PREF_CHECK_UPDATE_PRE_RELEASE, true)
// Hide the pre-release toggle - we always check releases
binding.checkPreRelease.visibility = android.view.View.GONE
"v${BuildConfig.VERSION_NAME} (${V2RayNativeManager.getLibVersion()})".also {
binding.tvVersion.text = it
}
checkForUpdates(binding.checkPreRelease.isChecked)
checkForUpdates()
}
private fun checkForUpdates(includePreRelease: Boolean) {
private fun checkForUpdates() {
toast(R.string.update_checking_for_update)
showLoading()
lifecycleScope.launch {
try {
val result = UpdateCheckerManager.checkForUpdate(includePreRelease)
val result = UpdateCheckerManager.checkForUpdate(false)
if (result.hasUpdate) {
showUpdateDialog(result)
} else {
@@ -67,15 +64,21 @@ class CheckUpdateActivity : BaseActivity() {
}
private fun showUpdateDialog(result: CheckUpdateResult) {
AlertDialog.Builder(this)
.setTitle(getString(R.string.update_new_version_found, result.latestVersion))
.setMessage(result.releaseNotes)
val message = result.releaseNotes?.let { MarkdownUtil.parseBasic(it) } ?: ""
val titleStr = getString(R.string.update_new_version_found, result.latestVersion)
val dialog = MaterialAlertDialogBuilder(this)
.setTitle(titleStr)
.setMessage(message)
.setPositiveButton(R.string.update_now) { _, _ ->
result.downloadUrl?.let {
Utils.openUri(this, it)
}
}
.setNegativeButton(android.R.string.cancel, null)
.show()
.create()
dialog.show()
val titleView = layoutInflater.inflate(R.layout.dialog_title_with_close, null)
titleView.findViewById<TextView>(R.id.dialog_title_text).text = titleStr
titleView.findViewById<android.widget.ImageButton>(R.id.dialog_close_btn).setOnClickListener { dialog.dismiss() }
dialog.setCustomTitle(titleView)
}
}
}
@@ -12,6 +12,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.snackbar.Snackbar
import xyz.zarazaex.olc.AppConfig
import xyz.zarazaex.olc.R
import xyz.zarazaex.olc.contracts.MainAdapterListener
@@ -137,9 +138,7 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>(),
* @param guid The server unique identifier
*/
private fun share2Clipboard(guid: String) {
if (AngConfigManager.share2Clipboard(ownerActivity, guid) == 0) {
ownerActivity.toastSuccess(R.string.toast_success)
} else {
if (AngConfigManager.share2Clipboard(ownerActivity, guid) != 0) {
ownerActivity.toastError(R.string.toast_failure)
}
}
@@ -264,6 +263,10 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>(),
setSelectServer(guid)
}
override fun onCopyToClipboard(guid: String) {
share2Clipboard(guid)
}
override fun onShare(guid: String, profile: ProfileItem, position: Int, more: Boolean) {
val isCustom = profile.configType == EConfigType.CUSTOM || profile.configType == EConfigType.POLICYGROUP
@@ -284,6 +287,13 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>(),
//binding.refreshLayout.isRefreshing = false
}
/**
* Scrolls to the top of the list (called on double-tap on tab)
*/
fun scrollToTop() {
binding.recyclerView.smoothScrollToPosition(0)
}
/**
* Scrolls to the currently selected server in the RecyclerView
*/
@@ -9,15 +9,18 @@ import android.util.Log
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
@@ -31,6 +34,7 @@ import xyz.zarazaex.olc.enums.PermissionType
import xyz.zarazaex.olc.extension.toast
import xyz.zarazaex.olc.extension.toastError
import xyz.zarazaex.olc.handler.AngConfigManager
import xyz.zarazaex.olc.handler.CountryDetector
import xyz.zarazaex.olc.handler.MmkvManager
import xyz.zarazaex.olc.handler.SettingsChangeManager
import xyz.zarazaex.olc.handler.SettingsManager
@@ -49,6 +53,8 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
private var isLiteTesting = false
private var easterEggClickCount = 0
private var isEasterEggActive = false
/** Был ли VPN уже запущен в предыдущем колбэке — чтобы детектировать момент подключения */
private var wasRunning = false
val mainViewModel: MainViewModel by viewModels()
private lateinit var groupPagerAdapter: GroupPagerAdapter
@@ -73,7 +79,22 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
setupToolbar(binding.toolbar, false, getString(R.string.title_server))
setupToolbar(binding.toolbar, false, getString(R.string.app_name))
// edge-to-edge: контент идёт под статус-бар, AppBarLayout тянется под него же
WindowCompat.setDecorFitsSystemWindows(window, false)
ViewCompat.setOnApplyWindowInsetsListener(binding.appBarLayout) { v, insets ->
v.setPadding(0, insets.getInsets(WindowInsetsCompat.Type.statusBars()).top, 0, 0)
insets
}
// Нижние кнопки поднимаются над навигационной панелью
ViewCompat.setOnApplyWindowInsetsListener(binding.bottomContainer) { v, insets ->
val navBarHeight = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
v.setPadding(0, 0, 0, navBarHeight)
insets
}
placeTabGroup()
groupPagerAdapter = GroupPagerAdapter(this, emptyList())
binding.viewPager.adapter = groupPagerAdapter
@@ -167,26 +188,57 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
private fun setupViewModel() {
mainViewModel.updateTestResultAction.observe(this) { setTestState(it) }
mainViewModel.isTesting.observe(this) { testing ->
if (testing) {
// Во время теста: блокируем всё кроме кнопки молнии (стоп)
binding.fab.isEnabled = false
binding.fab.alpha = 0.5f
val menu = binding.toolbar.menu
menu.findItem(R.id.real_ping_all)?.let { it.isEnabled = false; it.icon?.alpha = 128 }
menu.findItem(R.id.filter_by_country)?.let { it.isEnabled = false; it.icon?.alpha = 128 }
menu.findItem(R.id.sub_update)?.let { it.isEnabled = false; it.icon?.alpha = 128 }
// Молния — стоп-кнопка, всегда активна во время теста
binding.btnSummaryLite.isEnabled = true
binding.btnSummaryLite.alpha = 1.0f
binding.btnSummaryLite.setImageResource(R.drawable.ic_stop_24dp)
binding.btnSummaryLite.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_active))
} else {
setButtonsEnabled(true)
binding.btnSummaryLite.setImageResource(R.drawable.bolt_24)
binding.btnSummaryLite.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_inactive))
}
}
mainViewModel.liteTestFinished.observe(this) { finished ->
if (finished && isLiteTesting) {
isLiteTesting = false
mainViewModel.sortByTestResults()
mainViewModel.reloadServerList()
val firstReachable = mainViewModel.serversCache.firstOrNull { cache ->
(MmkvManager.decodeServerAffiliationInfo(cache.guid)?.testDelayMillis ?: 0L) > 0L
}
if (firstReachable != null) {
MmkvManager.setSelectServer(firstReachable.guid)
mainViewModel.reloadServerList() // reload AFTER selection so indicator renders correctly
showStatus("Подключаемся к быстрейшему серверу")
// Блокируем кнопки на время подключения
setButtonsEnabled(false)
applyRunningState(isLoading = true, isRunning = false)
startV2RayWithPermission()
} else {
mainViewModel.reloadServerList()
showStatus("Нет доступных серверов!")
setButtonsEnabled(true)
}
}
}
mainViewModel.isRunning.observe(this) { isRunning ->
applyRunningState(false, isRunning)
// Как только VPN только что подключился — обновляем подписки через него
if (isRunning && !wasRunning) {
updateSubsViaVpn()
}
wasRunning = isRunning
}
mainViewModel.startListenBroadcast()
mainViewModel.initAssets(assets)
@@ -208,6 +260,42 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
binding.viewPager.setCurrentItem(targetIndex, false)
binding.tabGroup.isVisible = groups.size > 1
// Double-tap on a tab scrolls to top of that group
binding.tabGroup.addOnTabSelectedListener(object : com.google.android.material.tabs.TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: com.google.android.material.tabs.TabLayout.Tab?) {}
override fun onTabUnselected(tab: com.google.android.material.tabs.TabLayout.Tab?) {}
override fun onTabReselected(tab: com.google.android.material.tabs.TabLayout.Tab?) {
val currentItem = binding.viewPager.currentItem
val itemId = groupPagerAdapter.getItemId(currentItem)
val fragment = supportFragmentManager.findFragmentByTag("f$itemId") as? GroupServerFragment
fragment?.scrollToTop()
}
})
}
private fun setButtonsEnabled(enabled: Boolean) {
binding.fab.isEnabled = enabled
binding.fab.alpha = if (enabled) 1.0f else 0.5f
setSecondaryButtonsEnabled(enabled)
}
private fun setSecondaryButtonsEnabled(enabled: Boolean) {
binding.btnSummaryLite.isEnabled = enabled
binding.btnSummaryLite.alpha = if (enabled) 1.0f else 0.5f
val menu = binding.toolbar.menu
menu.findItem(R.id.real_ping_all)?.let {
it.isEnabled = enabled
it.icon?.alpha = if (enabled) 255 else 128
}
menu.findItem(R.id.filter_by_country)?.let {
it.isEnabled = enabled
it.icon?.alpha = if (enabled) 255 else 128
}
menu.findItem(R.id.sub_update)?.let {
it.isEnabled = enabled
it.icon?.alpha = if (enabled) 255 else 128
}
}
private fun handleFabAction() {
@@ -218,6 +306,8 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
val isRunning = mainViewModel.isRunning.value == true
// Блокируем все кнопки сразу
setButtonsEnabled(false)
applyRunningState(isLoading = true, isRunning = false)
lifecycleScope.launch {
@@ -248,11 +338,22 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
}
private fun handleLiteAction() {
// If testing is in progress - stop it
if (mainViewModel.isTesting.value == true) {
mainViewModel.cancelAllTests()
showStatus("Тест остановлен")
isLiteTesting = false
return
}
if (isFabOperationInProgress) {
return
}
isFabOperationInProgress = true
// Блокируем все кнопки сразу при нажатии
setButtonsEnabled(false)
lifecycleScope.launch {
try {
if (mainViewModel.isRunning.value == true) {
@@ -266,17 +367,20 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
launch(Dispatchers.IO) {
val result = mainViewModel.updateConfigViaSubAll()
delay(500L)
launch(Dispatchers.Main) {
val removed = mainViewModel.removeDuplicateByIpAll()
withContext(Dispatchers.Main) {
mainViewModel.reloadServerList()
if (result.configCount > 0) {
mainViewModel.reloadServerList()
showStatus("Обновлено ${result.configCount} профилей. Запуск теста...")
val status = if (removed > 0)
"Обновлено ${result.configCount} профилей, удалено $removed дубл. IP. Запуск теста..."
else
"Обновлено ${result.configCount} профилей. Запуск теста..."
showStatus(status)
} else {
showStatus("Запуск теста...")
}
hideLoading()
delay(500L)
showStatus("Выполняется замер задержки. Ожидаем завершения...")
mainViewModel.testAllRealPing()
}
@@ -355,21 +459,36 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
private fun showStatus(resId: Int) = showStatus(getString(resId))
private fun applyRunningState(isLoading: Boolean, isRunning: Boolean) {
private fun accentColor(): ColorStateList {
val typedValue = android.util.TypedValue()
theme.resolveAttribute(androidx.appcompat.R.attr.colorPrimary, typedValue, true)
val color = if (typedValue.resourceId != 0)
ContextCompat.getColor(this, typedValue.resourceId)
else
typedValue.data
return ColorStateList.valueOf(color)
}
private fun applyRunningState(isLoading: Boolean, isRunning: Boolean) {
if (isLoading) {
binding.fab.setImageResource(R.drawable.ic_fab_check)
// Идёт процесс подключения/отключения — блокируем всё
setButtonsEnabled(false)
binding.fab.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_inactive))
return
}
if (isRunning) {
binding.fab.setImageResource(R.drawable.ic_stop_24dp)
binding.fab.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_active))
binding.btnSummaryLite.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_active))
// Подключены: только FAB (отключить) активен, остальное блокируем
setSecondaryButtonsEnabled(false)
binding.fab.isEnabled = true
binding.fab.alpha = 1.0f
binding.fab.backgroundTintList = accentColor()
binding.btnSummaryLite.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_inactive))
binding.fab.contentDescription = getString(R.string.action_stop_service)
setTestState(getString(R.string.connection_connected))
binding.layoutTest.isFocusable = true
} else {
binding.fab.setImageResource(R.drawable.ic_play_24dp)
setButtonsEnabled(true)
binding.fab.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_inactive))
binding.btnSummaryLite.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_inactive))
binding.fab.contentDescription = getString(R.string.tasker_start_service)
@@ -428,10 +547,16 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
}
R.id.sub_update -> {
setButtonsEnabled(false)
importConfigViaSub()
true
}
R.id.filter_by_country -> {
showCountryFilterDialog()
true
}
else -> super.onOptionsItemSelected(item)
}
@@ -521,16 +646,44 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
return true
}
/**
* Обновляет подписки через уже поднятый VPN (httpPort > 0).
* Вызывается сразу после того, как VPN перешёл в состояние isRunning = true.
*/
private fun updateSubsViaVpn() {
lifecycleScope.launch(Dispatchers.IO) {
// Даём VPN пару секунд инициализироваться
delay(2000)
Log.d(AppConfig.TAG, "updateSubsViaVpn: starting post-connect subscription update")
val result = mainViewModel.updateConfigViaSubAll()
if (result.configCount > 0) {
val removed = mainViewModel.removeDuplicateByIpAll()
withContext(Dispatchers.Main) {
mainViewModel.reloadServerList()
val msg = if (removed > 0)
"Подписки обновлены: ${result.configCount} профилей, удалено $removed дубл. IP"
else
"Подписки обновлены: ${result.configCount} профилей"
showStatus(msg)
}
}
}
}
private fun importAllSubsOnStartup() {
showLoading()
lifecycleScope.launch(Dispatchers.IO) {
val result = AngConfigManager.updateConfigViaSubAll()
val removed = mainViewModel.removeDuplicateByIpAll()
delay(500L)
launch(Dispatchers.Main) {
if (result.configCount > 0) {
mainViewModel.reloadServerList()
showStatus(getString(R.string.title_update_config_count, result.configCount))
val status = if (removed > 0)
"${getString(R.string.title_update_config_count, result.configCount)} (удалено $removed дубл. IP)"
else
getString(R.string.title_update_config_count, result.configCount)
showStatus(status)
}
hideLoading()
}
@@ -562,6 +715,7 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
mainViewModel.reloadServerList()
}
hideLoading()
applyRunningState(isLoading = false, isRunning = mainViewModel.isRunning.value == true)
}
}
return true
@@ -582,7 +736,7 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
}
private fun delAllConfig() {
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
MaterialAlertDialogBuilder(this).setMessage(R.string.del_config_comfirm)
.setPositiveButton(android.R.string.ok) { _, _ ->
showLoading()
lifecycleScope.launch(Dispatchers.IO) {
@@ -601,7 +755,7 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
}
private fun delDuplicateConfig() {
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
MaterialAlertDialogBuilder(this).setMessage(R.string.del_config_comfirm)
.setPositiveButton(android.R.string.ok) { _, _ ->
showLoading()
lifecycleScope.launch(Dispatchers.IO) {
@@ -721,7 +875,64 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
tabMediator?.detach()
super.onDestroy()
}
// ── Country filter dialog ─────────────────────────────────────────────────
private fun showCountryFilterDialog() {
showLoading()
lifecycleScope.launch(Dispatchers.IO) {
mainViewModel.refreshCountryCache()
// Collect all countries including UNKNOWN
val allCountriesMap = mainViewModel.collectAllCountries().toMutableMap()
// Add Unknown entry
allCountriesMap[CountryDetector.UNKNOWN] = "🌐 Неизвестно"
val currentFilter = mainViewModel.countryFilter // empty = show all
withContext(Dispatchers.Main) {
hideLoading()
if (allCountriesMap.size <= 1) {
showStatus("Нет серверов с известной страной")
return@withContext
}
val codes = allCountriesMap.keys.toTypedArray()
val labels = allCountriesMap.values.toTypedArray()
// In exclude mode: checked = should be EXCLUDED
// currentFilter stores included set (empty = show all)
// Convert to excluded set for UI
val allCodes = codes.toSet()
val excludedByFilter = if (currentFilter.isEmpty()) emptySet()
else allCodes - currentFilter
val checked = BooleanArray(codes.size) { codes[it] in excludedByFilter }
val dialog = MaterialAlertDialogBuilder(this@MainActivity)
.setTitle("Исключить страны")
.setMultiChoiceItems(labels, checked) { _, which, isChecked ->
checked[which] = isChecked
}
.setPositiveButton("Применить") { _, _ ->
val excluded = codes.filterIndexed { i, _ -> checked[i] }.toSet()
val included = if (excluded.isEmpty()) emptySet()
else allCodes - excluded
mainViewModel.applyCountryFilter(included)
val msg = if (excluded.isEmpty()) "Показаны все страны"
else "Скрыто: ${excluded.joinToString { CountryDetector.codeToFlag(it) }}"
showStatus(msg)
}
.setNeutralButton("Сбросить") { _, _ ->
mainViewModel.applyCountryFilter(emptySet())
showStatus("Показаны все страны")
}
.create()
dialog.show()
dialog.setCustomTitle(buildDialogTitleWithClose("Исключить страны") { dialog.dismiss() })
}
}
}
private fun checkForUpdatesOnStartup() {
showStatus("Проверка обновлений...")
lifecycleScope.launch {
@@ -740,18 +951,28 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
}
private fun showUpdateAvailableDialog(result: xyz.zarazaex.olc.dto.CheckUpdateResult) {
AlertDialog.Builder(this)
.setTitle(getString(R.string.update_new_version_found, result.latestVersion))
.setMessage(result.releaseNotes)
val message = result.releaseNotes?.let { xyz.zarazaex.olc.util.MarkdownUtil.parseBasic(it) } ?: ""
val titleStr = getString(R.string.update_new_version_found, result.latestVersion)
val dialog = MaterialAlertDialogBuilder(this)
.setTitle(titleStr)
.setMessage(message)
.setPositiveButton(R.string.update_now) { _, _ ->
result.downloadUrl?.let {
Utils.openUri(this, it)
}
}
.setNegativeButton(android.R.string.ok, null)
.show()
.create()
dialog.show()
dialog.setCustomTitle(buildDialogTitleWithClose(titleStr) { dialog.dismiss() })
}
private fun buildDialogTitleWithClose(title: String, onClose: () -> Unit): View {
val view = layoutInflater.inflate(R.layout.dialog_title_with_close, null)
view.findViewById<TextView>(R.id.dialog_title_text).text = title
view.findViewById<android.widget.ImageButton>(R.id.dialog_close_btn).setOnClickListener { onClose() }
return view
}
private fun activateEasterEgg() {
if (isEasterEggActive) return
isEasterEggActive = true
@@ -796,4 +1017,17 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
}
}
}
private fun placeTabGroup() {
val tabGroup = binding.tabGroup
val bottomSlot = binding.tabSlotBottom
val topSlot = binding.tabSlotTop
val subsBottom = MmkvManager.decodeSettingsBool(AppConfig.PREF_SUBSCRIPTIONS_BOTTOM, false)
(tabGroup.parent as? android.view.ViewGroup)?.removeView(tabGroup)
if (subsBottom) {
bottomSlot.addView(tabGroup, 0)
} else {
topSlot.addView(tabGroup)
}
}
}
@@ -33,6 +33,8 @@ class MainRecyclerAdapter(
private val doubleColumnDisplay =
MmkvManager.decodeSettingsBool(AppConfig.PREF_DOUBLE_COLUMN_DISPLAY, false)
private val showCopyButton =
MmkvManager.decodeSettingsBool(AppConfig.PREF_SHOW_COPY_BUTTON, false)
private var data: MutableList<ServersCache> = mutableListOf()
private var recyclerView: RecyclerView? = null
@@ -84,16 +86,13 @@ class MainRecyclerAdapter(
override fun areContentsTheSame(oldPos: Int, newPos: Int): Boolean {
val oldProfile = oldData[oldPos].profile
val newProfile = parsedNewData[newPos].profile
val oldGuid = oldData[oldPos].guid
val newGuid = parsedNewData[newPos].guid
return oldProfile == newProfile &&
oldProfile.isFavorite == newProfile.isFavorite &&
MmkvManager.decodeServerAffiliationInfo(
oldData[oldPos].guid
)
?.testDelayMillis ==
MmkvManager.decodeServerAffiliationInfo(
parsedNewData[newPos].guid
)
?.testDelayMillis
(oldGuid == MmkvManager.getSelectServer()) == (newGuid == MmkvManager.getSelectServer()) &&
MmkvManager.decodeServerAffiliationInfo(oldGuid)?.testDelayMillis ==
MmkvManager.decodeServerAffiliationInfo(newGuid)?.testDelayMillis
}
override fun getChangePayload(oldPos: Int, newPos: Int): Any? {
@@ -123,8 +122,13 @@ class MainRecyclerAdapter(
if (payloads.isNotEmpty() && holder is MainViewHolder) {
for (payload in payloads) {
if (payload == PAYLOAD_FAVORITE) {
val isFav = data[position].profile.isFavorite
animateFavorite(holder.itemMainBinding.ivFavorite, isFav)
val item = data.getOrNull(holder.bindingAdapterPosition) ?: data.getOrNull(position) ?: continue
val isFav = item.profile.isFavorite
// Set correct icon immediately, then animate scale bounce
holder.itemMainBinding.ivFavorite.setImageResource(
if (isFav) R.drawable.ic_star_filled else R.drawable.kid_star_outline_24
)
animateFavorite(holder.itemMainBinding.ivFavorite)
}
}
} else {
@@ -132,23 +136,20 @@ class MainRecyclerAdapter(
}
}
private fun animateFavorite(view: android.widget.ImageView, isFavorite: Boolean) {
private fun animateFavorite(view: android.widget.ImageView) {
view.animate().cancel()
view.animate()
.scaleX(1.3f)
.scaleY(1.3f)
.setDuration(150)
.withEndAction {
view.setImageResource(
if (isFavorite) R.drawable.ic_star_filled
else R.drawable.ic_star_empty
)
view.animate()
.scaleX(1.0f)
.scaleY(1.0f)
.setDuration(150)
.start()
}
.start()
.scaleX(1.4f)
.scaleY(1.4f)
.setDuration(120)
.withEndAction {
view.animate()
.scaleX(1.0f)
.scaleY(1.0f)
.setDuration(120)
.start()
}
.start()
}
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
@@ -191,15 +192,24 @@ class MainRecyclerAdapter(
val isFav = profile.isFavorite
holder.itemMainBinding.ivFavorite.setImageResource(
if (isFav) R.drawable.ic_star_filled else R.drawable.ic_star_empty
if (isFav) R.drawable.ic_star_filled else R.drawable.kid_star_outline_24
)
holder.itemMainBinding.ivFavorite.setOnClickListener {
profile.isFavorite = !profile.isFavorite
MmkvManager.encodeServerConfig(guid, profile)
holder.itemMainBinding.ivFavorite.setImageResource(
if (profile.isFavorite) R.drawable.ic_star_filled else R.drawable.kid_star_outline_24
)
animateFavorite(holder.itemMainBinding.ivFavorite)
mainViewModel.reloadServerList()
}
holder.itemMainBinding.ivCopy.visibility = if (showCopyButton) View.VISIBLE else View.GONE
holder.itemMainBinding.ivCopy.setOnClickListener {
adapterListener?.onCopyToClipboard(guid)
}
holder.itemMainBinding.infoContainer.setOnClickListener {
adapterListener?.onSelectServer(guid)
}
@@ -90,7 +90,7 @@ class PerAppProxyActivity : BaseActivity() {
}
appsAll = apps
adapter = PerAppProxyAdapter(apps, viewModel)
adapter = PerAppProxyAdapter(apps.toMutableList(), viewModel)
binding.recyclerView.adapter = adapter
} catch (e: Exception) {
@@ -134,17 +134,6 @@ class PerAppProxyActivity : BaseActivity() {
true
}
R.id.import_proxy_app -> {
importProxyApp()
allowPerAppProxy()
true
}
R.id.export_proxy_app -> {
exportProxyApp()
true
}
else -> super.onOptionsItemSelected(item)
}
@@ -1,5 +1,6 @@
package xyz.zarazaex.olc.ui
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -9,9 +10,9 @@ import xyz.zarazaex.olc.dto.AppInfo
import xyz.zarazaex.olc.viewmodel.PerAppProxyViewModel
class PerAppProxyAdapter(
val apps: List<AppInfo>,
val apps: MutableList<AppInfo>,
val viewModel: PerAppProxyViewModel
) :RecyclerView.Adapter<PerAppProxyAdapter.BaseViewHolder>() {
) : RecyclerView.Adapter<PerAppProxyAdapter.BaseViewHolder>() {
companion object {
private const val VIEW_TYPE_HEADER = 0
@@ -29,17 +30,12 @@ class PerAppProxyAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val ctx = parent.context
return when (viewType) {
VIEW_TYPE_HEADER -> {
val view = View(ctx)
view.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
0
)
view.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0)
BaseViewHolder(view)
}
else -> AppViewHolder(ItemRecyclerBypassListBinding.inflate(LayoutInflater.from(ctx), parent, false))
}
}
@@ -48,30 +44,53 @@ class PerAppProxyAdapter(
open class BaseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
inner class AppViewHolder(private val itemBypassBinding: ItemRecyclerBypassListBinding) : BaseViewHolder(itemBypassBinding.root),
View.OnClickListener {
inner class AppViewHolder(private val itemBypassBinding: ItemRecyclerBypassListBinding) :
BaseViewHolder(itemBypassBinding.root), View.OnClickListener {
private lateinit var appInfo: AppInfo
fun bind(appInfo: AppInfo) {
this.appInfo = appInfo
itemBypassBinding.icon.setImageDrawable(appInfo.appIcon)
itemBypassBinding.name.text = if (appInfo.isSystemApp) {
String.format("** %s", appInfo.appName)
"** ${appInfo.appName}"
} else {
appInfo.appName
}
itemBypassBinding.packageName.text = appInfo.packageName
itemBypassBinding.checkBox.isChecked = viewModel.contains(appInfo.packageName)
itemView.setOnClickListener(this)
}
@SuppressLint("NotifyDataSetChanged")
override fun onClick(v: View?) {
val packageName = appInfo.packageName
viewModel.toggle(packageName)
itemBypassBinding.checkBox.isChecked = viewModel.contains(packageName)
val isNowSelected = viewModel.contains(packageName)
itemBypassBinding.checkBox.isChecked = isNowSelected
// Move selected items to top, unselected back to their position
val currentPos = apps.indexOf(appInfo)
if (currentPos < 0) return
if (isNowSelected) {
// Find first non-selected item position (insert before it)
val insertAt = apps.indexOfFirst { !viewModel.contains(it.packageName) }
.takeIf { it >= 0 } ?: 0
if (currentPos != insertAt) {
apps.removeAt(currentPos)
apps.add(insertAt, appInfo)
notifyItemMoved(currentPos + 1, insertAt + 1) // +1 for header
}
} else {
// Move to end of selected group
val lastSelected = apps.indexOfLast { viewModel.contains(it.packageName) }
val insertAt = if (lastSelected < 0) 0 else lastSelected + 1
if (currentPos != insertAt) {
apps.removeAt(currentPos)
apps.add(insertAt, appInfo)
notifyItemMoved(currentPos + 1, insertAt + 1)
}
}
}
}
}
@@ -1,7 +1,10 @@
package xyz.zarazaex.olc.ui
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.preference.CheckBoxPreference
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
@@ -28,6 +31,7 @@ class SettingsActivity : BaseActivity() {
class SettingsFragment : PreferenceFragmentCompat() {
private val dynamicColors by lazy { findPreference<CheckBoxPreference>(AppConfig.PREF_DYNAMIC_COLORS) }
private val localDns by lazy { findPreference<CheckBoxPreference>(AppConfig.PREF_LOCAL_DNS_ENABLED) }
private val fakeDns by lazy { findPreference<CheckBoxPreference>(AppConfig.PREF_FAKE_DNS_ENABLED) }
private val appendHttpProxy by lazy { findPreference<CheckBoxPreference>(AppConfig.PREF_APPEND_HTTP_PROXY) }
@@ -63,8 +67,22 @@ class SettingsActivity : BaseActivity() {
addPreferencesFromResource(R.xml.pref_settings)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
dynamicColors?.isVisible = false
}
initPreferenceSummaries()
dynamicColors?.setOnPreferenceChangeListener { _, _ ->
Toast.makeText(context, R.string.restart_required, Toast.LENGTH_SHORT).show()
val intent = requireActivity().packageManager
.getLaunchIntentForPackage(requireActivity().packageName)
?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
requireActivity().finish()
intent?.let { startActivity(it) }
true
}
localDns?.setOnPreferenceChangeListener { _, any ->
updateLocalDns(any as Boolean)
true
@@ -250,5 +250,27 @@ object HttpUtil {
}
}
}
/**
* POST JSON body to [url] and return response as String or null.
*/
fun postJson(url: String, body: String, timeout: Int = 10000): String? {
var conn: java.net.HttpURLConnection? = null
return try {
conn = java.net.URL(url).openConnection() as java.net.HttpURLConnection
conn.requestMethod = "POST"
conn.connectTimeout = timeout
conn.readTimeout = timeout
conn.doOutput = true
conn.setRequestProperty("Content-Type", "application/json")
conn.setRequestProperty("Connection", "close")
conn.outputStream.use { it.write(body.toByteArray()) }
conn.inputStream.bufferedReader().readText()
} catch (_: Exception) {
null
} finally {
conn?.disconnect()
}
}
}
@@ -0,0 +1,82 @@
package xyz.zarazaex.olc.util
import android.content.Context
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.StyleSpan
import android.graphics.Typeface
/**
* Simple markdown to Spanned converter for basic ** bold ** syntax without external libraries.
*/
object MarkdownUtil {
/**
* Convert simple markdown to Spanned. Supports:
* - **bold**
* - # headers (rendered as bold)
* - - list items (bullet)
*/
fun parseBasic(text: String): CharSequence {
val lines = text.split("\n")
val builder = SpannableStringBuilder()
for (line in lines) {
val processedLine = processLine(line.trimEnd())
builder.append(processedLine)
builder.append("\n")
}
// Remove trailing newlines
while (builder.isNotEmpty() && builder.last() == '\n') {
builder.delete(builder.length - 1, builder.length)
}
return builder
}
private fun processLine(line: String): CharSequence {
// Handle headers
val headerLine = when {
line.startsWith("### ") -> line.removePrefix("### ")
line.startsWith("## ") -> line.removePrefix("## ")
line.startsWith("# ") -> line.removePrefix("# ")
else -> null
}
if (headerLine != null) {
val sb = SpannableStringBuilder(processBold(headerLine))
sb.setSpan(StyleSpan(Typeface.BOLD), 0, sb.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
return sb
}
// Handle list items
if (line.startsWith("- ") || line.startsWith("* ")) {
return SpannableStringBuilder("" + processBold(line.substring(2)))
}
return processBold(line)
}
private fun processBold(text: String): SpannableStringBuilder {
val sb = SpannableStringBuilder()
var i = 0
while (i < text.length) {
if (i + 1 < text.length && text[i] == '*' && text[i + 1] == '*') {
val end = text.indexOf("**", i + 2)
if (end > 0) {
val boldText = text.substring(i + 2, end)
val start = sb.length
sb.append(boldText)
sb.setSpan(StyleSpan(Typeface.BOLD), start, sb.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
i = end + 2
} else {
sb.append(text[i])
i++
}
} else {
sb.append(text[i])
i++
}
}
return sb
}
}
@@ -23,6 +23,7 @@ import xyz.zarazaex.olc.dto.TestServiceMessage
import xyz.zarazaex.olc.extension.matchesPattern
import xyz.zarazaex.olc.extension.serializable
import xyz.zarazaex.olc.handler.AngConfigManager
import xyz.zarazaex.olc.handler.CountryDetector
import xyz.zarazaex.olc.handler.MmkvManager
import xyz.zarazaex.olc.handler.SettingsManager
import xyz.zarazaex.olc.handler.SpeedtestManager
@@ -38,14 +39,18 @@ import java.util.Collections
import java.util.regex.PatternSyntaxException
class MainViewModel(application: Application) : AndroidViewModel(application) {
private var serverList = mutableListOf<String>() // MmkvManager.decodeServerList()
private var serverList = mutableListOf<String>()
var subscriptionId: String = MmkvManager.decodeSettingsString(AppConfig.CACHE_SUBSCRIPTION_ID, "").orEmpty()
var keywordFilter = ""
/** ISO codes to show (empty = show all) */
var countryFilter: Set<String> = MmkvManager.getCountryFilter()
private set
val serversCache = mutableListOf<ServersCache>()
val isRunning by lazy { MutableLiveData<Boolean>() }
val updateListAction by lazy { MutableLiveData<Int>() }
val updateTestResultAction by lazy { MutableLiveData<String>() }
val liteTestFinished = MutableLiveData<Boolean>()
val isTesting by lazy { MutableLiveData<Boolean>().also { it.value = false } }
private val tcpingTestScope by lazy { CoroutineScope(Dispatchers.IO) }
/**
@@ -158,10 +163,18 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
val searchRegex = try {
if (kw.isNotEmpty()) Regex(kw, setOf(RegexOption.IGNORE_CASE)) else null
} catch (e: PatternSyntaxException) {
null // Fallback to literal search if regex is invalid
null
}
val activeCountryFilter = countryFilter
for (guid in serverList) {
val profile = MmkvManager.decodeServerConfig(guid) ?: continue
// Country filter
if (activeCountryFilter.isNotEmpty()) {
val code = CountryDetector.getCountryCode(profile.remarks, profile.server)
if (code !in activeCountryFilter) continue
}
if (kw.isEmpty()) {
serversCache.add(ServersCache(guid, profile))
continue
@@ -181,6 +194,48 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
}
}
/** Sets a new country filter and reloads list. Pass empty set to show all. */
fun applyCountryFilter(codes: Set<String>) {
countryFilter = codes
MmkvManager.setCountryFilter(codes)
reloadServerList()
}
/**
* Returns all known countries from ALL servers across all subscriptions (for showing in filter dialog).
* Key = ISO code, Value = human-readable name + flag.
*/
fun collectAllCountries(): Map<String, String> {
val result = mutableMapOf<String, String>()
var hasUnknown = false
for (guid in MmkvManager.decodeAllServerList()) {
val profile = MmkvManager.decodeServerConfig(guid) ?: continue
val code = CountryDetector.getCountryCode(profile.remarks, profile.server)
if (code == CountryDetector.UNKNOWN) {
hasUnknown = true
} else {
result[code] = "${CountryDetector.codeToFlag(code)} ${CountryDetector.codeToName(code)}"
}
}
if (hasUnknown) {
result[CountryDetector.UNKNOWN] = "🌐 Неизвестно"
}
return result.toSortedMap()
}
/** Trigger background geo-lookup for IPs not yet cached. */
fun refreshCountryCache() {
viewModelScope.launch(Dispatchers.IO) {
val ips = MmkvManager.decodeAllServerList().mapNotNull {
MmkvManager.decodeServerConfig(it)?.server?.trim()
}.distinct()
CountryDetector.lookupAndCacheAll(ips)
withContext(Dispatchers.Main) {
reloadServerList()
}
}
}
/**
* Updates the configuration via subscription for all servers.
* @return Detailed result of the subscription update operation.
@@ -191,27 +246,20 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
} else if (subscriptionId.startsWith("group_")) {
val allSubs = MmkvManager.decodeSubscriptions()
val groupSubs = when (subscriptionId) {
"group_white" -> allSubs.filter {
it.subscription.remarks.startsWith("БЕЛЫЕ", ignoreCase = true) ||
"group_white" -> allSubs.filter {
it.subscription.remarks.startsWith("БЕЛЫЕ", ignoreCase = true) ||
it.subscription.remarks.startsWith("WHITE", ignoreCase = true)
}
"group_black" -> allSubs.filter {
it.subscription.remarks.startsWith("ЧЕРНЫЕ", ignoreCase = true) ||
"group_black" -> allSubs.filter {
it.subscription.remarks.startsWith("ЧЕРНЫЕ", ignoreCase = true) ||
it.subscription.remarks.startsWith("BLACK", ignoreCase = true)
}
else -> emptyList()
}
var totalResult = SubscriptionUpdateResult()
groupSubs.forEach { sub ->
val result = AngConfigManager.updateConfigViaSub(SubscriptionCache(sub.guid, sub.subscription))
totalResult = SubscriptionUpdateResult(
configCount = totalResult.configCount + result.configCount,
successCount = totalResult.successCount + result.successCount,
failureCount = totalResult.failureCount + result.failureCount,
skipCount = totalResult.skipCount + result.skipCount
)
// Parallel fetch for group subs (sequential, called from IO context)
return groupSubs.fold(SubscriptionUpdateResult()) { acc, sub ->
acc + AngConfigManager.updateConfigViaSub(SubscriptionCache(sub.guid, sub.subscription))
}
return totalResult
} else {
val subItem = MmkvManager.decodeSubscription(subscriptionId) ?: return SubscriptionUpdateResult()
return AngConfigManager.updateConfigViaSub(SubscriptionCache(subscriptionId, subItem))
@@ -263,6 +311,17 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
}
}
/**
* Cancels all running ping tests.
*/
fun cancelAllTests() {
MessageUtil.sendMsg2TestService(
getApplication(),
TestServiceMessage(key = AppConfig.MSG_MEASURE_CONFIG_CANCEL)
)
isTesting.value = false
}
/**
* Tests the real ping for all servers.
*/
@@ -271,35 +330,43 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
getApplication(),
TestServiceMessage(key = AppConfig.MSG_MEASURE_CONFIG_CANCEL)
)
MmkvManager.clearAllTestDelayResults(serversCache.map { it.guid }.toList())
updateListAction.value = -1
viewModelScope.launch(Dispatchers.Default) {
if (serversCache.isEmpty()) {
withContext(Dispatchers.Main) { reloadServerList() }
}
if (serversCache.isEmpty()) {
return@launch
}
val actualSubId = if (subscriptionId.startsWith("group_")) {
""
} else {
subscriptionId
}
MessageUtil.sendMsg2TestService(
getApplication(),
TestServiceMessage(
key = AppConfig.MSG_MEASURE_CONFIG,
subscriptionId = actualSubId,
serverGuids = if (keywordFilter.isNotEmpty() || subscriptionId.startsWith("group_")) {
serversCache.map { it.guid }
} else {
emptyList()
// Auto-deduplicate by IP before scanning so we don't waste time on dupes
viewModelScope.launch(Dispatchers.IO) {
val removed = removeDuplicateByIpAll()
withContext(Dispatchers.Main) {
if (removed > 0) {
reloadServerList()
}
MmkvManager.clearAllTestDelayResults(serversCache.map { it.guid }.toList())
updateListAction.value = -1
isTesting.value = true
viewModelScope.launch(Dispatchers.Default) {
if (serversCache.isEmpty()) {
withContext(Dispatchers.Main) { reloadServerList() }
}
)
)
if (serversCache.isEmpty()) {
withContext(Dispatchers.Main) { isTesting.value = false }
return@launch
}
val actualSubId = if (subscriptionId.startsWith("group_")) "" else subscriptionId
MessageUtil.sendMsg2TestService(
getApplication(),
TestServiceMessage(
key = AppConfig.MSG_MEASURE_CONFIG,
subscriptionId = actualSubId,
serverGuids = if (keywordFilter.isNotEmpty() || subscriptionId.startsWith("group_")) {
serversCache.map { it.guid }
} else {
emptyList()
}
)
)
}
}
}
}
@@ -436,6 +503,103 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
return deleteServer.count()
}
/**
* Removes servers with duplicate IP addresses (same `server` field),
* keeping the one with the best ping result (or the first encountered if untested).
* @return Number of removed servers.
*/
fun removeDuplicateByIp(): Int {
val selectedGuid = MmkvManager.getSelectServer()
// Group all currently visible servers by their IP address
val byIp = LinkedHashMap<String, MutableList<ServersCache>>()
for (sc in serversCache) {
val ip = sc.profile.server?.trim()?.lowercase() ?: continue
byIp.getOrPut(ip) { mutableListOf() }.add(sc)
}
val toDelete = mutableListOf<String>()
for ((_, group) in byIp) {
if (group.size <= 1) continue
val best = group.minWithOrNull(compareBy(
{ it.guid != selectedGuid },
{ !it.profile.isFavorite },
{
val d = MmkvManager.decodeServerAffiliationInfo(it.guid)?.testDelayMillis ?: 0L
when {
d > 0L -> d
d == 0L -> Long.MAX_VALUE - 1
else -> Long.MAX_VALUE
}
}
))!!
group.filter { it.guid != best.guid }.forEach { toDelete.add(it.guid) }
}
for (guid in toDelete) {
MmkvManager.removeServer(guid)
}
return toDelete.size
}
/**
* Removes duplicate servers by IP across ALL subscriptions (for use after sub update / before scan).
* Per-subscription deduplication: within each sub keeps the best (favorite > lowest ping > first).
*/
/**
* Removes servers with duplicate IP addresses across ALL subscriptions globally.
* Keeps the best one per IP (favorite > lowest ping > first encountered).
* @return Number of removed servers.
*/
fun removeDuplicateByIpAll(): Int {
val selectedGuid = MmkvManager.getSelectServer()
// Collect every server GUID across all subscriptions
data class Entry(val guid: String, val ip: String, val isFav: Boolean)
val allEntries = mutableListOf<Entry>()
val allSubIds = MmkvManager.decodeSubsList().toMutableList()
// Add the default (no-sub) slot if not already present
if (!allSubIds.contains(AppConfig.DEFAULT_SUBSCRIPTION_ID)) {
allSubIds.add(0, AppConfig.DEFAULT_SUBSCRIPTION_ID)
}
for (subId in allSubIds) {
for (guid in MmkvManager.decodeServerList(subId)) {
val profile = MmkvManager.decodeServerConfig(guid) ?: continue
val ip = profile.server?.trim()?.lowercase()?.takeIf { it.isNotEmpty() } ?: continue
allEntries.add(Entry(guid, ip, profile.isFavorite))
}
}
// Group by IP globally
val byIp = LinkedHashMap<String, MutableList<Entry>>()
for (e in allEntries) {
byIp.getOrPut(e.ip) { mutableListOf() }.add(e)
}
val toDelete = mutableListOf<String>()
for ((_, group) in byIp) {
if (group.size <= 1) continue
val best = group.minWith(compareBy(
{ it.guid != selectedGuid },
{ !it.isFav },
{
val d = MmkvManager.decodeServerAffiliationInfo(it.guid)?.testDelayMillis ?: 0L
when {
d > 0L -> d
d == 0L -> Long.MAX_VALUE - 1
else -> Long.MAX_VALUE
}
}
))
group.filter { it.guid != best.guid }.forEach { toDelete.add(it.guid) }
}
for (guid in toDelete) {
MmkvManager.removeServer(guid)
}
return toDelete.size
}
/**
* Removes all servers.
* @return The number of removed servers.
@@ -457,6 +621,25 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
/**
* Sorts servers by their test results.
*/
/**
* Sorts serversCache in-place by test delay in real time (during a ping test).
* Favorites always come first, then sorted ascending by delay (failed/untested go to bottom).
*/
@Synchronized
fun sortServersCacheInPlace() {
serversCache.sortWith(compareBy(
{ !it.profile.isFavorite },
{
val delay = MmkvManager.decodeServerAffiliationInfo(it.guid)?.testDelayMillis ?: 0L
when {
delay > 0L -> delay
delay == 0L -> Long.MAX_VALUE - 1 // untested
else -> Long.MAX_VALUE // failed
}
}
))
}
fun sortByTestResults() {
if (subscriptionId.isEmpty()) {
MmkvManager.decodeSubsList().forEach { guid ->
@@ -590,6 +773,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
withContext(Dispatchers.Main) {
reloadServerList()
isTesting.value = false
liteTestFinished.value = true
liteTestFinished.value = false
}
@@ -626,7 +810,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
AppConfig.MSG_MEASURE_CONFIG_SUCCESS -> {
val resultPair = intent.serializable<Pair<String, Long>>("content") ?: return
MmkvManager.encodeServerTestDelayMillis(resultPair.first, resultPair.second)
updateListAction.value = getPosition(resultPair.first)
sortServersCacheInPlace()
updateListAction.value = -1
}
AppConfig.MSG_MEASURE_CONFIG_BATCH -> {
@@ -634,6 +819,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
update.results.forEach { result ->
MmkvManager.encodeServerTestDelayMillis(result.guid, result.delay)
}
sortServersCacheInPlace()
updateListAction.value = -1
}
@@ -647,6 +833,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
val content = intent.getStringExtra("content")
if (content == "0") {
onTestsFinished()
} else {
// cancelled or finished with non-zero count still in queue — mark as not testing
isTesting.value = false
}
}
}
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
>
<path
android:fillColor="#FFFFFFFF"
android:pathData="M320,880L360,600L160,600L520,80L600,80L560,400L800,400L400,880L320,880Z"/>
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorOnSurface"
android:pathData="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12z" />
</vector>
@@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="@android:color/white"
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z" />
</vector>
@@ -1,10 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorAccent">
<path
android:fillColor="@android:color/white"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M305,256L417,111Q429,95 445.5,87.5Q462,80 480,80Q498,80 514.5,87.5Q531,95 543,111L655,256L825,313Q851,321 866,342.5Q881,364 881,390Q881,402 877.5,414Q874,426 866,437L756,593L760,757Q761,792 737,816Q713,840 681,840Q679,840 659,837L480,787L301,837Q296,839 290,839.5Q284,840 279,840Q247,840 223,816Q199,792 200,757L204,592L95,437Q87,426 83.5,414Q80,402 80,390Q80,365 94.5,343.5Q109,322 135,313L305,256Z"/>
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M305,256L417,111Q429,95 445.5,87.5Q462,80 480,80Q498,80 514.5,87.5Q531,95 543,111L655,256L825,313Q851,321 866,342.5Q881,364 881,390Q881,402 877.5,414Q874,426 866,437L756,593L760,757Q761,792 737,816Q713,840 681,840Q679,840 659,837L480,787L301,837Q296,839 290,839.5Q284,840 279,840Q247,840 223,816Q199,792 200,757L204,592L95,437Q87,426 83.5,414Q80,402 80,390Q80,365 94.5,343.5Q109,322 135,313L305,256Z"/>
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M305,256L417,111Q429,95 445.5,87.5Q462,80 480,80Q498,80 514.5,87.5Q531,95 543,111L655,256L825,313Q851,321 866,342.5Q881,364 881,390Q881,402 877.5,414Q874,426 866,437L756,593L760,757Q761,792 737,816Q713,840 681,840Q679,840 659,837L480,787L301,837Q296,839 290,839.5Q284,840 279,840Q247,840 223,816Q199,792 200,757L204,592L95,437Q87,426 83.5,414Q80,402 80,390Q80,365 94.5,343.5Q109,322 135,313L305,256ZM354,325L160,389Q160,389 160,389Q160,389 160,389L284,568L280,759Q280,759 280,759Q280,759 280,759L480,704L680,760Q680,760 680,760Q680,760 680,760L676,568L800,391Q800,391 800,391Q800,391 800,391L606,325L480,160Q480,160 480,160Q480,160 480,160L354,325ZM480,460L480,460Q480,460 480,460Q480,460 480,460L480,460L480,460Q480,460 480,460Q480,460 480,460L480,460L480,460Q480,460 480,460Q480,460 480,460L480,460L480,460Q480,460 480,460Q480,460 480,460L480,460L480,460Q480,460 480,460Q480,460 480,460L480,460Z"/>
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM440,798L440,720Q407,720 383.5,696.5Q360,673 360,640L360,600L168,408Q165,426 162.5,444Q160,462 160,480Q160,601 239.5,692Q319,783 440,798ZM716,696Q736,674 752,648.5Q768,623 778.5,595.5Q789,568 794.5,539Q800,510 800,480Q800,382 745.5,301Q691,220 600,184L600,200Q600,233 576.5,256.5Q553,280 520,280L440,280L440,360Q440,377 428.5,388.5Q417,400 400,400L320,400L320,480L560,480Q577,480 588.5,491.5Q600,503 600,520L600,640L640,640Q666,640 687,655.5Q708,671 716,696Z"/>
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M98,423L266,255Q280,241 299,235Q318,229 338,233L390,244Q336,308 305,360Q274,412 245,486L98,423ZM303,514Q326,442 365.5,378Q405,314 461,258Q549,170 662,126.5Q775,83 873,100Q890,198 847,311Q804,424 716,512Q661,567 596,607.5Q531,648 459,671L303,514ZM579,394Q602,417 635.5,417Q669,417 692,394Q715,371 715,337.5Q715,304 692,281Q669,258 635.5,258Q602,258 579,281Q556,304 556,337.5Q556,371 579,394ZM551,875L487,728Q561,699 613.5,668Q666,637 730,583L740,635Q744,655 738,674.5Q732,694 718,708L551,875ZM162,642Q197,607 247,606.5Q297,606 332,641Q367,676 367,726Q367,776 332,811Q307,836 248.5,854Q190,872 87,886Q101,783 119,725Q137,667 162,642Z"/>
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-9,-4z"/>
</vector>
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorOnSurface"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
@@ -15,58 +15,58 @@
android:orientation="vertical"
android:padding="@dimen/padding_spacing_dp16">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="@string/split_tunneling_description"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:alpha="0.7" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="horizontal"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/container_per_app_proxy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/container_per_app_proxy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_per_app_proxy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/per_app_proxy_settings_enable"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:theme="@style/BrandedSwitch" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_per_app_proxy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/per_app_proxy_settings_enable"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:theme="@style/BrandedSwitch" />
</LinearLayout>
<LinearLayout
android:id="@+id/container_bypass_apps"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_bypass_apps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/switch_bypass_apps_mode"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:theme="@style/BrandedSwitch" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/container_bypass_apps"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_bypass_apps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/switch_bypass_apps_mode"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:theme="@style/BrandedSwitch" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
@@ -77,4 +77,4 @@
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" />
</LinearLayout>
</LinearLayout>
@@ -1,83 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:fitsSystemWindows="true"
android:orientation="vertical">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout
android:id="@+id/layout_check_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center|start"
android:orientation="horizontal"
android:padding="@dimen/padding_spacing_dp16">
<LinearLayout
android:layout_width="match_parent"
<ImageView
android:layout_width="@dimen/image_size_dp24"
android:layout_height="@dimen/image_size_dp24"
android:importantForAccessibility="no"
app:srcCompat="@drawable/ic_check_update_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center|start"
android:orientation="horizontal"
android:padding="@dimen/padding_spacing_dp16">
<ImageView
android:layout_width="@dimen/image_size_dp24"
android:layout_height="@dimen/image_size_dp24"
android:importantForAccessibility="no"
app:srcCompat="@drawable/ic_source_code_24dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/check_pre_release"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:paddingStart="@dimen/padding_spacing_dp16"
android:text="@string/update_check_pre_release"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:theme="@style/BrandedSwitch" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_check_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center|start"
android:orientation="horizontal"
android:padding="@dimen/padding_spacing_dp16">
<ImageView
android:layout_width="@dimen/image_size_dp24"
android:layout_height="@dimen/image_size_dp24"
android:importantForAccessibility="no"
app:srcCompat="@drawable/ic_check_update_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/padding_spacing_dp16"
android:text="@string/update_check_for_update"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/padding_spacing_dp16">
<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_about"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</LinearLayout>
android:paddingStart="@dimen/padding_spacing_dp16"
android:text="@string/update_check_for_update"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
</LinearLayout>
</ScrollView>
<!-- Hidden pre-release toggle (kept in layout for binding compatibility) -->
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/check_pre_release"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="@dimen/padding_spacing_dp16"
android:gravity="center"
android:layout_marginBottom="16dp"
android:alpha="0.5"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</LinearLayout>
@@ -4,22 +4,26 @@
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:background="@color/md_theme_surface">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@color/md_theme_surface"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
android:layout_height="?attr/actionBarSize"
app:title="@string/app_name"
app:titleCentered="true" />
</com.google.android.material.appbar.AppBarLayout>
@@ -43,17 +47,18 @@
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="invisible"
app:indicatorColor="@color/color_fab_active" />
app:indicatorColor="@color/md_theme_primary" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_group"
<LinearLayout
android:id="@+id/tab_slot_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorFullWidth="true"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabTextAppearance="@style/TabLayoutTextStyle" />
android:orientation="vertical" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color_light" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
@@ -64,6 +69,7 @@
android:layout_weight="1" />
<LinearLayout
android:id="@+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@@ -73,6 +79,25 @@
android:layout_height="1dp"
android:background="@color/divider_color_light" />
<LinearLayout
android:id="@+id/tab_slot_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorFullWidth="true"
app:tabMode="auto"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabRippleColor="@android:color/transparent"
app:tabTextAppearance="@style/TabLayoutTextStyle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -88,9 +113,10 @@
android:layout_marginEnd="16dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_lite_bolt"
android:src="@drawable/bolt_24"
app:tint="@color/colorWhite"
app:backgroundTint="@color/color_fab_inactive"
app:rippleColor="#33FFFFFF"
app:fabSize="normal"
app:maxImageSize="28dp"
app:elevation="4dp"
@@ -105,8 +131,9 @@
android:contentDescription="@string/tasker_start_service"
android:focusable="true"
android:nextFocusLeft="@+id/layout_test"
android:src="@drawable/ic_play_24dp"
android:src="@drawable/shield_24"
app:tint="@color/colorWhite"
app:rippleColor="#33FFFFFF"
app:fabSize="normal"
app:maxImageSize="28dp"
app:elevation="4dp"
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="8dp"
android:paddingTop="20dp"
android:paddingBottom="12dp">
<TextView
android:id="@+id/dialog_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/dialog_close_btn"
android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall"
android:textColor="?attr/colorOnSurface" />
<ImageButton
android:id="@+id/dialog_close_btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Закрыть"
android:src="@drawable/ic_close_24dp"
android:tint="?attr/colorOnSurfaceVariant" />
</RelativeLayout>
@@ -14,30 +14,23 @@
android:layout_height="@dimen/view_height_dp48"
android:padding="@dimen/padding_spacing_dp8" />
<LinearLayout
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:orientation="vertical">
android:maxLines="1"
android:paddingStart="@dimen/padding_spacing_dp8"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
<!-- package_name hidden but kept for adapter compatibility -->
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/package_name"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/package_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:paddingTop="@dimen/padding_spacing_dp8"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatCheckBox
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -45,4 +38,4 @@
android:focusable="false"
android:padding="@dimen/padding_spacing_dp8" />
</LinearLayout>
</LinearLayout>
@@ -99,16 +99,35 @@
</LinearLayout>
<ImageView
android:id="@+id/iv_favorite"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/padding_spacing_dp8"
android:src="@drawable/ic_star_empty" />
android:orientation="vertical"
android:gravity="end">
<ImageView
android:id="@+id/iv_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/padding_spacing_dp8"
android:src="@drawable/kid_star_outline_24" />
<ImageView
android:id="@+id/iv_copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/padding_spacing_dp8"
android:visibility="gone"
app:srcCompat="@drawable/ic_copy"
app:tint="?attr/colorAccent" />
</LinearLayout>
</LinearLayout>
@@ -19,16 +19,4 @@
android:title="@string/menu_item_invert_selection"
app:showAsAction="withText" />
<item
android:id="@+id/import_proxy_app"
android:icon="@drawable/ic_description_24dp"
android:title="@string/menu_item_import_proxy_app"
app:showAsAction="withText" />
<item
android:id="@+id/export_proxy_app"
android:icon="@drawable/ic_description_24dp"
android:title="@string/menu_item_export_proxy_app"
app:showAsAction="withText" />
</menu>
+7 -1
View File
@@ -15,7 +15,13 @@
<item
android:id="@+id/sub_update"
android:icon="@drawable/ic_check_update_24dp"
android:icon="@drawable/update_24"
android:title="@string/title_sub_update"
app:showAsAction="always" />
<item
android:id="@+id/filter_by_country"
android:icon="@drawable/public_24"
android:title="Фильтр по странам"
app:showAsAction="always" />
</menu>
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
</adaptive-icon>
@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
</adaptive-icon>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 10 KiB

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_fab_active">#90CAF9</color>
<color name="color_fab_active">#C0C0C0</color>
<color name="color_fab_inactive">#646464</color>
<color name="divider_color_light">#424242</color>
@@ -236,6 +236,9 @@
<string name="title_pref_group_all_display">Общая вкладка групп</string>
<string name="summary_pref_group_all_display">Показывать дополнительную вкладку со всеми профилями групп</string>
<string name="title_pref_show_copy_button">Кнопка копирования</string>
<string name="summary_pref_show_copy_button">Показывать кнопку копирования конфигурации сервера в буфер обмена</string>
<!-- AboutActivity -->
<string name="title_pref_feedback">Обратная связь</string>
<string name="summary_pref_feedback">Предложить улучшение или сообщить об ошибке на GitHub</string>
@@ -260,6 +263,11 @@
<string name="title_language">Язык</string>
<string name="title_ui_settings">Настройки интерфейса</string>
<string name="title_pref_ui_mode_night">Тема интерфейса</string>
<string name="title_pref_dynamic_colors">Динамические цвета (Material You)</string>
<string name="summary_pref_dynamic_colors">Использовать цвета обоев (Android 12+). Требует перезапуска.</string>
<string name="restart_required">Требуется перезапуск приложения</string>
<string name="title_pref_subscriptions_bottom">Подписки снизу</string>
<string name="summary_pref_subscriptions_bottom">Переместить вкладки подписок под список серверов</string>
<string name="title_pref_use_hev_tunnel">Использовать Hev TUN</string>
<string name="summary_pref_use_hev_tunnel">Если включено, TUN будет использовать hev-socks5-tunnel; иначе будет использован xray-core</string>
<string name="title_pref_hev_tunnel_loglevel">Подробность журнала HevTun</string>
+1 -1
View File
@@ -4,7 +4,7 @@
<color name="colorPingRed">#FF0099</color>
<color name="colorConfigType">#1976D2</color>
<color name="colorWhite">#FFFFFF</color>
<color name="color_fab_active">#1976D2</color>
<color name="color_fab_active">#000000</color>
<color name="color_fab_inactive">#9C9C9C</color>
<color name="divider_color_light">#E0E0E0</color>
<color name="colorIndicator">@color/md_theme_primary</color>
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>
<color name="ic_launcher_background">#1C1C1E</color>
</resources>
+15 -6
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">olcNG</string>
<string name="app_name" translatable="false">olcng</string>
<string name="app_widget_name">Switch</string>
<string name="app_tile_name">Switch</string>
<string name="app_tile_first_use">First use of this feature, please use the app to add server</string>
@@ -144,8 +144,9 @@
<string name="msg_downloading_content">Downloading content</string>
<string name="menu_item_export_proxy_app">Export to Clipboard</string>
<string name="menu_item_import_proxy_app">Import from Clipboard</string>
<string name="per_app_proxy_settings">Per-app settings</string>
<string name="per_app_proxy_settings_enable">Enable per-app</string>
<string name="per_app_proxy_settings">Раздельное туннелирование</string>
<string name="per_app_proxy_settings_enable">Включить</string>
<string name="split_tunneling_description">Выберите приложения, которые будут использовать VPN. В режиме обхода — выбранные приложения НЕ используют VPN.</string>
<!-- Preferences -->
<string name="title_settings">Settings</string>
@@ -160,6 +161,9 @@
<string name="title_pref_auto_sort_after_test">Auto sort after testing</string>
<string name="summary_pref_auto_sort_after_test">Test results may not be accurate;</string>
<string name="title_pref_show_copy_button">Show copy button</string>
<string name="summary_pref_show_copy_button">Show button to copy server configuration to clipboard</string>
<string name="title_mux_settings">Mux Settings</string>
<string name="title_pref_mux_enabled">Enable Mux</string>
<string name="summary_pref_mux_enabled">Faster, but it may cause unstable connectivity\nCustomize how to handle TCP, UDP and QUIC below</string>
@@ -266,11 +270,16 @@
<string name="title_language">Language</string>
<string name="title_ui_settings">UI settings</string>
<string name="title_pref_ui_mode_night">UI mode settings</string>
<string name="title_pref_dynamic_colors">Dynamic colors (Material You)</string>
<string name="summary_pref_dynamic_colors">Use wallpaper-based colors (Android 12+). Requires app restart.</string>
<string name="title_pref_subscriptions_bottom">Subscriptions panel at the bottom</string>
<string name="summary_pref_subscriptions_bottom">Move the subscription tabs below the server list</string>
<string name="title_pref_use_hev_tunnel">Enable Hev TUN Feature</string>
<string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use xray-core.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun read/write timeout (seconds) (tcp,udp default 300,60)</string>
<string name="restart_required">Restart required to apply changes</string>
<string name="title_logcat">Logcat</string>
<string name="logcat_copy">Copy</string>
<string name="logcat_clear">Clear</string>
@@ -337,14 +346,14 @@
<string name="connection_test_pending">Check Connectivity</string>
<string name="connection_test_testing">Testing…</string>
<string name="connection_test_testing_count">Testing %d configs</string>
<string name="connection_test_testing_count">Тестирование %d серверов</string>
<string name="connection_test_available">Success: Connection took %dms</string>
<string name="connection_test_error">Fail to detect internet connection: %s</string>
<string name="connection_test_fail">Internet Unavailable</string>
<string name="connection_test_error_status_code">Error code: #%d</string>
<string name="connection_connected">Connected, tap to check connection</string>
<string name="connection_not_connected">Not connected</string>
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
<string name="connection_not_connected">Готово к подключению</string>
<string name="connection_runing_task_left">Проверено успешно: %s</string>
<string name="import_subscription_success">Subscription imported Successfully</string>
<string name="import_subscription_failure">Import subscription failed</string>
+1 -1
View File
@@ -49,7 +49,7 @@
<item name="colorPrimaryInverse">@color/md_theme_inversePrimary</item>
<!-- Status bar and navigation bar - system bars -->
<item name="android:statusBarColor">@color/md_theme_surface</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@color/md_theme_surface</item>
<!-- Typography: use Roboto (Google's Material font) everywhere -->
@@ -28,6 +28,12 @@
android:summary="@string/summary_pref_group_all_display"
android:title="@string/title_pref_group_all_display" />
<CheckBoxPreference
android:key="pref_show_copy_button"
android:defaultValue="false"
android:summary="@string/summary_pref_show_copy_button"
android:title="@string/title_pref_show_copy_button" />
<ListPreference
android:defaultValue="auto"
android:entries="@array/language_select"
@@ -44,6 +50,18 @@
android:summary="%s"
android:title="@string/title_pref_ui_mode_night" />
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_subscriptions_bottom"
android:summary="@string/summary_pref_subscriptions_bottom"
android:title="@string/title_pref_subscriptions_bottom" />
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_dynamic_colors"
android:summary="@string/summary_pref_dynamic_colors"
android:title="@string/title_pref_dynamic_colors" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_vpn_settings">
+1
View File
@@ -66,6 +66,7 @@ recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "r
preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "preferenceKtx" }
androidx-viewpager2 = { module = "androidx.viewpager2:viewpager2", version.ref = "viewpager2" }
androidx-fragment = { module = "androidx.fragment:fragment-ktx", version.ref = "fragment" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }