|
@@ -1,19 +1,19 @@
|
|
|
package com.swago.app
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
import android.app.Application
|
|
|
import android.content.Intent
|
|
|
-import android.util.Log
|
|
|
-import android.widget.Toast
|
|
|
+import android.os.Handler
|
|
|
+import android.os.Message
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
import com.google.gson.Gson
|
|
|
import com.swago.baseswago.constant.ARouteConstant
|
|
|
import com.swago.baseswago.constant.UrlConstant
|
|
|
+import com.swago.baseswago.http.RetrofitManager
|
|
|
import com.swago.baseswago.inter.ApiManager
|
|
|
-import com.swago.baseswago.model.ConfigModel
|
|
|
import com.swago.baseswago.util.*
|
|
|
-import com.tencent.qcloud.tim.uikit.TUIKit
|
|
|
-import com.tencent.qcloud.tim.uikit.base.IUIKitCallBack
|
|
|
+import org.jsoup.Jsoup
|
|
|
|
|
|
/**
|
|
|
*@date 2022/2/26 11:33
|
|
@@ -25,6 +25,110 @@ class SplashVm (application: Application) : BaseViewModel(application) {
|
|
|
Gson()
|
|
|
}
|
|
|
|
|
|
+ val jumpToLoginLiveData by lazy {
|
|
|
+ MutableLiveData<Boolean>()
|
|
|
+ }
|
|
|
+
|
|
|
+ var retry = 0
|
|
|
+
|
|
|
+ private val executorService by lazy {
|
|
|
+ ThreadPoolUtils.getInstance().executorService
|
|
|
+ }
|
|
|
+
|
|
|
+ private val mHandler = @SuppressLint("HandlerLeak")
|
|
|
+ object: Handler(){
|
|
|
+ override fun handleMessage(msg: Message) {
|
|
|
+ if (UserInfo.getLoginModel() == null){
|
|
|
+ jumpToLoginLiveData.value = false
|
|
|
+ }else{
|
|
|
+ loginByAuto()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getApiDomain(){
|
|
|
+ requestData2 {
|
|
|
+ requestData {
|
|
|
+ val data = ApiManager.configApi.getApiDomain()
|
|
|
+ if (BuildConfig.DEBUG) {
|
|
|
+ UrlConstant.BASE_URL = "http:test-api.swago.cn"
|
|
|
+ } else {
|
|
|
+ UrlConstant.BASE_URL = data.host
|
|
|
+ }
|
|
|
+ RetrofitManager.resetUrl()
|
|
|
+ if (UserInfo.getLoginModel() == null){
|
|
|
+ jumpToLoginLiveData.value = false
|
|
|
+ }else{
|
|
|
+ loginByAuto()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ requestError {
|
|
|
+ retry++
|
|
|
+ if (BuildConfig.DEBUG){
|
|
|
+ executorService.execute {
|
|
|
+ val document = Jsoup.connect("https://github.com/whyNotBanMagna/MvpProject/blob/master/README.md").timeout(2000).get()
|
|
|
+ val list = document.text().split(" ")
|
|
|
+ list.forEach {
|
|
|
+ if (it.length==32){
|
|
|
+ if (BuildConfig.DEBUG) {
|
|
|
+ UrlConstant.BASE_URL = "http:test-api.swago.cn"
|
|
|
+ } else {
|
|
|
+ UrlConstant.BASE_URL = MD5Util.decodeBase64(it)
|
|
|
+ }
|
|
|
+ RetrofitManager.resetUrl()
|
|
|
+ mHandler.sendEmptyMessage(0)
|
|
|
+ return@execute
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ when(retry){
|
|
|
+ 1 -> {
|
|
|
+ getApiDomain()
|
|
|
+ }
|
|
|
+ 2 -> {
|
|
|
+ executorService.execute {
|
|
|
+ val document = Jsoup.connect("https://github.com/whyNotBanMagna/MvpProject/blob/master/README.md").timeout(2000).get()
|
|
|
+ val list = document.text().split(" ")
|
|
|
+ list.forEach {
|
|
|
+ if (it.length==32){
|
|
|
+ if (BuildConfig.DEBUG) {
|
|
|
+ UrlConstant.BASE_URL = "http:test-api.swago.cn"
|
|
|
+ } else {
|
|
|
+ UrlConstant.BASE_URL = MD5Util.decodeBase64(it)
|
|
|
+ }
|
|
|
+ RetrofitManager.resetUrl()
|
|
|
+ mHandler.sendEmptyMessage(0)
|
|
|
+ return@execute
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 3 -> {
|
|
|
+ executorService.execute {
|
|
|
+ val document = Jsoup.connect("https://github.com/whyNotBanMagna/MvpProject/blob/master/README.md").timeout(2000).get()
|
|
|
+ val list = document.text().split(" ")
|
|
|
+ list.forEach {
|
|
|
+ if (it.length==32){
|
|
|
+ if (BuildConfig.DEBUG) {
|
|
|
+ UrlConstant.BASE_URL = "http:test-api.swago.cn"
|
|
|
+ } else {
|
|
|
+ UrlConstant.BASE_URL = MD5Util.decodeBase64(it)
|
|
|
+ }
|
|
|
+ RetrofitManager.resetUrl()
|
|
|
+ mHandler.sendEmptyMessage(0)
|
|
|
+ return@execute
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fun loginByAuto() {
|
|
|
requestData {
|
|
|
val configModel = ApiManager.configApi.getAppConfig()
|