作者 zhangji

增加401未跳转登录的问题

... ... @@ -16,7 +16,6 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>
... ...
... ... @@ -12,6 +12,7 @@ import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLogi
import com.wjx.android.wanandroidmvvm.network.response.BaseResponse
import io.reactivex.rxjava3.core.Observer
import io.reactivex.rxjava3.disposables.Disposable
import retrofit2.HttpException
/**
* Time: 7/26/2021 10:11
... ... @@ -53,7 +54,13 @@ class BaseObserver<T : BaseResponse<*>>(
}
override fun onError(p0: Throwable) {
loadState.postValue(State(StateType.NETWORK_ERROR))
if (p0 is HttpException) {
if (p0.code()==401) {
loadState.postValue(State(StateType.NOT_LOGIN, message = "请重新登录"))
}
}else{
loadState.postValue(State(StateType.NETWORK_ERROR))
}
}
override fun onComplete() {}
... ...
... ... @@ -9,6 +9,8 @@ import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.br_technology.electricityandroid.util.pos_id
import com.br_technology.electricityandroid.util.token
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.common.CommonUtil
import com.br_technology.securitytrain_master.base.common.State
... ... @@ -17,6 +19,7 @@ import com.br_technology.securitytrain_master.base.common.callback.EmptyCallBack
import com.br_technology.securitytrain_master.base.common.callback.LoadingCallBack
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.expand.statusBarHeight
import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLoginActivity
import com.kingja.loadsir.callback.SuccessCallback
/**
... ... @@ -98,6 +101,12 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr
loadService.showCallback(EmptyCallBack::class.java)
}
private fun toLogin() {
token = ""
pos_id = 0
startActivity(AccountLoginActivity::class.java)
}
/**
* 分发应用状态
*/
... ... @@ -109,10 +118,9 @@ abstract class BaseLifeCycleActivity<VM : BaseViewModel<*>, VB : ViewBinding>(pr
StateType.LOADING -> showLoading()
StateType.ERROR -> showTip(it.message)
StateType.NETWORK_ERROR -> showError("网络出现问题啦")
// StateType.NOT_LOGIN -> showError("请重新登录",401)
StateType.NOT_LOGIN -> toLogin()
StateType.TIP -> showTip(it.message)
StateType.EMPTY -> showEmpty()
else -> {}
}
}
}
... ...
... ... @@ -12,6 +12,8 @@ import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.br_technology.electricityandroid.util.pos_id
import com.br_technology.electricityandroid.util.token
import com.br_technology.securitytrain_master.base.common.CommonUtil
import com.br_technology.securitytrain_master.base.common.State
import com.br_technology.securitytrain_master.base.common.StateType
... ... @@ -19,6 +21,7 @@ import com.br_technology.securitytrain_master.base.common.callback.EmptyCallBack
import com.br_technology.securitytrain_master.base.common.callback.ErrorCallBack
import com.br_technology.securitytrain_master.base.common.callback.LoadingCallBack
import com.br_technology.securitytrain_master.base.view.BaseViewModel
import com.br_technology.securitytrain_master.ui.view.login.activity.AccountLoginActivity
import com.kingja.loadsir.callback.SuccessCallback
/**
... ... @@ -102,11 +105,17 @@ abstract class BaseLifeCycleFragment<VM : BaseViewModel<*>, VB : ViewBinding>(
StateType.NETWORK_ERROR -> showError("网络异常")
StateType.TIP -> showTip(it.message)
StateType.EMPTY -> showEmpty()
StateType.NOT_LOGIN->toLogin()
}
}
}
}
private fun toLogin() {
token = ""
pos_id = 0
startActivity(AccountLoginActivity::class.java)
}
override fun reLoad() {
showLoading()
... ...