Commit 2fd69fc0 authored by mengcuiguang2's avatar mengcuiguang2

代码优化

parent 49d0ee24
...@@ -47,7 +47,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(), View ...@@ -47,7 +47,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(), View
override fun initViewObservable() { override fun initViewObservable() {
super.initViewObservable() super.initViewObservable()
viewModel.data.observe(this, Observer<String>{ viewModel.data.observe(this, Observer<String>{
ToastUtils.showLong("初始化成功") // ToastUtils.showLong("初始化成功")
}) })
} }
......
...@@ -2,17 +2,12 @@ package com.mints.street.login ...@@ -2,17 +2,12 @@ package com.mints.street.login
import android.app.Application import android.app.Application
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import android.text.TextUtils
import androidx.lifecycle.viewModelScope
import com.mints.street.bean.AwardBean
import com.mints.street.bean.UserBean import com.mints.street.bean.UserBean
import com.mints.street.common.DeviceInfo import com.mints.street.common.DeviceInfo
import com.mints.street.manager.UserManager import com.mints.street.manager.UserManager
import com.mints.street.model.ApiModel import com.mints.street.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl import com.mints.street.netwrok.base.HttpSubscribeImpl
import com.mints.street.utils.DeviceUuidFactory import com.mints.street.utils.DeviceUuidFactory
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.goldze.mvvmhabit.base.BaseViewModel import me.goldze.mvvmhabit.base.BaseViewModel
import me.goldze.mvvmhabit.http.BaseResponse import me.goldze.mvvmhabit.http.BaseResponse
import me.goldze.mvvmhabit.utils.KLog import me.goldze.mvvmhabit.utils.KLog
...@@ -51,6 +46,7 @@ class LoginViewModel(application: Application) : BaseViewModel(application) { ...@@ -51,6 +46,7 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
} }
fun login(mobile: String, smsCode: String) { fun login(mobile: String, smsCode: String) {
showDialog()
val vo = HashMap<String, Any>() val vo = HashMap<String, Any>()
vo["mobile"] = mobile vo["mobile"] = mobile
vo["smsCode"] = smsCode vo["smsCode"] = smsCode
...@@ -60,13 +56,14 @@ class LoginViewModel(application: Application) : BaseViewModel(application) { ...@@ -60,13 +56,14 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
object : HttpSubscribeImpl<BaseResponse<UserBean>>( object : HttpSubscribeImpl<BaseResponse<UserBean>>(
this@LoginViewModel, true) { this@LoginViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<UserBean>) { override fun onBusinessSuccess(response: BaseResponse<UserBean>) {
data.value = response.message dismissDialog()
KLog.e("login", response.result.toString()) this@LoginViewModel.saveTerminalInfo()
ToastUtils.showShort("登录信息="+response.result.ConsumerBean().idcode)
UserManager.INSTANCE.saveUserInfo(response.result) UserManager.INSTANCE.saveUserInfo(response.result)
this@LoginViewModel.saveTerminalInfo() data.value = response.message
KLog.e("login", response.result.toString())
ToastUtils.showShort("登录信息="+response.result.consumer?.idcode)
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
...@@ -81,10 +78,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) { ...@@ -81,10 +78,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
* 提交设备信息 * 提交设备信息
*/ */
fun saveTerminalInfo() { fun saveTerminalInfo() {
viewModelScope.launch(Dispatchers.IO) {
val appInfoMap = deviceInfo.getAppInfoMap()
launch(Dispatchers.Main) {
val vo = hashMapOf<String, Any>() val vo = hashMapOf<String, Any>()
val macAddress: String = deviceInfo.getMacAddress() val macAddress: String = deviceInfo.getMacAddress()
val mac = macAddress.replace(":", "") val mac = macAddress.replace(":", "")
...@@ -100,7 +93,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) { ...@@ -100,7 +93,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
vo["uuid"] = DeviceUuidFactory().deviceUuid vo["uuid"] = DeviceUuidFactory().deviceUuid
vo["osversion"] = deviceInfo.oSVersion vo["osversion"] = deviceInfo.oSVersion
vo["appversion"] = deviceInfo.versionName vo["appversion"] = deviceInfo.versionName
vo["appPkgList"] = appInfoMap
ApiModel.saveTerminalInfo(lifecycleProvider,vo).safeSubscribe( ApiModel.saveTerminalInfo(lifecycleProvider,vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<Any>>( object : HttpSubscribeImpl<BaseResponse<Any>>(
...@@ -110,6 +102,4 @@ class LoginViewModel(application: Application) : BaseViewModel(application) { ...@@ -110,6 +102,4 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
} }
}) })
} }
}
}
} }
\ No newline at end of file
...@@ -31,7 +31,7 @@ import retrofit2.Retrofit; ...@@ -31,7 +31,7 @@ import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
/** /**
* Created by jeme on 2019/1/31 * Created by mcg
*/ */
public class RetrofitClient { public class RetrofitClient {
...@@ -50,38 +50,10 @@ public class RetrofitClient { ...@@ -50,38 +50,10 @@ public class RetrofitClient {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder() OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
.cookieJar(new CookieJarImpl(new PersistentCookieStore(mContext))) .cookieJar(new CookieJarImpl(new PersistentCookieStore(mContext)))
// .cache(cache)
// .addInterceptor()
// .addInterceptor(new CacheInterceptor(mContext))
// .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
.connectTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS) .connectTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS)
.writeTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS) .writeTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS)
.readTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS) .readTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS)
.connectionPool(new ConnectionPool(8, 15, TimeUnit.SECONDS)); .connectionPool(new ConnectionPool(8, 15, TimeUnit.SECONDS));
// 这里你可以根据自己的机型设置同时连接的个数和时间,我这里8个,和每个保持时间为10s
// if (configuation.getInterceptors() != null) {
// for (Interceptor interceptor : configuation.getInterceptors()) {
// clientBuilder.addInterceptor(interceptor);
// }
// }
// if(BuildConfig.IS_DEV) {
// clientBuilder.addInterceptor(new LoggingInterceptor
// .Builder()
// //是否开启日志打印
// .loggable(BuildConfig.DEBUG)
// //打印的等级
// .setLevel(Level.BASIC)
// // 打印类型
// .log(Platform.INFO)
// // request的Tag
// .request("Request")
// // Response的Tag
// .response("Request")
//// .addHeader("log-header", "I am the log request header.") // 添加打印头, 注意 key 和 value 都不能是中文
// .build()
// );
// }
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
...@@ -122,25 +94,4 @@ public class RetrofitClient { ...@@ -122,25 +94,4 @@ public class RetrofitClient {
} }
return mRetrofit.create(service); return mRetrofit.create(service);
} }
/**
* /**
* execute your customer API
* For example:
* MyApiService service =
* RetrofitClient.getInstance(MainActivity.this).create(MyApiService.class);
* <p>
* RetrofitClient.getInstance(MainActivity.this)
* .execute(service.lgon("name", "password"), subscriber)
* * @param subscriber
*/
public static <T> T execute(Observable<T> observable, Observer<T> subscriber) {
observable.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
return null;
}
} }
...@@ -21,7 +21,8 @@ android.enableJetifier=true ...@@ -21,7 +21,8 @@ android.enableJetifier=true
isBuildModule=false isBuildModule=false
DEBUG_URL="http://test.mints-id.com/map-api/" DEBUG_URL="http://test.mints-id.com/map-api/"
RELEASE_URL="https://api.mints-id.com/gc-api/" #RELEASE_URL="https://api.mints-id.com/map-api/"
RELEASE_URL="http://test.mints-id.com/map-api/"
RELEASE_KEY_PASSWORD=mints.street RELEASE_KEY_PASSWORD=mints.street
RELEASE_KEY_ALIAS=mints_street RELEASE_KEY_ALIAS=mints_street
......
...@@ -70,7 +70,6 @@ dependencies { ...@@ -70,7 +70,6 @@ dependencies {
//Google LiveData和ViewModel组件 //Google LiveData和ViewModel组件
api rootProject.ext.dependencies["lifecycle-extensions"] api rootProject.ext.dependencies["lifecycle-extensions"]
kapt rootProject.ext.dependencies["lifecycle-compiler"] kapt rootProject.ext.dependencies["lifecycle-compiler"]
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
//api "com.jeme:gif:1.0.5@aar" //api "com.jeme:gif:1.0.5@aar"
//使用aar库引用 //使用aar库引用
......
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