diff --git a/V2rayNG/app/build.gradle b/V2rayNG/app/build.gradle index 92d7a52c..54f8d845 100644 --- a/V2rayNG/app/build.gradle +++ b/V2rayNG/app/build.gradle @@ -109,11 +109,11 @@ dependencies { implementation 'io.reactivex:rxjava:1.3.8' implementation 'io.reactivex:rxandroid:1.2.1' implementation 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar' - implementation 'me.dm7.barcodescanner:core:1.9.8' - implementation 'me.dm7.barcodescanner:zxing:1.9.8' implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar' implementation 'me.drakeet.support:toastcompat:1.1.0' implementation 'com.blacksquircle.ui:editorkit:2.1.1' implementation 'com.blacksquircle.ui:language-base:2.1.1' implementation 'com.blacksquircle.ui:language-json:2.1.1' + implementation 'io.github.g00fy2.quickie:quickie-bundled:1.6.0' + implementation 'com.google.zxing:core:3.5.1' } \ No newline at end of file diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt index 3793e583..5c7e6a31 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt @@ -39,6 +39,7 @@ object AppConfig { const val PREF_PER_APP_PROXY_SET = "pref_per_app_proxy_set" const val PREF_BYPASS_APPS = "pref_bypass_apps" const val PREF_CONFIRM_REMOVE = "pref_confirm_remove" + const val PREF_START_SCAN_IMMEDIATE = "pref_start_scan_immediate" const val HTTP_PROTOCOL: String = "http://" const val HTTPS_PROTOCOL: String = "https://" diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScannerActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScannerActivity.kt index 883f51b5..33b7f685 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScannerActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ScannerActivity.kt @@ -3,58 +3,62 @@ package com.v2ray.ang.ui import android.Manifest import android.app.Activity import android.os.Bundle -import com.google.zxing.Result -import me.dm7.barcodescanner.zxing.ZXingScannerView import android.content.Intent import android.graphics.BitmapFactory import android.os.Build import android.view.Menu import android.view.MenuItem import androidx.activity.result.contract.ActivityResultContracts -import com.google.zxing.BarcodeFormat import com.tbruyelle.rxpermissions.RxPermissions +import com.tencent.mmkv.MMKV +import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.extension.toast +import com.v2ray.ang.util.MmkvManager import com.v2ray.ang.util.QRCodeDecoder +import io.github.g00fy2.quickie.QRResult +import io.github.g00fy2.quickie.ScanCustomCode +import io.github.g00fy2.quickie.config.ScannerConfig -class ScannerActivity : BaseActivity(), ZXingScannerView.ResultHandler { +class ScannerActivity : BaseActivity(){ - private var mScannerView: ZXingScannerView? = null + private val scanQrCode = registerForActivityResult(ScanCustomCode(), ::handleResult) + private val settingsStorage by lazy { MMKV.mmkvWithID(MmkvManager.ID_SETTING, MMKV.MULTI_PROCESS_MODE) } public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - mScannerView = ZXingScannerView(this) // Programmatically initialize the scanner view - mScannerView?.setAutoFocus(true) - val formats = ArrayList() - formats.add(BarcodeFormat.QR_CODE) - mScannerView?.setFormats(formats) - - setContentView(mScannerView) // Set the scanner view as the content view + if (settingsStorage?.decodeBool(AppConfig.PREF_START_SCAN_IMMEDIATE) == true) { + launchScan() + } supportActionBar?.setDisplayHomeAsUpEnabled(true) } public override fun onResume() { super.onResume() - mScannerView!!.setResultHandler(this) // Register ourselves as a handler for scan results. - mScannerView!!.startCamera() // Start camera on resume } public override fun onPause() { super.onPause() - mScannerView!!.stopCamera() // Stop camera on pause } - override fun handleResult(rawResult: Result) { - // Do something with the result here -// Log.v(FragmentActivity.TAG, rawResult.text) // Prints scan results -// Log.v(FragmentActivity.TAG, rawResult.barcodeFormat.toString()) // Prints the scan format (qrcode, pdf417 etc.) + private fun launchScan(){ + scanQrCode.launch( + ScannerConfig.build { + setHapticSuccessFeedback(true) // enable (default) or disable haptic feedback when a barcode was detected + setShowTorchToggle(true) // show or hide (default) torch/flashlight toggle button + setShowCloseButton(true) // show or hide (default) close button + } + ) + } - finished(rawResult.text) - - // If you would like to resume scanning, call this method below: -// mScannerView!!.resumeCameraPreview(this) + private fun handleResult(result: QRResult) { + if (result is QRResult.QRSuccess ) { + finished(result.content.rawValue) + } else { + finish() + } } private fun finished(text: String) { @@ -70,6 +74,10 @@ class ScannerActivity : BaseActivity(), ZXingScannerView.ResultHandler { } override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) { + R.id.scan_code -> { + launchScan() + true + } R.id.select_photo -> { val permission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { Manifest.permission.READ_MEDIA_IMAGES diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt index 2b40cc39..d2c7e913 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt @@ -50,7 +50,8 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application AppConfig.PREF_PREFER_IPV6, AppConfig.PREF_PER_APP_PROXY, AppConfig.PREF_BYPASS_APPS, - AppConfig.PREF_CONFIRM_REMOVE, -> { + AppConfig.PREF_CONFIRM_REMOVE, + AppConfig.PREF_START_SCAN_IMMEDIATE, -> { settingsStorage?.encode(key, sharedPreferences.getBoolean(key, false)) } AppConfig.PREF_SNIFFING_ENABLED -> { diff --git a/V2rayNG/app/src/main/res/menu/menu_scanner.xml b/V2rayNG/app/src/main/res/menu/menu_scanner.xml index b986bb5a..37701804 100644 --- a/V2rayNG/app/src/main/res/menu/menu_scanner.xml +++ b/V2rayNG/app/src/main/res/menu/menu_scanner.xml @@ -1,6 +1,11 @@ + تایید حذف پرونده پیکربندی آیا برای حذف پرونده پیکربندی نیاز به تایید دوم توسط کاربر است + Start scanning immediately + Open the camera to scan immediately at startup, otherwise you can choose to scan the code or select a photo in the toolbar + بازخورد بهبودهای بازخورد یا اشکالات در گیت‌هاب عضویت در گروه تلگرام @@ -159,6 +162,7 @@ حالت برای راهنمایی بیشتر روی این متن، کلیک کنید زبان + UI settings گزارشات کپی diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml index 995d5573..6600ecdc 100644 --- a/V2rayNG/app/src/main/res/values-ru/strings.xml +++ b/V2rayNG/app/src/main/res/values-ru/strings.xml @@ -152,6 +152,9 @@ Подтверждение удаления профиля Требовать двойное подтверждение удаления профиля + Start scanning immediately + Open the camera to scan immediately at startup, otherwise you can choose to scan the code or select a photo in the toolbar + Обратная связь Предложить улучшение или сообщить об ошибке на GitHub Присоединиться к группе в Telegram @@ -164,6 +167,7 @@ Режим Нажмите для получения дополнительной информации Язык + UI settings Системный журнал Копировать diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml index 46d5f515..ebe9e3a9 100644 --- a/V2rayNG/app/src/main/res/values-vi/strings.xml +++ b/V2rayNG/app/src/main/res/values-vi/strings.xml @@ -146,6 +146,9 @@ Hiển thị thông báo xác nhận xoá cấu hình Hiển thị thông báo xác nhận xoá cấu hình khi bạn xoá một cấu hình. + Start scanning immediately + Open the camera to scan immediately at startup, otherwise you can choose to scan the code or select a photo in the toolbar + Phản hồi lỗi Phản hồi cải tiến hoặc lỗi lên GitHub Tham gia nhóm Telegram @@ -158,6 +161,7 @@ Chế độ kết nối Nhấn vào đây nếu bạn cần trợ giúp! Ngôn ngữ + UI settings Nhật ký hoạt động Sao chép nhật ký diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 984caa79..fa47d25b 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -146,6 +146,9 @@ 删除配置文件确认 删除配置文件是否需要用户二次确认 + 立即启动扫码 + 启动时立即打开相机扫描,否则可在工具栏选择扫码或选照片 + 反馈 反馈改进或漏洞至 GitHub 加入Telegram Group @@ -158,6 +161,7 @@ 模式 点此查看更多帮助 语言 + 用户界面设置 Logcat 复制 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index 968913b1..9970045f 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -146,6 +146,9 @@ 刪除配置文件確認 刪除配置文件是否需要用戶二次確認 + 立即啟動掃碼 + 啟動時立即打開相機掃描,否則可在工具欄選擇掃碼或選照片 + 意見回饋 前往 GitHub 回報錯誤 加入 Telegram 群組 @@ -158,6 +161,7 @@ 模式 輕觸以檢視說明 語言 + 用戶界面設置 Logcat 複製 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index 4108aee4..42c0dddc 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -154,6 +154,9 @@ Delete configuration file confirmation Whether to delete the configuration file requires a second confirmation by the user + Start scanning immediately + Open the camera to scan immediately at startup, otherwise you can choose to scan the code or select a photo in the toolbar + Feedback Feedback enhancements or bugs to GitHub Join Telegram Group @@ -166,6 +169,7 @@ Mode Click me for more help Language + UI settings Logcat Copy diff --git a/V2rayNG/app/src/main/res/xml/pref_settings.xml b/V2rayNG/app/src/main/res/xml/pref_settings.xml index 73cec7d9..660f77c7 100644 --- a/V2rayNG/app/src/main/res/xml/pref_settings.xml +++ b/V2rayNG/app/src/main/res/xml/pref_settings.xml @@ -124,6 +124,20 @@ android:summary="%s" android:title="@string/title_mode" /> + + + + + + + + - -