Commit 8286a5df authored by liusheng's avatar liusheng

修复加速AuthToken重新登录不刷新的问题

parent 3f146744
...@@ -137,12 +137,6 @@ class AccelertorFragment : XPageFragment() { ...@@ -137,12 +137,6 @@ class AccelertorFragment : XPageFragment() {
binding.progressArea.visibility = View.GONE binding.progressArea.visibility = View.GONE
binding.btnQuick.isEnabled = true binding.btnQuick.isEnabled = true
binding.progressViewCircleSmall.progress = 0F binding.progressViewCircleSmall.progress = 0F
binding.progressViewCircleSmall.postDelayed({
Log.e("onCircleProgressFinished","====="+state.toString())
if (state != BaseService.State.Connected) {
ToastUtils.show("加速失败")
}
}, 3000)
AcceleratorUtils.startAccelerator(this@AccelertorFragment) AcceleratorUtils.startAccelerator(this@AccelertorFragment)
} }
}) })
......
...@@ -98,7 +98,7 @@ object AcceleratorUtils { ...@@ -98,7 +98,7 @@ object AcceleratorUtils {
val delay = val delay =
NetUtils.tcpPing(split[0], split[1].toInt(), DataStore.portProxy) NetUtils.tcpPing(split[0], split[1].toInt(), DataStore.portProxy)
.toInt() .toInt()
net.accNetDelay = (delay * 0.5).toInt() net.accNetDelay = delay
LoginUtils.getUserHasTimer { LoginUtils.getUserHasTimer {
if (!it) { //没有加速时长关闭服务 if (!it) { //没有加速时长关闭服务
stopAccelerator() stopAccelerator()
...@@ -171,7 +171,6 @@ object AcceleratorUtils { ...@@ -171,7 +171,6 @@ object AcceleratorUtils {
proxyGames.add(it) proxyGames.add(it)
} }
} }
proxyGames.addAll(profile.individual.split("\n"))
profile.individual = proxyGames.joinToString("\n") profile.individual = proxyGames.joinToString("\n")
profile.route = Acl.BYPASS_LAN profile.route = Acl.BYPASS_LAN
profile.password = "barfoo!" profile.password = "barfoo!"
......
...@@ -101,7 +101,7 @@ object LoginUtils { ...@@ -101,7 +101,7 @@ object LoginUtils {
timer?.schedule(timerTask, 0, 1000); timer?.schedule(timerTask, 0, 1000);
} }
fun stopTimer(){ fun stopTimer() {
_phone = "" _phone = ""
timer?.cancel() timer?.cancel()
} }
...@@ -136,7 +136,7 @@ object LoginUtils { ...@@ -136,7 +136,7 @@ object LoginUtils {
context, context,
PhoneLoginActivity::class.java PhoneLoginActivity::class.java
) )
intent.addFlags(FLAG_ACTIVITY_NEW_TASK ) intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
context.startActivity( context.startActivity(
intent intent
) )
...@@ -148,21 +148,17 @@ object LoginUtils { ...@@ -148,21 +148,17 @@ object LoginUtils {
fun clearToken() { fun clearToken() {
Core.stopService() Core.stopService()
MMKV.defaultMMKV().remove(KEY_TOKEN) token = null
} }
var token: String? var token: String?
get() = MMKV.defaultMMKV().decodeString(KEY_TOKEN, null) get() = AuthManager.authToken
set(token) { set(token) {
MMKV.defaultMMKV().putString(KEY_TOKEN, token) AuthManager.authToken = token
if (token != null) {
AuthManager.loginAuthToken=token
Log.e("LoginUtils","===loginAuthToken:"+ AuthManager.loginAuthToken)
}
} }
fun hasToken(): Boolean { fun hasToken(): Boolean {
return MMKV.defaultMMKV().containsKey(KEY_TOKEN) return !AuthManager.authToken.isNullOrBlank()
} }
fun logout() { fun logout() {
......
...@@ -64,9 +64,9 @@ object AuthManager { ...@@ -64,9 +64,9 @@ object AuthManager {
} }
var authToken: String? var authToken: String?
get() = MMKV.defaultMMKV().decodeString(KEY_TOKEN, null) get() = MMKV.mmkvWithID("InterProcessKV", MMKV.MULTI_PROCESS_MODE).decodeString(KEY_TOKEN, null)
set(token) { set(token) {
MMKV.defaultMMKV().putString(KEY_TOKEN, token) MMKV.mmkvWithID("InterProcessKV", MMKV.MULTI_PROCESS_MODE).putString(KEY_TOKEN, token)
} }
// 加速时长 // 加速时长
...@@ -87,7 +87,7 @@ object AuthManager { ...@@ -87,7 +87,7 @@ object AuthManager {
suspend fun initAuthProfile(profile: Profile) { suspend fun initAuthProfile(profile: Profile) {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val gameId: Int = gameId?.toInt() ?: throw AuthException("游戏不存在") val gameId: Int = gameId?.toInt() ?: throw AuthException("游戏不存在")
val lineConfigResult = postSync<LineConfig>("/api/acc/line", LineConfigReq(gameId, area)) val lineConfigResult = postSync<LineConfig>("/api/acc/line",authToken, LineConfigReq(gameId, area))
if (lineConfigResult.isSuccessful()) { if (lineConfigResult.isSuccessful()) {
val lineConfig = lineConfigResult.unwrapData() val lineConfig = lineConfigResult.unwrapData()
profile.host = lineConfig.host profile.host = lineConfig.host
...@@ -119,7 +119,7 @@ object AuthManager { ...@@ -119,7 +119,7 @@ object AuthManager {
if (data.state == BaseService.State.Connected) { if (data.state == BaseService.State.Connected) {
data.proxy?.let { proxyInstance -> data.proxy?.let { proxyInstance ->
val refreshTokenResult = postSync<RefreshTokenRes>( val refreshTokenResult = postSync<RefreshTokenRes>(
"/api/acc/line/refresh", "/api/acc/line/refresh",authToken,
RefreshTokenReq(proxyInstance.profile.token ?: "") RefreshTokenReq(proxyInstance.profile.token ?: "")
) )
Timber.d("refreshTokenResult: $refreshTokenResult") Timber.d("refreshTokenResult: $refreshTokenResult")
...@@ -151,13 +151,14 @@ object AuthManager { ...@@ -151,13 +151,14 @@ object AuthManager {
inline fun <reified T> postSync( inline fun <reified T> postSync(
url: String, url: String,
token: String?,
params: Any params: Any
): ApiResult<T> { ): ApiResult<T> {
val body: RequestBody = gson.toJson(params).toString().toRequestBody(jsonType) val body: RequestBody = gson.toJson(params).toString().toRequestBody(jsonType)
val request = Request.Builder() val request = Request.Builder()
.url(HttpConfig.baseUrl + url) .url(HttpConfig.baseUrl + url)
.post(body) .post(body)
authToken?.let { token?.let {
request.addHeader("Authorization", it) request.addHeader("Authorization", it)
} }
Log.e("postSync","===authToken:"+authToken) Log.e("postSync","===authToken:"+authToken)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment