作者 zhangji

增加401未跳转登录的问题

@@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
16 </set> 16 </set>
17 </option> 17 </option>
18 <option name="resolveModulePerSourceSet" value="false" /> 18 <option name="resolveModulePerSourceSet" value="false" />
19 - <option name="useQualifiedModuleNames" value="true" />  
20 </GradleProjectSettings> 19 </GradleProjectSettings>
21 </option> 20 </option>
22 </component> 21 </component>
@@ -12,6 +12,7 @@ import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLogi @@ -12,6 +12,7 @@ import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLogi
12 import com.wjx.android.wanandroidmvvm.network.response.BaseResponse 12 import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
13 import io.reactivex.rxjava3.core.Observer 13 import io.reactivex.rxjava3.core.Observer
14 import io.reactivex.rxjava3.disposables.Disposable 14 import io.reactivex.rxjava3.disposables.Disposable
  15 +import retrofit2.HttpException
15 16
16 /** 17 /**
17 * Time: 7/26/2021 10:11 18 * Time: 7/26/2021 10:11
@@ -53,7 +54,13 @@ class BaseObserver<T : BaseResponse<*>>( @@ -53,7 +54,13 @@ class BaseObserver<T : BaseResponse<*>>(
53 } 54 }
54 55
55 override fun onError(p0: Throwable) { 56 override fun onError(p0: Throwable) {
56 - loadState.postValue(State(StateType.NETWORK_ERROR)) 57 + if (p0 is HttpException) {
  58 + if (p0.code()==401) {
  59 + loadState.postValue(State(StateType.NOT_LOGIN, message = "请重新登录"))
  60 + }
  61 + }else{
  62 + loadState.postValue(State(StateType.NETWORK_ERROR))
  63 + }
57 } 64 }
58 65
59 override fun onComplete() {} 66 override fun onComplete() {}
@@ -9,6 +9,8 @@ import androidx.appcompat.widget.Toolbar @@ -9,6 +9,8 @@ import androidx.appcompat.widget.Toolbar
9 import androidx.lifecycle.Observer 9 import androidx.lifecycle.Observer
10 import androidx.lifecycle.ViewModelProvider 10 import androidx.lifecycle.ViewModelProvider
11 import androidx.viewbinding.ViewBinding 11 import androidx.viewbinding.ViewBinding
  12 +import com.br_technology.electricityandroid.util.pos_id
  13 +import com.br_technology.electricityandroid.util.token
12 import com.br_technology.securitytrain_master.R 14 import com.br_technology.securitytrain_master.R
13 import com.br_technology.securitytrain_master.base.common.CommonUtil 15 import com.br_technology.securitytrain_master.base.common.CommonUtil
14 import com.br_technology.securitytrain_master.base.common.State 16 import com.br_technology.securitytrain_master.base.common.State
@@ -17,6 +19,7 @@ import com.br_technology.securitytrain_master.base.common.callback.EmptyCallBack @@ -17,6 +19,7 @@ import com.br_technology.securitytrain_master.base.common.callback.EmptyCallBack
17 import com.br_technology.securitytrain_master.base.common.callback.LoadingCallBack 19 import com.br_technology.securitytrain_master.base.common.callback.LoadingCallBack
18 import com.br_technology.securitytrain_master.base.view.BaseViewModel 20 import com.br_technology.securitytrain_master.base.view.BaseViewModel
19 import com.br_technology.securitytrain_master.expand.statusBarHeight 21 import com.br_technology.securitytrain_master.expand.statusBarHeight
  22 +import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLoginActivity
20 import com.kingja.loadsir.callback.SuccessCallback 23 import com.kingja.loadsir.callback.SuccessCallback
21 24
22 /** 25 /**
@@ -98,6 +101,12 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr @@ -98,6 +101,12 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr
98 loadService.showCallback(EmptyCallBack::class.java) 101 loadService.showCallback(EmptyCallBack::class.java)
99 } 102 }
100 103
  104 + private fun toLogin() {
  105 + token = ""
  106 + pos_id = 0
  107 + startActivity(AccountLoginActivity::class.java)
  108 + }
  109 +
101 /** 110 /**
102 * 分发应用状态 111 * 分发应用状态
103 */ 112 */
@@ -109,10 +118,9 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr @@ -109,10 +118,9 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr
109 StateType.LOADING -> showLoading() 118 StateType.LOADING -> showLoading()
110 StateType.ERROR -> showTip(it.message) 119 StateType.ERROR -> showTip(it.message)
111 StateType.NETWORK_ERROR -> showError("网络出现问题啦") 120 StateType.NETWORK_ERROR -> showError("网络出现问题啦")
112 -// StateType.NOT_LOGIN -> showError("请重新登录",401) 121 + StateType.NOT_LOGIN -> toLogin()
113 StateType.TIP -> showTip(it.message) 122 StateType.TIP -> showTip(it.message)
114 StateType.EMPTY -> showEmpty() 123 StateType.EMPTY -> showEmpty()
115 - else -> {}  
116 } 124 }
117 } 125 }
118 } 126 }
@@ -12,6 +12,8 @@ import android.widget.Toast @@ -12,6 +12,8 @@ import android.widget.Toast
12 import androidx.lifecycle.Observer 12 import androidx.lifecycle.Observer
13 import androidx.lifecycle.ViewModelProvider 13 import androidx.lifecycle.ViewModelProvider
14 import androidx.viewbinding.ViewBinding 14 import androidx.viewbinding.ViewBinding
  15 +import com.br_technology.electricityandroid.util.pos_id
  16 +import com.br_technology.electricityandroid.util.token
