1.一键连更改模式选择代码
This commit is contained in:
level 2025-12-08 18:56:39 +08:00
parent bd1132f741
commit 3d9c1b4585
3 changed files with 73 additions and 45 deletions

View File

@ -132,27 +132,28 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
tvProA.setOnClickListener { tvProA.setOnClickListener {
if(!clashRunning){ val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clIntelligentMode ==>${getIsGlo}")
if(getIsGlo){
setBackground(ProxyMode.PAC) setBackground(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false) MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
checkGlo() checkGlo()
}else{
RxToast.info(resources.getString(R.string.closeRunningChoose))
}
if(clashRunning){
RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener
} }
} }
tvProj.setOnClickListener { tvProj.setOnClickListener {
if(!clashRunning){ if (!clashRunning) {
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true) RxToast.info(resources.getString(R.string.SwitchingSourceModel))
setBackground(ProxyMode.GLOBAL) return@setOnClickListener
}else{
RxToast.info(resources.getString(R.string.closeRunningChoose))
} }
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clGlobalModel ==>${getIsGlo}")
if (!getIsGlo) {
setBackground(ProxyMode.GLOBAL)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
checkGlo()
}
} }
aiBack.setOnClickListener { aiBack.setOnClickListener {

View File

@ -229,20 +229,33 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
startActivityForResult(intent, 2) startActivityForResult(intent, 2)
} }
tvIntelligentMode.setOnClickListener { tvIntelligentMode.setOnClickListener {
if(clashRunning){ // if(clashRunning){
RxToast.info(resources.getString(R.string.SwitchingSourceModel)) // RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener // return@setOnClickListener
} // }
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clIntelligentMode ==>${getIsGlo}")
if(getIsGlo){
setProxyModeView(ProxyMode.PAC) setProxyModeView(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false) MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
checkGlo()
}
} }
tvGlobalMode.setOnClickListener { tvGlobalMode.setOnClickListener {
if(clashRunning){ if (!clashRunning) {
RxToast.info(resources.getString(R.string.SwitchingSourceModel)) RxToast.info(resources.getString(R.string.SwitchingSourceModel))
return@setOnClickListener return@setOnClickListener
} }
val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("clGlobalModel ==>${getIsGlo}")
if (!getIsGlo) {
setProxyModeView(ProxyMode.GLOBAL) setProxyModeView(ProxyMode.GLOBAL)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true) MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
checkGlo()
}
} }
clLinks.setOnClickListener { clLinks.setOnClickListener {
if (clashRunning) { if (clashRunning) {
@ -348,12 +361,12 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
private fun startClash(isStart: Boolean) { private fun startClash(isStart: Boolean) {
launch { launch {
if (isStart) {
delay(2000)
}
MainActivity.profileBinder?.let { pm -> MainActivity.profileBinder?.let { pm ->
val active = pm.queryActive() val active = pm.queryActive()
if (active == null) { if (active == null) {
if (isStart) {
delay(2000)
}
Log.d("startClash: 未选择") Log.d("startClash: 未选择")
val pro = pm.queryAll().find { val pro = pm.queryAll().find {
it.name == Conf.getClashConfName(this@HomeFragment.context) it.name == Conf.getClashConfName(this@HomeFragment.context)
@ -512,7 +525,14 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
fun nodeChooseBase(data: Intent?) { fun nodeChooseBase(data: Intent?) {
val node = data?.extras?.getString(BZYConstants.MMKV_KEY_SELECT_NODE_NAME) val node = data?.extras?.getString(BZYConstants.MMKV_KEY_SELECT_NODE_NAME)
val isRunning = data?.extras?.getBoolean(BZYConstants.EXTRA_KEY_IS_RUNING) val isRunning = data?.extras?.getBoolean(BZYConstants.EXTRA_KEY_IS_RUNING)
Log.d("onActivityResult ==>>> Node:${node}") val getIsGlo= MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
if(getIsGlo){
setProxyModeView(ProxyMode.GLOBAL)
}else{
setProxyModeView(ProxyMode.PAC)
}
Log.d("onActivityResult ==>>> Node:${node} ::getIsGlo::${getIsGlo}")
node?.let { node?.let {
setNodeNameAndImg(it) setNodeNameAndImg(it)
if (clashRunning) { if (clashRunning) {
@ -635,6 +655,12 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
Log.i("checkGlo isGlobal==>${isGlobal} clashRunning==>${clashRunning}") Log.i("checkGlo isGlobal==>${isGlobal} clashRunning==>${clashRunning}")
launch(Dispatchers.IO) { launch(Dispatchers.IO) {
if (isGlobal) { if (isGlobal) {
if (clashRunning) {
Log.i("AAAAAAAAAAAAAA innner to==>")
getNodes()
}
}else{
if(clashRunning){
delay(1000) delay(1000)
clashBinder?.let { cm -> clashBinder?.let { cm ->
val names = cm.queryProxyGroupNames(false) val names = cm.queryProxyGroupNames(false)
@ -660,7 +686,7 @@ open class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispa
} }
} }
} }
getNodes() }
} }
} }
} }

View File

@ -479,4 +479,5 @@
<string name="ShartPagetxt">邀请新朋友通过你的分享链接注册并订购任意会员套餐,\n <string name="ShartPagetxt">邀请新朋友通过你的分享链接注册并订购任意会员套餐,\n
您可以获得30天会员仅限新用户订购有效</string> 您可以获得30天会员仅限新用户订购有效</string>
<string name="LinkSharetxt">点击分享</string> <string name="LinkSharetxt">点击分享</string>
<string name="OpenSwitchingSourceModel">请开启加速后在进行全局模式切换</string>
</resources> </resources>