Bug fix
This commit is contained in:
@@ -641,6 +641,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
e.printStackTrace()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fun setTestState(content: String?) {
|
||||
binding.tvTestState.text = content
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.v2ray.ang.ui
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.v2ray.ang.AppConfig
|
||||
import android.util.Log
|
||||
import com.v2ray.ang.R
|
||||
import com.v2ray.ang.databinding.ActivityLogcatBinding
|
||||
import com.v2ray.ang.extension.toast
|
||||
@@ -24,32 +24,21 @@ class UrlSchemeActivity : BaseActivity() {
|
||||
if (action == Intent.ACTION_SEND) {
|
||||
if ("text/plain" == type) {
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||
val uri = Uri.parse(it)
|
||||
if (uri.scheme?.startsWith(AppConfig.PROTOCOL_HTTPS) == true || uri.scheme?.startsWith(
|
||||
AppConfig.PROTOCOL_HTTP
|
||||
) == true
|
||||
) {
|
||||
val name = uri.getQueryParameter("name") ?: "Subscription"
|
||||
importSubscription(it, name)
|
||||
} else {
|
||||
importConfig(it)
|
||||
}
|
||||
parseUri(it)
|
||||
}
|
||||
}
|
||||
} else if (action == Intent.ACTION_VIEW) {
|
||||
when (data?.host) {
|
||||
"install-config" -> {
|
||||
val uri: Uri? = intent.data
|
||||
val shareUrl: String = uri?.getQueryParameter("url")!!
|
||||
toast(shareUrl)
|
||||
importConfig(shareUrl)
|
||||
val shareUrl = uri?.getQueryParameter("url") ?: ""
|
||||
parseUri(shareUrl)
|
||||
}
|
||||
|
||||
"install-sub" -> {
|
||||
val uri: Uri? = intent.data
|
||||
val url = uri?.getQueryParameter("url")!!
|
||||
val name = uri.getQueryParameter("name") ?: "Subscription"
|
||||
importSubscription(url, name)
|
||||
val shareUrl = uri?.getQueryParameter("url") ?: ""
|
||||
parseUri(shareUrl)
|
||||
}
|
||||
|
||||
else -> {
|
||||
@@ -57,10 +46,8 @@ class UrlSchemeActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
@@ -68,19 +55,21 @@ class UrlSchemeActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun importSubscription(url: String, name: String) {
|
||||
val decodedUrl = URLDecoder.decode(url, "UTF-8")
|
||||
private fun parseUri(uriString: String?) {
|
||||
if (uriString.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
Log.d("UrlScheme", uriString)
|
||||
|
||||
val check = AngConfigManager.importSubscription(name, decodedUrl)
|
||||
if (check) toast(R.string.import_subscription_success) else toast(R.string.import_subscription_failure)
|
||||
}
|
||||
|
||||
private fun importConfig(shareUrl: String) {
|
||||
val count = AngConfigManager.importBatchConfig(shareUrl, "", false)
|
||||
if (count > 0) {
|
||||
toast(R.string.toast_success)
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
val decodedUrl = URLDecoder.decode(uriString, "UTF-8")
|
||||
val uri = Uri.parse(decodedUrl)
|
||||
if (uri != null) {
|
||||
val count = AngConfigManager.importBatchConfig(decodedUrl, "", false)
|
||||
if (count > 0) {
|
||||
toast(R.string.import_subscription_success)
|
||||
} else {
|
||||
toast(R.string.import_subscription_failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,11 +217,9 @@ object AngConfigManager {
|
||||
return R.string.toast_none_data
|
||||
}
|
||||
|
||||
//maybe sub
|
||||
if (TextUtils.isEmpty(subid) && (str.startsWith(PROTOCOL_HTTP) || str.startsWith(
|
||||
PROTOCOL_HTTPS
|
||||
))
|
||||
) {
|
||||
//maybe Subscription
|
||||
if (TextUtils.isEmpty(subid)
|
||||
&& (str.startsWith(PROTOCOL_HTTP) || str.startsWith(PROTOCOL_HTTPS))) {
|
||||
MmkvManager.importUrlAsSubscription(str)
|
||||
return 0
|
||||
}
|
||||
@@ -1025,24 +1023,7 @@ object AngConfigManager {
|
||||
return 0
|
||||
}
|
||||
|
||||
fun importSubscription(remark: String, url: String, enabled: Boolean = true): Boolean {
|
||||
val subId = Utils.getUuid()
|
||||
val subItem = SubscriptionItem()
|
||||
|
||||
|
||||
subItem.remarks = remark
|
||||
subItem.url = url
|
||||
subItem.enabled = enabled
|
||||
|
||||
if (TextUtils.isEmpty(subItem.remarks) || TextUtils.isEmpty(subItem.url)) {
|
||||
return false
|
||||
}
|
||||
subStorage?.encode(subId, Gson().toJson(subItem))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun appendCustomConfigServer(server: String?, subid: String): Int {
|
||||
fun appendCustomConfigServer(server: String?, subid: String): Int {
|
||||
if (server == null) {
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user