一键连进入获取订阅地址
This commit is contained in:
parent
3fad9e6843
commit
09bcec1012
|
|
@ -15,6 +15,7 @@ import android.widget.ImageView
|
|||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
|
|
@ -31,17 +32,20 @@ import com.tencent.mmkv.MMKV
|
|||
import com.yingmao.clash.R
|
||||
import com.yingmao.clash.act.ProxyModeActivity.ProxyMode
|
||||
import com.yingmao.clash.act.NewMainActivity.Companion.clashBinder
|
||||
import com.yingmao.clash.act.NewMainActivity.Companion.isSubed
|
||||
import com.yingmao.clash.act.NewMainActivity.Companion.newUuid
|
||||
import com.yingmao.clash.act.NewMainActivity.Companion.profileBinder
|
||||
import com.yingmao.clash.act.NewMainActivity.Companion.subUrl
|
||||
import com.yingmao.clash.app.MainApplication
|
||||
import com.yingmao.clash.base.BaseActivity
|
||||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.conf.Conf
|
||||
import com.yingmao.clash.entity.ClashNodebBean
|
||||
import com.yingmao.clash.fragment.NewAccFragment
|
||||
import com.yingmao.clash.fragment.NewAccFragment.Companion.CHECK_NODE_REQUEST_CODE
|
||||
import com.yingmao.clash.fragment.NewAccFragment.Companion.clashRunning
|
||||
import com.yingmao.clash.fragment.NewAccFragment.Companion.isGlo
|
||||
import com.yingmao.clash.net.http.HttpReqType
|
||||
import com.yingmao.clash.net.http.HttpStatus
|
||||
import com.yingmao.clash.net.http.entity.SubscriptionRsp
|
||||
import com.yingmao.clash.remote.Resource
|
||||
import com.yingmao.clash.util.Utils
|
||||
import com.yingmao.clash.view.RxToast
|
||||
|
|
@ -78,8 +82,8 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_change_node)
|
||||
setMoreBar("线路测速", this)
|
||||
changeNodeVM = ViewModelProvider(this)[ChangeNodeVM::class.java]
|
||||
observe(this, changeNodeVM)
|
||||
initData()
|
||||
initViews()
|
||||
}
|
||||
|
|
@ -91,7 +95,9 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
}
|
||||
|
||||
private fun initData() {
|
||||
cacheNodeStr = MMKV.defaultMMKV().decodeString(BZYConstants.NODE_All_ITEM_NAME_KEY, "");
|
||||
//进入获取订阅地址信息
|
||||
changeNodeVM.getAirNodes()
|
||||
cacheNodeStr = MMKV.defaultMMKV().decodeString(BZYConstants.NODE_All_ITEM_NAME_KEY, "")
|
||||
val intentFilter = IntentFilter(Intents.ACTION_NODE_LIST)
|
||||
broadcastReceiver = NodeListBR()
|
||||
if (Build.VERSION.SDK_INT >= 34 && applicationInfo.targetSdkVersion >= 34) {
|
||||
|
|
@ -106,8 +112,104 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
intentFilter
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun httpSuccess(httpStatus: HttpStatus.Success) {
|
||||
if(httpStatus.reqType == HttpReqType.GET_AIRNODES){
|
||||
val data = httpStatus.rsp as SubscriptionRsp
|
||||
if (data.code=="1000") {
|
||||
data.data.let { url ->
|
||||
if(subUrl!=url){
|
||||
// var url2="https://api.ymvpnpro11.cc:8700/7air2vr7ikiqzgvxz/api/v1/client/subscribe?token=5af82930d222840cbc2dec572b21d6c6"
|
||||
if (url.isNotEmpty()) {
|
||||
//todo 判断订阅地址是否修改过,未修改就用接口返回的地址反之使用本地修改的地址
|
||||
val proSubUrl =
|
||||
MMKV.defaultMMKV().decodeString(BZYConstants.PROFILE_SUB_URL, "")
|
||||
subUrl = if (!TextUtils.isEmpty(proSubUrl)){
|
||||
if (proSubUrl == url) {
|
||||
url
|
||||
} else {
|
||||
proSubUrl
|
||||
}
|
||||
}else{
|
||||
url
|
||||
}
|
||||
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
subUrl?.let { setSubUrl(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
RxToast.error(resources.getString(R.string.NodeAcquisitionFailed) + "${data.msg}")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun setSubUrl(url: String) {
|
||||
Log.d("setSub2 2")
|
||||
profileBinder?.let { pm ->
|
||||
Log.d("setSub2 3")
|
||||
pm.queryAll().forEach { itemPro ->
|
||||
Log.d("setSub2 itemPro ==>${itemPro}")
|
||||
if (itemPro.name != Conf.getClashConfName(this@ChangeNodeActivity.applicationContext)) {
|
||||
Log.d("setSub2 delete ==>${itemPro.name}")
|
||||
pm.delete(itemPro.uuid)
|
||||
}
|
||||
}
|
||||
val pro = pm.queryActive()
|
||||
Log.d("setSub2 4")
|
||||
pro?.let {
|
||||
val actName = it.name
|
||||
Log.d("new main actname==>$actName")
|
||||
Log.d("setSub2 pro 已存在 ==>")
|
||||
pm.setActive(it)
|
||||
delay(500)
|
||||
if (!TextUtils.isEmpty(pro.source)) {
|
||||
if (pro.source != url) {
|
||||
Log.d("setSub2 patch")
|
||||
pm.patch(pro.uuid, pro.name, url, 1800000L)
|
||||
pm.commit(pro.uuid) { status ->
|
||||
Log.d("setSub2 updateStatus: " + Gson().toJson(status.args) + ", pro==>" + status.progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
pm.update(it.uuid)
|
||||
|
||||
newUuid = pro.uuid.toString();
|
||||
isSubed = true
|
||||
Log.d("setSub2 setActive end")
|
||||
} ?: run {
|
||||
createMyProfile(pm, url)
|
||||
}
|
||||
}
|
||||
}
|
||||
private suspend fun createMyProfile(pm: IProfileManager, url: String) {
|
||||
val uuid: UUID = pm.create(
|
||||
Profile.Type.Url, Conf.getClashConfName(this@ChangeNodeActivity.applicationContext)
|
||||
)
|
||||
delay(500)
|
||||
pm.queryByUUID(uuid)?.let { qPro ->
|
||||
pm.setActive(qPro)
|
||||
pm.patch(
|
||||
qPro.uuid, qPro.name,
|
||||
url, 1800000L
|
||||
)
|
||||
pm.commit(qPro.uuid) { status ->
|
||||
android.util.Log.d(
|
||||
Conf.TAG,
|
||||
"new updateStatus: " + Gson().toJson(status.args) + ", pro==>" + status.progress
|
||||
)
|
||||
}
|
||||
newUuid = qPro.uuid.toString()
|
||||
isSubed = true
|
||||
}
|
||||
}
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun initViews() {
|
||||
aiBack=findViewById(R.id.aiBack)
|
||||
|
|
@ -298,6 +400,7 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
swipeLayout.isRefreshing = true
|
||||
updateProfile(false)
|
||||
swipeLayout.isRefreshing = false
|
||||
changeNodeVM.getAirNodes()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -395,8 +498,6 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
nodeListAdapter.selectedPosition
|
||||
nodeListAdapter.setOnItemClickListener { baseQuickAdapter: BaseQuickAdapter<*, *>, view: View, position: Int ->
|
||||
(baseQuickAdapter.getItem(position) as ClashNodebBean).let { profile ->
|
||||
com.cncat.vpn.common.log.Log.i("select_node : ${profile.name}")
|
||||
// checkedNode = profile
|
||||
MMKV.defaultMMKV().encode(BZYConstants.NODE_SELECTED_NAME_KEY, profile.name)
|
||||
nodeListAdapter.notifyItemChanged(nodeListAdapter.selectedPosition)
|
||||
nodeListAdapter.selectedPosition =
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ class NewMainActivity : BaseActivity() {
|
|||
} else {
|
||||
RxToast.error(resources.getString(R.string.NodeAcquisitionFailed) + "${data.msg}")
|
||||
}
|
||||
data.data?.let { url ->
|
||||
data.data.let { url ->
|
||||
android.util.Log.e("Data", "机场URL:=${url}")
|
||||
// var url2="https://api.ymvpnpro11.cc:8700/7air2vr7ikiqzgvxz/api/v1/client/subscribe?token=5af82930d222840cbc2dec572b21d6c6"
|
||||
if (url.isNotEmpty()) {
|
||||
|
|
|
|||
|
|
@ -93,10 +93,10 @@ class NetService private constructor() : INetService {
|
|||
// .sslSocketFactory(getSSLSocketFactory(), CustomTrustManager())//信任所有证书
|
||||
.sslSocketFactory(getSSLSocketFactory(), trustAllCerts[0] as X509TrustManager)
|
||||
.hostnameVerifier(getHostnameVerifier()!!)
|
||||
if (BuildConfig.DEBUG) {
|
||||
builder.addInterceptor(loggingInterceptor)
|
||||
}
|
||||
// if (BuildConfig.DEBUG) {
|
||||
// builder.addInterceptor(loggingInterceptor)
|
||||
// }
|
||||
builder.addInterceptor(loggingInterceptor)
|
||||
return builder.build()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,6 +138,25 @@ subprojects {
|
|||
)
|
||||
)
|
||||
}
|
||||
create("9505") {
|
||||
isDefault = true
|
||||
dimension = flavorDimensionList[0]
|
||||
buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")")
|
||||
buildConfigField("boolean", "is_back_cn", "false")
|
||||
buildConfigField("boolean", "is_ym", "true")
|
||||
buildConfigField("boolean", "is_tz", "false")
|
||||
buildConfigField("boolean", "is_yunti", "false")
|
||||
buildConfigField("String", "applicationId", "\"com.jsq.wufu\"")
|
||||
buildConfigField("String", "service_url", "\"https://api.yijianlianjsq.com/\"")
|
||||
buildConfigField("boolean", "is_free", "false")
|
||||
buildConfigField("String", "productId", "\"9505\"")
|
||||
manifestPlaceholders(
|
||||
mapOf(
|
||||
"APP_NAME" to "@string/wf",
|
||||
"APP_ICON" to "@mipmap/oneclickconnection"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
getByName("8888") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue