diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 3bd47e00..1f737d4f 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -24,6 +24,8 @@ dependencies {
implementation(libs.androidx.coordinator)
implementation(libs.androidx.recyclerview)
implementation(libs.google.material)
+
+
}
tasks.getByName("clean", type = Delete::class) {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index cd595f0b..0d172f2b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -197,5 +197,9 @@
+
+
diff --git a/app/src/main/java/com/github/kr328/clash/NewProfileActivity.kt b/app/src/main/java/com/github/kr328/clash/NewProfileActivity.kt
index 529c146f..1947c549 100644
--- a/app/src/main/java/com/github/kr328/clash/NewProfileActivity.kt
+++ b/app/src/main/java/com/github/kr328/clash/NewProfileActivity.kt
@@ -47,6 +47,14 @@ class NewProfileActivity : BaseActivity() {
create(Profile.Type.File, name)
is ProfileProvider.Url ->
create(Profile.Type.Url, name)
+ is ProfileProvider.QR -> {
+ val provider = it.provider as ProfileProvider.QR
+ if (provider.url!=null){
+ create(Profile.Type.Url, name, provider.url!!)
+ }else{
+ null
+ }
+ }
is ProfileProvider.External -> {
val data = p.get()
@@ -138,7 +146,7 @@ class NewProfileActivity : BaseActivity() {
ProfileProvider.External(name.toString(), summary.toString(), icon, intent)
}
- listOf(ProfileProvider.File(self), ProfileProvider.Url(self)) + providers
+ listOf(ProfileProvider.File(self), ProfileProvider.Url(self),ProfileProvider.QR(self)) + providers
}
}
}
diff --git a/design/build.gradle.kts b/design/build.gradle.kts
index 6e4421e6..74fd10e3 100644
--- a/design/build.gradle.kts
+++ b/design/build.gradle.kts
@@ -18,4 +18,5 @@ dependencies {
implementation(libs.androidx.fragment)
implementation(libs.androidx.viewpager)
implementation(libs.google.material)
+ implementation("com.google.android.gms:play-services-code-scanner:16.1.0")
}
diff --git a/design/src/main/java/com/github/kr328/clash/design/NewProfileDesign.kt b/design/src/main/java/com/github/kr328/clash/design/NewProfileDesign.kt
index e38d01e7..ee59f874 100644
--- a/design/src/main/java/com/github/kr328/clash/design/NewProfileDesign.kt
+++ b/design/src/main/java/com/github/kr328/clash/design/NewProfileDesign.kt
@@ -6,6 +6,9 @@ import com.github.kr328.clash.design.adapter.ProfileProviderAdapter
import com.github.kr328.clash.design.databinding.DesignNewProfileBinding
import com.github.kr328.clash.design.model.ProfileProvider
import com.github.kr328.clash.design.util.*
+import com.google.mlkit.vision.barcode.common.Barcode
+import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
+import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
class NewProfileDesign(context: Context) : Design(context) {
sealed class Request {
@@ -38,7 +41,31 @@ class NewProfileDesign(context: Context) : Design(cont
}
private fun requestCreate(provider: ProfileProvider) {
- requests.trySend(Request.Create(provider))
+ if (provider is ProfileProvider.QR){
+ val options = GmsBarcodeScannerOptions.Builder()
+ .setBarcodeFormats(
+ Barcode.FORMAT_QR_CODE,
+ Barcode.FORMAT_AZTEC)
+ .enableAutoZoom() // available on 16.1.0 and higher
+ .build()
+ val scanner = GmsBarcodeScanning.getClient(context,options)
+ scanner.startScan()
+ .addOnSuccessListener { barcode ->
+ // Task completed successfully
+ provider.url = barcode.rawValue
+ requests.trySend(Request.Create(provider))
+ }
+ .addOnCanceledListener {
+ // Task canceled
+ }
+ .addOnFailureListener { e ->
+ // Task failed with an exception
+ }
+
+ }else{
+ requests.trySend(Request.Create(provider))
+ }
+
}
private fun requestDetail(provider: ProfileProvider): Boolean {
diff --git a/design/src/main/java/com/github/kr328/clash/design/model/ProfileProvider.kt b/design/src/main/java/com/github/kr328/clash/design/model/ProfileProvider.kt
index 7b09c22b..7df22ebb 100644
--- a/design/src/main/java/com/github/kr328/clash/design/model/ProfileProvider.kt
+++ b/design/src/main/java/com/github/kr328/clash/design/model/ProfileProvider.kt
@@ -14,6 +14,8 @@ sealed class ProfileProvider {
get() = context.getString(R.string.import_from_file)
override val icon: Drawable?
get() = context.getDrawableCompat(R.drawable.ic_baseline_attach_file)
+
+
}
class Url(private val context: Context) : ProfileProvider() {
@@ -25,6 +27,15 @@ sealed class ProfileProvider {
get() = context.getDrawableCompat(R.drawable.ic_baseline_cloud_download)
}
+ class QR(private val context: Context) : ProfileProvider() {
+ override val name: String
+ get() = context.getString(R.string.qr)
+ override val summary: String
+ get() = context.getString(R.string.import_from_qr)
+ override val icon: Drawable?
+ get() = context.getDrawableCompat(R.drawable.baseline_qr_code_scanner)
+ var url:String? =null
+ }
class External(
override val name: String,
override val summary: String,
diff --git a/design/src/main/res/drawable/baseline_qr_code_scanner.xml b/design/src/main/res/drawable/baseline_qr_code_scanner.xml
new file mode 100644
index 00000000..0c334193
--- /dev/null
+++ b/design/src/main/res/drawable/baseline_qr_code_scanner.xml
@@ -0,0 +1,9 @@
+
+
+
+
diff --git a/design/src/main/res/values-ja-rJP/strings.xml b/design/src/main/res/values-ja-rJP/strings.xml
index 102066fb..3dd21769 100644
--- a/design/src/main/res/values-ja-rJP/strings.xml
+++ b/design/src/main/res/values-ja-rJP/strings.xml
@@ -30,6 +30,7 @@
ファイルからインポート
URL
URLからインポート
+ QRコードからインポート
外部入力
%s (未保存)
アプリが破損しています
diff --git a/design/src/main/res/values-ko-rKR/strings.xml b/design/src/main/res/values-ko-rKR/strings.xml
index dc852797..f8ad8743 100644
--- a/design/src/main/res/values-ko-rKR/strings.xml
+++ b/design/src/main/res/values-ko-rKR/strings.xml
@@ -31,6 +31,7 @@
URL
URL에서 가져오기
외부
+ QR코드에서 가져오기
%s (저장되지 않음)
앱 오류
앱 중지
diff --git a/design/src/main/res/values-ru/strings.xml b/design/src/main/res/values-ru/strings.xml
index 753a0f1d..f95bc379 100644
--- a/design/src/main/res/values-ru/strings.xml
+++ b/design/src/main/res/values-ru/strings.xml
@@ -38,6 +38,7 @@
URL
Импорт из URL
Внешний
+ Импорт из QR-кода
%s (не сохранён)
Приложение сломано
diff --git a/design/src/main/res/values-zh-rHK/strings.xml b/design/src/main/res/values-zh-rHK/strings.xml
index 51d62c13..c7bd6d3b 100644
--- a/design/src/main/res/values-zh-rHK/strings.xml
+++ b/design/src/main/res/values-zh-rHK/strings.xml
@@ -41,6 +41,7 @@
從文件導入
從 URL 導入
界面
+ 從二維碼導入
無效的 URL
Logcat
日誌
diff --git a/design/src/main/res/values-zh-rTW/strings.xml b/design/src/main/res/values-zh-rTW/strings.xml
index 91c69fa7..f22b5a29 100644
--- a/design/src/main/res/values-zh-rTW/strings.xml
+++ b/design/src/main/res/values-zh-rTW/strings.xml
@@ -40,6 +40,7 @@
歷史
從檔案匯入
從 URL 匯入
+ 從二維碼導入
介面
無效 URL
Logcat
diff --git a/design/src/main/res/values-zh/strings.xml b/design/src/main/res/values-zh/strings.xml
index 64e8dea0..be75986d 100644
--- a/design/src/main/res/values-zh/strings.xml
+++ b/design/src/main/res/values-zh/strings.xml
@@ -40,6 +40,7 @@
历史
从文件导入
从 URL 导入
+ 从二维码导入
界面
无效的 URL
Logcat
diff --git a/design/src/main/res/values/strings.xml b/design/src/main/res/values/strings.xml
index 2840f209..08a4c740 100644
--- a/design/src/main/res/values/strings.xml
+++ b/design/src/main/res/values/strings.xml
@@ -41,7 +41,9 @@
File
Import from File
URL
+ QR
Import from URL
+ Import from QR
External
%s (Unsaved)