15 import com.br_technology.securitytrain_master.base.common.CommonUtil 17 import com.br_technology.securitytrain_master.base.common.CommonUtil
16 import com.br_technology.securitytrain_master.base.common.State 18 import com.br_technology.securitytrain_master.base.common.State
17 import com.br_technology.securitytrain_master.base.common.StateType 19 import com.br_technology.securitytrain_master.base.common.StateType
@@ -19,6 +21,7 @@ import com.br_technology.securitytrain_master.base.common.callback.EmptyCallBack @@ -19,6 +21,7 @@ import com.br_technology.securitytrain_master.base.common.callback.EmptyCallBack
19 import com.br_technology.securitytrain_master.base.common.callback.ErrorCallBack 21 import com.br_technology.securitytrain_master.base.common.callback.ErrorCallBack
20 import com.br_technology.securitytrain_master.base.common.callback.LoadingCallBack 22 import com.br_technology.securitytrain_master.base.common.callback.LoadingCallBack
21 import com.br_technology.securitytrain_master.base.view.BaseViewModel 23 import com.br_technology.securitytrain_master.base.view.BaseViewModel
  24 +import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLoginActivity
22 import com.kingja.loadsir.callback.SuccessCallback 25 import com.kingja.loadsir.callback.SuccessCallback
23 26
24 /** 27 /**
@@ -102,11 +105,17 @@ abstract class BaseLifeCycleFragment<VM : BaseViewModel<*>, VB : ViewBinding>( @@ -102,11 +105,17 @@ abstract class BaseLifeCycleFragment<VM : BaseViewModel<*>, VB : ViewBinding>(
102 StateType.NETWORK_ERROR -> showError("网络异常") 105 StateType.NETWORK_ERROR -> showError("网络异常")
103 StateType.TIP -> showTip(it.message) 106 StateType.TIP -> showTip(it.message)
104 StateType.EMPTY -> showEmpty() 107 StateType.EMPTY -> showEmpty()
  108 + StateType.NOT_LOGIN->toLogin()
105 } 109 }
106 } 110 }
107 } 111 }
108 } 112 }
109 113
  114 + private fun toLogin() {
  115 + token = ""
  116 + pos_id = 0
  117 + startActivity(AccountLoginActivity::class.java)
  118 + }
110 119
111 override fun reLoad() { 120 override fun reLoad() {
112 showLoading() 121 showLoading()