Commit 2fd69fc0 authored by mengcuiguang2's avatar mengcuiguang2

代码优化

parent 49d0ee24
......@@ -47,7 +47,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(), View
override fun initViewObservable() {
super.initViewObservable()
viewModel.data.observe(this, Observer<String>{
ToastUtils.showLong("初始化成功")
// ToastUtils.showLong("初始化成功")
})
}
......
......@@ -2,17 +2,12 @@ package com.mints.street.login
import android.app.Application
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.common.DeviceInfo
import com.mints.street.manager.UserManager
import com.mints.street.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl
import com.mints.street.utils.DeviceUuidFactory
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.goldze.mvvmhabit.base.BaseViewModel
import me.goldze.mvvmhabit.http.BaseResponse
import me.goldze.mvvmhabit.utils.KLog
......@@ -51,6 +46,7 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
}
fun login(mobile: String, smsCode: String) {
showDialog()
val vo = HashMap<String, Any>()
vo["mobile"] = mobile
vo["smsCode"] = smsCode
......@@ -60,13 +56,14 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
object : HttpSubscribeImpl<BaseResponse<UserBean>>(
this@LoginViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<UserBean>) {
data.value = response.message
KLog.e("login", response.result.toString())
ToastUtils.showShort("登录信息="+response.result.ConsumerBean().idcode)
dismissDialog()
this@LoginViewModel.saveTerminalInfo()
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) {
......@@ -81,35 +78,28 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
* 提交设备信息
*/
fun saveTerminalInfo() {
viewModelScope.launch(Dispatchers.IO) {
val appInfoMap = deviceInfo.getAppInfoMap()
launch(Dispatchers.Main) {
val vo = hashMapOf<String, Any>()
val macAddress: String = deviceInfo.getMacAddress()
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
vo["androidid"] = deviceInfo.getAndroidId(null)
vo["imei"] = deviceInfo.iMEI
val vo = hashMapOf<String, Any>()
val macAddress: String = deviceInfo.getMacAddress()
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
vo["androidid"] = deviceInfo.getAndroidId(null)
vo["imei"] = deviceInfo.iMEI
// if (!TextUtils.isEmpty(App.OAID)) {
// vo["oaid"] = App.OAID
// }
vo["os"] = "android"
vo["model"] = deviceInfo.newModel
vo["uuid"] = DeviceUuidFactory().deviceUuid
vo["osversion"] = deviceInfo.oSVersion
vo["appversion"] = deviceInfo.versionName
vo["appPkgList"] = appInfoMap
vo["os"] = "android"
vo["model"] = deviceInfo.newModel
vo["uuid"] = DeviceUuidFactory().deviceUuid
vo["osversion"] = deviceInfo.oSVersion
vo["appversion"] = deviceInfo.versionName
ApiModel.saveTerminalInfo(lifecycleProvider,vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<Any>>(
this@LoginViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<Any>) {
KLog.e("saveTerminalInfo", response.result.toString())
}
})
}
}
ApiModel.saveTerminalInfo(lifecycleProvider,vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<Any>>(
this@LoginViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<Any>) {
KLog.e("saveTerminalInfo", response.result.toString())
}
})
}
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
/**
* Created by jeme on 2019/1/31
* Created by mcg
*/
public class RetrofitClient {
......@@ -50,38 +50,10 @@ public class RetrofitClient {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
.cookieJar(new CookieJarImpl(new PersistentCookieStore(mContext)))
// .cache(cache)
// .addInterceptor()
// .addInterceptor(new CacheInterceptor(mContext))
// .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
.connectTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS)
.writeTimeout(mHttpConfig.getTimeOut(), TimeUnit.SECONDS)
.readTimeout(mHttpConfig.getTimeOut(), 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) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
......@@ -122,25 +94,4 @@ public class RetrofitClient {
}
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
isBuildModule=false
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_ALIAS=mints_street
......
......@@ -70,7 +70,6 @@ dependencies {
//Google LiveData和ViewModel组件
api rootProject.ext.dependencies["lifecycle-extensions"]
kapt rootProject.ext.dependencies["lifecycle-compiler"]
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
//api "com.jeme:gif:1.0.5@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