diff --git a/app/src/main/java/com/yingmao/clash/act/MemberRechargeActivity.kt b/app/src/main/java/com/yingmao/clash/act/MemberRechargeActivity.kt index cccbb9d..1d2206d 100644 --- a/app/src/main/java/com/yingmao/clash/act/MemberRechargeActivity.kt +++ b/app/src/main/java/com/yingmao/clash/act/MemberRechargeActivity.kt @@ -33,12 +33,15 @@ import com.stripe.android.model.StripeIntent import com.tencent.mmkv.MMKV import com.yingmao.clash.BuildConfig import com.yingmao.clash.R +import com.yingmao.clash.act.NewMainActivity.Companion.profileBinder import com.yingmao.clash.app.MainApplication import com.yingmao.clash.base.BaseActivity import com.yingmao.clash.conf.BZYConstants import com.yingmao.clash.entity.CheckLoginRsp import com.yingmao.clash.entity.PayUploadParamData import com.yingmao.clash.entity.RechargeModelEntity +import com.yingmao.clash.fragment.NewAccFragment +import com.yingmao.clash.fragment.home.HomeFragment.Companion.clashRunning import com.yingmao.clash.fragment.recharge.RechargeViewModel import com.yingmao.clash.fragment.recharge.adapter.RechargeModelAdapter import com.yingmao.clash.fragment.recharge.adapter.VIPRechargeAdapter @@ -57,9 +60,11 @@ import com.yingmao.clash.view.dialog.DialogDoMainChoose import com.yingmao.clash.view.dialog.PayConfirmDialog import com.yingmao.clash.view.dialog.RxDialogShapeLoading import com.yingmao.clash.view.dialog.SplashDialog +import com.yingmao.clash.vm.MainAtyVM import com.yingmao.clash.webview.BZYWebViewKeFu import com.yingmao.clash.webview.CustomerServiceWebView import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.MainScope import kotlinx.coroutines.launch @@ -82,6 +87,7 @@ class MemberRechargeActivity : BaseActivity() { private var selectedGradeID :Int=0 //stripePay 支付 private var paymentIntentClientSecret: String = "" + private lateinit var mainAtyVM: MainAtyVM private val stripe: Stripe by lazy { Stripe( this@MemberRechargeActivity, @@ -98,6 +104,7 @@ class MemberRechargeActivity : BaseActivity() { } private fun initData() { + mainAtyVM = ViewModelProvider(this)[MainAtyVM::class.java] viewModel = ViewModelProvider(this)[RechargeViewModel::class.java] observe(this, viewModel) //获取充值列表 @@ -178,12 +185,19 @@ class MemberRechargeActivity : BaseActivity() { HttpReqType.GET_RECHARGE_INFO -> { Logger.d("获取充值续费信息请求成功") swipeLayout.isRefreshing = false - (httpStatus.rsp as RechargeInfoRsp).let { it -> - if (it.code != "1000") { - RxToast.error(if (it.message.isNullOrBlank())resources.getString(R.string.FailedRechargeList)+ "(${it.code})" else "${it.code}:${it.message}") - } else { - it.data?.let { rechargeInfo -> - initAdapter(rechargeInfo) + (httpStatus.rsp as RechargeInfoRsp).let { + when (it.code) { + "1088" -> { + RxToast.info(resources.getString(R.string.LoginOut)) + cleanUserInfo() + } + "1000" -> { + it.data?.let { rechargeInfo -> + initAdapter(rechargeInfo) + } + } + else -> { + RxToast.error(if (it.message.isNullOrBlank())resources.getString(R.string.FailedRechargeList)+ "(${it.code})" else "${it.code}:${it.message}") } } } @@ -506,4 +520,36 @@ class MemberRechargeActivity : BaseActivity() { } } + private fun cleanUserInfo() { + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_PH_TOKEN) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_TOKEN) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_CURRENT_NODE) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.NODE_SELECTED_NAME_KEY) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_VPN_UserCommand) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.NODE_All_ITEM_NAME_KEY) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.PROFILE_SUB_URL) + Log.d("cleanUserInfo clashRunning==>$clashRunning") + if (clashRunning) { + NewAccFragment().stopClash() + } + mainAtyVM.stopHeartBeat() + cleanProfile() + val intent=Intent(CommonUtils.getApp(), LoginActivity::class.java) + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + finish() + } + private fun cleanProfile() { + Log.d("cleanProfile start") + GlobalScope.launch(Dispatchers.IO) { + profileBinder?.let { pm -> + pm.queryAll().forEach { profile -> + Log.d("cleanProfile go delete name==>${profile.name}, uuid==>${profile.uuid}") + pm.delete(profile.uuid) + } + } ?: let { + Log.d("profileBinder is null") + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/yingmao/clash/act/NewMainActivity.kt b/app/src/main/java/com/yingmao/clash/act/NewMainActivity.kt index 54690bf..42c2d22 100644 --- a/app/src/main/java/com/yingmao/clash/act/NewMainActivity.kt +++ b/app/src/main/java/com/yingmao/clash/act/NewMainActivity.kt @@ -680,7 +680,10 @@ class NewMainActivity : BaseActivity() { } else { // RxToast.info(resources.getString(R.string.PaymentResultsStr)) } - } else { + } else if(checkLoginRsp.code == -2){ + RxToast.info(resources.getString(R.string.LoginOut)) + cleanUserInfoToLogout() + }else{ RxToast.info(resources.getString(R.string.QueryFailed)) } payResultLoading?.dismiss() @@ -979,6 +982,26 @@ class NewMainActivity : BaseActivity() { startActivity(Intent(CommonUtils.getApp(), LoginActivity::class.java)) finish() } + private fun cleanUserInfoToLogout() { + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_PH_TOKEN) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_TOKEN) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_CURRENT_NODE) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.NODE_SELECTED_NAME_KEY) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.MMKV_KEY_VPN_UserCommand) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.NODE_All_ITEM_NAME_KEY) + MMKV.defaultMMKV().removeValueForKey(BZYConstants.PROFILE_SUB_URL) + Log.d("cleanUserInfo clashRunning==>${clashRunning}") + if (clashRunning) { + fragments.filterIsInstance().forEach { it.stopClash() } + } + stopUploadTimer() + mainAtyVM.stopHeartBeat() + cleanProfile() + val intent=Intent(CommonUtils.getApp(), LoginActivity::class.java) + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + finish() + } private fun cleanProfile() { diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index c1a1703..cd11a78 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -398,5 +398,6 @@ Service Description\n Switching, please wait The current node is congested, please switch manually Please turn off acceleration before switching sources + It is detected that the current account is logged in on other devices. If it is not your own operation, please change the password immediately and log out of the unfamiliar device. \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 16f3c06..1ea5336 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -388,4 +388,6 @@ 切換中,請稍後 當前節點擁堵請手動切換 請關閉加速後在進行源切換 + 檢測到當前賬號在其他設備登錄,如非本人操作,請立即修改密碼並退出陌生設備。 + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0ba2dea..dd861e8 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -386,4 +386,6 @@ 切換中,請稍後 當前節點擁堵請手動切換 請關閉加速後在進行源切換 + 檢測到當前賬號在其他設備登錄,如非本人操作,請立即修改密碼並退出陌生設備。 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2e9aef7..a8da261 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -412,4 +412,6 @@ 切换中,请稍后 当前节点拥堵请手动切换 请关闭加速后在进行源切换 + 检测到当前账号在其他设备登录,如非本人操作,请立即修改密码并退出陌生设备。 + \ No newline at end of file