parent
1e3265785a
commit
d315250538
|
|
@ -29,6 +29,7 @@ import com.cncat.vpn.service.remote.IRemoteService
|
|||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonParser
|
||||
import com.tencent.mmkv.MMKV
|
||||
import com.yingmao.clash.BuildConfig
|
||||
import com.yingmao.clash.R
|
||||
import com.yingmao.clash.act.ProxyModeActivity.ProxyMode
|
||||
import com.yingmao.clash.act.NewMainActivity.Companion.clashBinder
|
||||
|
|
@ -36,6 +37,7 @@ 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.act.UIMainActivity.Companion.isSubed
|
||||
import com.yingmao.clash.app.MainApplication
|
||||
import com.yingmao.clash.base.BaseActivity
|
||||
import com.yingmao.clash.conf.BZYConstants
|
||||
|
|
@ -418,15 +420,18 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
subUrl?.let {
|
||||
nowSubUrl = it
|
||||
}
|
||||
doProfile()
|
||||
doProfile(false)
|
||||
|
||||
}
|
||||
|
||||
fun doProfile() {
|
||||
fun doProfile(isDelete: Boolean) {
|
||||
if (TextUtils.isEmpty(cacheNodeStr)) {
|
||||
|
||||
}
|
||||
showLoading("正在获取...", this@ChangeNodeActivity)
|
||||
if(!isDelete){
|
||||
showLoading("正在获取...", this@ChangeNodeActivity)
|
||||
}
|
||||
|
||||
startTimer()
|
||||
updateProfile(false)
|
||||
}
|
||||
|
|
@ -584,19 +589,36 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
var isCreate: Boolean = false
|
||||
private var timerJob: Job? = null
|
||||
private fun startTimer() {
|
||||
GetNodeTimeOutNum = 10
|
||||
GetNodeTimeOutNum = 15
|
||||
timerJob = launch {
|
||||
repeat(11) {
|
||||
repeat(16) {
|
||||
Log.d("GetNodeTimeOutNum==>$GetNodeTimeOutNum")
|
||||
if (GetNodeTimeOutNum == 0) {
|
||||
hideLoading()
|
||||
Log.d("stopTimer...")
|
||||
RxToast.error("获取节点失败...请尝试切换其他地址")
|
||||
showDomainList()
|
||||
timerJob?.cancel()
|
||||
// delay(1000)
|
||||
// this@ChangeNodeActivity.finish()
|
||||
RxToast.error("获取节点失败...正在切换其他地址")
|
||||
if (setNewData()) {
|
||||
timerJob?.cancel()
|
||||
MMKV.defaultMMKV()
|
||||
.removeValueForKey(BZYConstants.NODE_All_ITEM_NAME_KEY)
|
||||
saveSubUrl()
|
||||
|
||||
MainApplication.restartApp(this@ChangeNodeActivity, object :
|
||||
MainApplication.OnRestartButtonListener {
|
||||
|
||||
override fun enterButton() {
|
||||
|
||||
}
|
||||
|
||||
override fun cancelButton() {
|
||||
doProfile(false)
|
||||
}
|
||||
|
||||
})
|
||||
} else {
|
||||
timerJob?.cancel()
|
||||
RxToast.error("获取全部线路失败...请切换网络重试")
|
||||
}
|
||||
}
|
||||
GetNodeTimeOutNum--
|
||||
delay(1000)
|
||||
|
|
@ -621,7 +643,7 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
// com.cncat.vpn.common.log.Log.d("tryButton currentHost==>${currentHost}")
|
||||
var oldUrl = nowSubUrl
|
||||
currentHost?.let { changeSubUrl(oldUrl, it) }
|
||||
doProfile()
|
||||
doProfile(false)
|
||||
}
|
||||
|
||||
override fun cancel() {
|
||||
|
|
@ -697,4 +719,54 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
intent.setPackage(this.packageName)
|
||||
)
|
||||
}
|
||||
private fun setNewData(): Boolean {
|
||||
var mmkv = MMKV.defaultMMKV()
|
||||
val originalUrl =
|
||||
mmkv.decodeString(BZYConstants.MMKV_KEY_CURRENT_HOST, BuildConfig.service_url)
|
||||
var newUrlString = originalUrl
|
||||
var isChange = false
|
||||
val routerHost = mmkv.decodeStringSet(BZYConstants.MMKV_KEY_ROUTER_HOST, HashSet())
|
||||
var switchFinshSet = mmkv.decodeStringSet(BZYConstants.MMKV_KEY_Switch_Finsh_Set, HashSet())
|
||||
routerHost?.let {
|
||||
if (it.isEmpty()) {
|
||||
android.util.Log.d(Conf.TAG, "routerHost isEmpty")
|
||||
return isChange
|
||||
}
|
||||
Log.d("switchFinshSet.size==>${switchFinshSet?.size!!} , routerHost.size==>${routerHost.size}")
|
||||
//次数已满
|
||||
if (switchFinshSet?.size!! >= routerHost.size) {
|
||||
return isChange
|
||||
}
|
||||
android.util.Log.d(Conf.TAG, "routerHost not empty")
|
||||
for (url in it) {
|
||||
|
||||
if (url == originalUrl) {
|
||||
switchFinshSet?.add(url)
|
||||
mmkv.encode(BZYConstants.MMKV_KEY_Switch_Finsh_Set, switchFinshSet)
|
||||
continue
|
||||
}
|
||||
|
||||
if (switchFinshSet?.contains(url) == true) {
|
||||
continue
|
||||
} else {
|
||||
isChange = true
|
||||
android.util.Log.e("Retry", "切换到新url:$url")
|
||||
newUrlString = url
|
||||
switchFinshSet?.add(newUrlString)
|
||||
mmkv.encode(BZYConstants.MMKV_KEY_Switch_Finsh_Set, switchFinshSet)
|
||||
break
|
||||
}
|
||||
}
|
||||
mmkv.encode(BZYConstants.MMKV_KEY_CURRENT_HOST, newUrlString)
|
||||
|
||||
}
|
||||
return isChange
|
||||
}
|
||||
private fun saveSubUrl() {
|
||||
var currentHost = MMKV.defaultMMKV()
|
||||
.decodeString(BZYConstants.MMKV_KEY_CURRENT_HOST, "")
|
||||
Log.d("tryButton currentHost==>${currentHost}")
|
||||
var oldUrl = nowSubUrl
|
||||
currentHost?.let { changeSubUrl(oldUrl, it) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,7 +268,16 @@ class MemberRechargeActivity : BaseActivity() {
|
|||
override fun httpFailure(httpStatus: HttpStatus.Failure) {
|
||||
when (httpStatus.reqType) {
|
||||
HttpReqType.GET_RECHARGE_INFO -> {
|
||||
showDomainList()
|
||||
if (super.switchServer2()) {
|
||||
val username =
|
||||
MMKV.defaultMMKV()
|
||||
.decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
|
||||
val phToken =
|
||||
MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_PH_TOKEN, "")!!
|
||||
val userId = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_USER_ID)!!
|
||||
viewModel.getPhRechargeInfo(username, phToken, userId)
|
||||
}
|
||||
|
||||
Logger.d("获取充值续费信息异常${httpStatus.msg}")
|
||||
swipeLayout.isRefreshing = false
|
||||
RxToast.error(resources.getString(R.string.DataError))
|
||||
|
|
|
|||
|
|
@ -664,78 +664,20 @@ class SplashActivity : BaseActivity() {
|
|||
when (httpStatus.reqType) {
|
||||
HttpReqType.REGISTER -> {
|
||||
dialogDoMainChoose?.dismiss()
|
||||
with(httpStatus.rsp as RegisterRsp) {
|
||||
if (code == "10000" || code == "200") {
|
||||
if (data != null) {
|
||||
if (!data.phoneNumber.isNullOrEmpty()) {
|
||||
MMKV.defaultMMKV()
|
||||
.encode(MMKV_KEY_REMEMBER_USERNAME, data.phoneNumber)
|
||||
} else {
|
||||
MMKV.defaultMMKV().encode(MMKV_KEY_REMEMBER_USERNAME, username)
|
||||
}
|
||||
} else {
|
||||
MMKV.defaultMMKV().encode(MMKV_KEY_REMEMBER_USERNAME, username)
|
||||
rlPb.visibility = View.GONE
|
||||
pb_web.visibility = View.INVISIBLE
|
||||
com.cncat.vpn.common.log.Log.d("httpFailure HttpReqType.REGISTER")
|
||||
if (super.switchServer2()) {//切换服务器并直接重试
|
||||
doRegisterByEncryption()
|
||||
} else {
|
||||
MaterialDialog(this@SplashActivity).show {
|
||||
message(text = initErrMsg)
|
||||
positiveButton(R.string.retry) {
|
||||
doRegisterByEncryption()
|
||||
}
|
||||
MMKV.defaultMMKV()
|
||||
.encode(MMKV_KEY_REMEMBER_PASSWORD, BZYConstants.defaultPassword)
|
||||
MMKV.defaultMMKV().encode(MMKV_KEY_IS_REGISTER, true)
|
||||
MMKV.defaultMMKV().encode(MMKV_KEY_NOTE_DEFAULT_PSW, true)
|
||||
val encryName = AESUtil.byteArrayToHexStr(
|
||||
AESUtil.encrypt(data?.phoneNumber)
|
||||
)
|
||||
val encryPsw = AESUtil.byteArrayToHexStr(
|
||||
AESUtil.encrypt(BZYConstants.defaultPassword)
|
||||
)
|
||||
val decodeBool =
|
||||
MMKV.defaultMMKV().decodeBool(BZYConstants.INITIALIZATION, true)
|
||||
if (decodeBool) {
|
||||
MMKV.defaultMMKV().encode(BZYConstants.INITIALIZATION, true)
|
||||
}
|
||||
splashAtyVM.login(encryName, encryPsw)
|
||||
} else if (code == "20062") {
|
||||
message?.let {
|
||||
RxToast.error(it)
|
||||
}
|
||||
// if (data != null) {
|
||||
//
|
||||
// var jo =
|
||||
// Gson().fromJson<JsonObject>(data, JsonObject::class.java)
|
||||
// var userName = jo.get("data").asString;
|
||||
// if (!TextUtils.isEmpty(userName)) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
if (data != null) {
|
||||
if (!data.phoneNumber.isNullOrEmpty()) {
|
||||
MMKV.defaultMMKV()
|
||||
.encode(MMKV_KEY_REMEMBER_USERNAME, data.phoneNumber)
|
||||
} else {
|
||||
MMKV.defaultMMKV().encode(MMKV_KEY_REMEMBER_USERNAME, username)
|
||||
}
|
||||
} else {
|
||||
MMKV.defaultMMKV().encode(MMKV_KEY_REMEMBER_USERNAME, username)
|
||||
}
|
||||
val intent = Intent(this@SplashActivity, LoginActivity::class.java)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
// graphicVerificationDialog()
|
||||
} else if (code == "403") {
|
||||
pb_web.visibility = View.INVISIBLE
|
||||
message?.let {
|
||||
RxToast.error(it)
|
||||
}
|
||||
webView?.setOnTouchListener { _, _ -> false }
|
||||
} else {
|
||||
MaterialDialog(this@SplashActivity).show {
|
||||
message(text = initErrMsg)
|
||||
positiveButton(R.string.retry) {
|
||||
// doRegister()
|
||||
doRegisterByEncryption()
|
||||
}
|
||||
negativeButton(R.string.cancel) {
|
||||
it.dismiss()
|
||||
finish()
|
||||
}
|
||||
negativeButton(R.string.cancel) {
|
||||
it.dismiss()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
|
|
@ -93,7 +95,10 @@ class MainApplication : Application() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
fun logException(e: Throwable) {
|
||||
val log = StringWriter().also { e.printStackTrace(PrintWriter(it)) }.toString()
|
||||
Log.d("MainApplication logException==>${log}")
|
||||
}
|
||||
fun initUtil() {
|
||||
getApp()?.let { mainApplication ->
|
||||
DeviceIdentifier.register(mApp)
|
||||
|
|
|
|||
|
|
@ -303,6 +303,51 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope(), Br
|
|||
mmkv.encode(BZYConstants.MMKV_KEY_CURRENT_HOST, newUrlString)
|
||||
}
|
||||
|
||||
return isChange
|
||||
}
|
||||
@Synchronized
|
||||
fun switchServer2(): Boolean {
|
||||
var isChange = false
|
||||
val mmkv = MMKV.defaultMMKV()
|
||||
val originalUrl =
|
||||
mmkv.decodeString(BZYConstants.MMKV_KEY_CURRENT_HOST, BuildConfig.service_url)
|
||||
var newUrlString = originalUrl
|
||||
val routerHost = mmkv.decodeStringSet(BZYConstants.MMKV_KEY_ROUTER_HOST, HashSet())
|
||||
var switchFinshSet = mmkv.decodeStringSet(BZYConstants.MMKV_KEY_Switch_Finsh_Set, HashSet())
|
||||
routerHost?.let {
|
||||
if (it.isEmpty()) {
|
||||
Log.d(Conf.TAG, "routerHost isEmpty")
|
||||
return isChange
|
||||
}
|
||||
com.cncat.vpn.common.log.Log.d("switchFinshSet.size==>${switchFinshSet?.size!!} , routerHost.size==>${routerHost.size}")
|
||||
//次数已满
|
||||
if (switchFinshSet?.size!! >= routerHost.size) {
|
||||
return isChange
|
||||
}
|
||||
|
||||
Log.d(Conf.TAG, "routerHost not empty")
|
||||
for (url in it) {
|
||||
|
||||
if (url == originalUrl) {
|
||||
switchFinshSet?.add(url)
|
||||
mmkv.encode(BZYConstants.MMKV_KEY_Switch_Finsh_Set, switchFinshSet)
|
||||
continue
|
||||
}
|
||||
|
||||
if (switchFinshSet?.contains(url) == true) {
|
||||
continue
|
||||
} else {
|
||||
isChange = true
|
||||
Log.e("Retry", "切换到新url:$url")
|
||||
newUrlString = url
|
||||
switchFinshSet?.add(newUrlString)
|
||||
mmkv.encode(BZYConstants.MMKV_KEY_Switch_Finsh_Set, switchFinshSet)
|
||||
break
|
||||
}
|
||||
}
|
||||
mmkv.encode(BZYConstants.MMKV_KEY_CURRENT_HOST, newUrlString)
|
||||
}
|
||||
|
||||
return isChange
|
||||
}
|
||||
}
|
||||
|
|
@ -120,5 +120,7 @@ class BZYConstants {
|
|||
const val applicationMode = "ApplicationMode"
|
||||
const val CONNECTID = "connectId"
|
||||
const val is_splash_first = "is_splash_first"
|
||||
const val MMKV_KEY_Switch_Finsh_Set ="MMKV_KEY_Switch_Finsh_Set"
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue