Commit 49d0ee24 authored by mengcuiguang2's avatar mengcuiguang2

添加网络优化

parents 422093e5 b5a3fec2
...@@ -152,7 +152,9 @@ dependencies { ...@@ -152,7 +152,9 @@ dependencies {
implementation 'com.github.iielse:switchbutton:1.0.4' implementation 'com.github.iielse:switchbutton:1.0.4'
// BottomDialog // BottomDialog
implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.material:material:1.0.0'
// 日志
implementation 'com.squareup.okhttp3:logging-interceptor:4.1.0'
implementation 'com.orhanobut:logger:2.2.0'
// 三方接入 // 三方接入
// 移动安全联盟 // 移动安全联盟
......
...@@ -314,10 +314,6 @@ ...@@ -314,10 +314,6 @@
} }
-keep class com.uc.crashsdk.** { *; } -keep class com.uc.crashsdk.** { *; }
-keep interface com.uc.crashsdk.** { *; } -keep interface com.uc.crashsdk.** { *; }
......
...@@ -3,8 +3,6 @@ package com.mints.street ...@@ -3,8 +3,6 @@ package com.mints.street
import android.content.Context import android.content.Context
import android.os.StrictMode import android.os.StrictMode
import android.os.StrictMode.VmPolicy import android.os.StrictMode.VmPolicy
import android.util.Log
import android.widget.Toast
import com.baidu.lbsapi.BMapManager import com.baidu.lbsapi.BMapManager
import com.baidu.mapapi.CoordType import com.baidu.mapapi.CoordType
import com.baidu.mapapi.SDKInitializer import com.baidu.mapapi.SDKInitializer
...@@ -13,8 +11,11 @@ import com.fry.base.base.BaseApp ...@@ -13,8 +11,11 @@ import com.fry.base.base.BaseApp
import com.mints.street.main.vr.PanoramicActivity import com.mints.street.main.vr.PanoramicActivity
import com.mints.street.manager.CsjGroMoreManager import com.mints.street.manager.CsjGroMoreManager
import com.mints.street.manager.UmengManager import com.mints.street.manager.UmengManager
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.FormatStrategy
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import me.goldze.mvvmhabit.utils.KLog import me.goldze.mvvmhabit.utils.KLog
import java.util.concurrent.TimeoutException
/** /**
* Created by 冯瑞雨 on 2021/7/1. * Created by 冯瑞雨 on 2021/7/1.
...@@ -61,6 +62,8 @@ class AppApplication : BaseApp() { ...@@ -61,6 +62,8 @@ class AppApplication : BaseApp() {
SDKInitializer.setCoordType(CoordType.BD09LL) SDKInitializer.setCoordType(CoordType.BD09LL)
//百度全景 //百度全景
initEngineManager(this) initEngineManager(this)
bindLogger()
} }
/** /**
* 初始化百度全景 * 初始化百度全景
...@@ -74,6 +77,21 @@ class AppApplication : BaseApp() { ...@@ -74,6 +77,21 @@ class AppApplication : BaseApp() {
} }
} }
/**
* 自定义logger
*/
private fun bindLogger() {
//自定义logger
val formatStrategy: FormatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(false) //是否选择显示线程信息,默认为true
.methodCount(0) //方法数显示多少行,默认2行
.methodOffset(7) //隐藏方法内部调用到偏移量,默认5
// .logStrategy(customLog) //打印日志的策略,默认LogCat
.tag("mints---network") //自定义TAG全部标签,默认PRETTY_LOGGER
.build()
Logger.addLogAdapter(AndroidLogAdapter(formatStrategy))
}
companion object { companion object {
var mContext: AppApplication? = null var mContext: AppApplication? = null
var mBMapManager: BMapManager? = null var mBMapManager: BMapManager? = null
......
package com.mints.street.api package com.mints.street.api
import com.google.gson.JsonObject
import com.mints.street.bean.AwardBean import com.mints.street.bean.AwardBean
import com.mints.street.bean.UserBean import com.mints.street.bean.UserBean
import com.mints.street.netwrok.common.HttpManager import com.mints.street.netwrok.common.HttpManager
...@@ -18,6 +19,15 @@ interface MainApi { ...@@ -18,6 +19,15 @@ interface MainApi {
return HttpManager.getInstance().defaultClient.create(MainApi::class.java) return HttpManager.getInstance().defaultClient.create(MainApi::class.java)
} }
} }
/**
* 获取验证码
*
* @return
*/
@POST("api/sendMobileCode")
fun sendMobileCode(@Body vo: @JvmSuppressWildcards Map<String, Any>): Observable<Response<BaseResponse<Any>>>
/** /**
* 登录 * 登录
*/ */
...@@ -25,9 +35,11 @@ interface MainApi { ...@@ -25,9 +35,11 @@ interface MainApi {
fun mobileLogin(@Body vo: @JvmSuppressWildcards Map<String, Any>): Observable<Response<BaseResponse<UserBean>>> fun mobileLogin(@Body vo: @JvmSuppressWildcards Map<String, Any>): Observable<Response<BaseResponse<UserBean>>>
/** /**
* 获取用户配置信息 * 提交设备信息
* *
* @return
*/ */
@POST("api/getCoinMsg") @POST("api/saveTerminalInfo")
fun getCoinMsg(): Observable<Response<BaseResponse<AwardBean>>> fun saveTerminalInfo(@Body vo: @JvmSuppressWildcards Map<String, Any>): Observable<Response<BaseResponse<Any>>>
} }
\ No newline at end of file
...@@ -5,31 +5,20 @@ import java.io.Serializable ...@@ -5,31 +5,20 @@ import java.io.Serializable
/** /**
* 描述:用户信息 * 描述:用户信息
* 作者:孟崔广 * 作者:孟崔广
* 时间:2019/10/29 18:42 * 时间:2021/7/29 18:42
* 邮箱:mengcga@163.com
*/ */
class UserBean : Serializable { class UserBean : Serializable {
val token: String? = null val token: String = ""
val toKeepAnAccount: String? = null
val consumer: ConsumerBean? = null val consumer: ConsumerBean? = null
inner class ConsumerBean : Serializable { inner class ConsumerBean : Serializable {
val head: String? = null val head: String = ""
val openid: String? = null val openid: String = ""
val nickname: String? = null val nickname: String = ""
val mobile: String? = null val mobile: String = ""
val real_name: String? = null val real_name: String = ""
val alipay_account: String? = null val idcode: String = ""
val idcode: String? = null
val gameInfo: String? = null
var sumCoin: String? = null
val surplus //余额
= 0.0
val coin // 积分
= 0
val pk_id // 用户id val pk_id // 用户id
: Long = 0 : Long = 0
val isFirstSignInApp // 首次登录app true:首次
= false
} }
} }
...@@ -30,7 +30,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(), View ...@@ -30,7 +30,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(), View
private fun initListener() { private fun initListener() {
binding.button.setOnClickListener { binding.button.setOnClickListener {
viewModel.login() viewModel.login("18311400069","123456")
} }
iv_left_icon.setOnClickListener(this) iv_left_icon.setOnClickListener(this)
......
...@@ -2,40 +2,114 @@ package com.mints.street.login ...@@ -2,40 +2,114 @@ 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.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.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl 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.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
import me.goldze.mvvmhabit.utils.ToastUtils
import java.util.HashMap
/** /**
* Created by 冯瑞雨 on 2021/7/2. * Created by mcg
*/ */
class LoginViewModel(application: Application) : BaseViewModel(application) { class LoginViewModel(application: Application) : BaseViewModel(application) {
val data :MutableLiveData<String> = MutableLiveData() val data :MutableLiveData<String> = MutableLiveData()
fun login() { val deviceInfo: DeviceInfo
get() {
return DeviceInfo.instance
}
ApiModel.coinMsg(lifecycleProvider).safeSubscribe( /**
object : HttpSubscribeImpl<BaseResponse<AwardBean>>( * 手机验证码
this@LoginViewModel, true *
) { * @param mobile
override fun onBusinessSuccess(response: BaseResponse<AwardBean>) { */
data.value = response.message fun sendMobileCode(mobile: String) {
KLog.e("sfdsdf", response.result.toString()) val vo = HashMap<String, Any>()
} vo["mobile"] = mobile
vo["type"] = 1
override fun onError(e: Throwable) { ApiModel.sendMobileCode(lifecycleProvider,vo).safeSubscribe(
data.value = "失败" object : HttpSubscribeImpl<BaseResponse<Any>>(
KLog.e("LoginViewModel", "登录错误") this@LoginViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<Any>) {
KLog.e("sendMobileCode", response.result.toString())
}
})
}
fun login(mobile: String, smsCode: String) {
val vo = HashMap<String, Any>()
vo["mobile"] = mobile
vo["smsCode"] = smsCode
vo["device"] = DeviceUuidFactory().deviceUuid.toString()
ApiModel.login(lifecycleProvider,vo).safeSubscribe(
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)
UserManager.INSTANCE.saveUserInfo(response.result)
this@LoginViewModel.saveTerminalInfo()
}
override fun onError(e: Throwable) {
data.value = "失败"
KLog.e("LoginViewModel", "登录错误")
}
})
}
/**
* 提交设备信息
*/
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
// 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
override fun onComplete() { ApiModel.saveTerminalInfo(lifecycleProvider,vo).safeSubscribe(
super.onComplete() 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
...@@ -2,13 +2,11 @@ package com.mints.street.main.home ...@@ -2,13 +2,11 @@ package com.mints.street.main.home
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.coorchice.library.utils.LogUtils
import com.fry.base.base.BaseActivity import com.fry.base.base.BaseActivity
import com.mints.street.BR import com.mints.street.BR
import com.mints.street.R import com.mints.street.R
import com.mints.street.databinding.ActivityHistoricalImageBinding import com.mints.street.databinding.ActivityHistoricalImageBinding
import kotlinx.android.synthetic.main.activity_historical_image.* import kotlinx.android.synthetic.main.activity_historical_image.*
import me.goldze.mvvmhabit.utils.ToastUtils
/** /**
* 描述:历史影像 * 描述:历史影像
...@@ -17,6 +15,8 @@ import me.goldze.mvvmhabit.utils.ToastUtils ...@@ -17,6 +15,8 @@ import me.goldze.mvvmhabit.utils.ToastUtils
*/ */
class HistoricalimageActivity :BaseActivity<ActivityHistoricalImageBinding, HistoricalimageModel>(), View.OnClickListener { class HistoricalimageActivity :BaseActivity<ActivityHistoricalImageBinding, HistoricalimageModel>(), View.OnClickListener {
var strings= mutableListOf<String>()
override fun initVariableId() = BR.viewModel override fun initVariableId() = BR.viewModel
override fun initContentView(savedInstanceState: Bundle?)= R.layout.activity_historical_image override fun initContentView(savedInstanceState: Bundle?)= R.layout.activity_historical_image
override fun initData() { override fun initData() {
...@@ -25,9 +25,23 @@ class HistoricalimageActivity :BaseActivity<ActivityHistoricalImageBinding, Hist ...@@ -25,9 +25,23 @@ class HistoricalimageActivity :BaseActivity<ActivityHistoricalImageBinding, Hist
} }
private fun initView() { private fun initView() {
iv_left.setOnClickListener(this)
iv_right.setOnClickListener(this)
bt_main.setOnClickListener(this)
for (i in 0..19) {
strings.add(i.toString() + "00")
}
hsMain.setData(strings)
} }
override fun onClick(v: View?) { override fun onClick(v: View?) {
when (v?.getId()) {
R.id.iv_left -> hsMain.setAnLeftOffset()
R.id.iv_right -> hsMain.setAnRightOffset()
R.id.bt_main -> tvMain.setText("所选文本:" + hsMain.getSelectedString())
else -> {
}
}
} }
} }
...@@ -13,11 +13,6 @@ class UserManager { ...@@ -13,11 +13,6 @@ class UserManager {
companion object { companion object {
/**
* 游客 or 登录用户
*/
private const val IS_TEMP_USER = "is_temp_user"
/** /**
* 用户ID * 用户ID
*/ */
...@@ -43,41 +38,6 @@ class UserManager { ...@@ -43,41 +38,6 @@ class UserManager {
*/ */
private const val REAL_NAME = "realName" private const val REAL_NAME = "realName"
/**
* 支付宝
*/
private const val ALIPAY_ACCOUNT = "alipay_account"
/**
* 用户金币
*/
private const val USER_GOLD = "user_gold"
/**
* 用户总金币
*/
private const val USER_SUM_GOLD = "user_sum_gold"
/**
* 用户零钱
*/
private const val USER_CASH = "user_cash"
/**
* 是否老用户 true-老用户
*/
private const val USER_OLD = "user_old"
/**
* 猎豹游戏info
*/
private const val GAME_INFO = "game_info"
/**
* 广告隐藏标识
*/
private const val AD_SHOW_FLAG = "ad_show_flag"
/** /**
* 微信名称 * 微信名称
*/ */
...@@ -117,25 +77,16 @@ class UserManager { ...@@ -117,25 +77,16 @@ class UserManager {
if (user != null) { if (user != null) {
val mobile: String? = user.mobile val mobile: String? = user.mobile
val openid: String? = user.openid val openid: String? = user.openid
if (mobile == null && openid == null) {
MMKV.mmkvWithID(IS_TEMP_USER).remove(IS_TEMP_USER)
} else {
MMKV.mmkvWithID(IS_TEMP_USER).encode(IS_TEMP_USER, mobile + openid)
}
MMKV.mmkvWithID(USER_ID).encode(USER_ID, user.pk_id.toString()) MMKV.mmkvWithID(USER_ID).encode(USER_ID, user.pk_id.toString())
MMKV.mmkvWithID(CODE_ID).encode(CODE_ID, user.idcode.toString()) MMKV.mmkvWithID(CODE_ID).encode(CODE_ID, user.idcode.toString())
MMKV.mmkvWithID(MOBILE).encode(MOBILE, mobile) if (!TextUtils.isEmpty(mobile)) {
MMKV.mmkvWithID(ALIPAY_ACCOUNT) MMKV.mmkvWithID(MOBILE).encode(MOBILE, mobile)
.encode(ALIPAY_ACCOUNT, user.alipay_account.toString()) }
MMKV.mmkvWithID(USER_GOLD).encode(USER_GOLD, user.coin.toString())
MMKV.mmkvWithID(USER_CASH)
.encode(USER_CASH, String.format("%.2f", user.surplus))
MMKV.mmkvWithID(USER_SUM_GOLD).encode(USER_SUM_GOLD, user.sumCoin.toString())
MMKV.mmkvWithID(USER_OLD).encode(USER_OLD, !user.isFirstSignInApp)
MMKV.mmkvWithID(WX_NAME).encode(WX_NAME, user.nickname.toString()) MMKV.mmkvWithID(WX_NAME).encode(WX_NAME, user.nickname.toString())
MMKV.mmkvWithID(WX_HEADER).encode(WX_HEADER, user.head) MMKV.mmkvWithID(WX_HEADER).encode(WX_HEADER, user.head)
MMKV.mmkvWithID(WX_OPENID).encode(WX_OPENID, openid) if (!TextUtils.isEmpty(openid)) {
MMKV.mmkvWithID(GAME_INFO).encode(GAME_INFO, user.gameInfo) MMKV.mmkvWithID(WX_OPENID).encode(WX_OPENID, openid)
}
MMKV.mmkvWithID(REAL_NAME).encode(REAL_NAME, user.real_name) MMKV.mmkvWithID(REAL_NAME).encode(REAL_NAME, user.real_name)
} }
} }
...@@ -154,7 +105,7 @@ class UserManager { ...@@ -154,7 +105,7 @@ class UserManager {
* @return true为已登录 false 为未登录 * @return true为已登录 false 为未登录
*/ */
fun userIsLogin(): Boolean { fun userIsLogin(): Boolean {
val kv = MMKV.mmkvWithID(IS_TEMP_USER).decodeString(IS_TEMP_USER, "") val kv = MMKV.mmkvWithID(WX_OPENID).decodeString(WX_OPENID, "")
return !TextUtils.isEmpty(kv) return !TextUtils.isEmpty(kv)
} }
...@@ -200,83 +151,6 @@ class UserManager { ...@@ -200,83 +151,6 @@ class UserManager {
kv.encode(REAL_NAME, name) kv.encode(REAL_NAME, name)
} }
/**
* 是否老用户 true-老用户
*/
fun getUserOld(): Boolean {
val kv = MMKV.mmkvWithID(USER_OLD)
return kv.decodeBool(USER_OLD, false)
}
fun getAdShowFlag(): Boolean {
val kv = MMKV.mmkvWithID(AD_SHOW_FLAG)
return kv.decodeBool(AD_SHOW_FLAG, false)
}
/**
* 设置真实姓名
*
* @param userOld
*/
fun setUserOld(userOld: Boolean) {
val kv = MMKV.mmkvWithID(USER_OLD)
kv.encode(USER_OLD, userOld)
}
/**
* 获取支付宝账户
*/
fun getAlipayAccount(): String {
val kv = MMKV.mmkvWithID(ALIPAY_ACCOUNT)
return kv.decodeString(ALIPAY_ACCOUNT, "")
}
/**
* 设置支付宝账户
*
* @param alipay
*/
fun setAlipayAccount(alipay: String?) {
val kv = MMKV.mmkvWithID(ALIPAY_ACCOUNT)
kv.encode(ALIPAY_ACCOUNT, alipay)
}
fun getUserSumGold(): String {
val kv = MMKV.mmkvWithID(USER_SUM_GOLD)
return kv.decodeString(USER_SUM_GOLD, "")
}
/**
* 获取用户金币/积分
*/
fun getUserGold(): String {
val kv = MMKV.mmkvWithID(USER_GOLD)
return kv.decodeString(USER_GOLD, "")
}
/**
* 设置用户金币/积分
*
* @param gold
*/
fun setUserGold(gold: String?) {
val kv = MMKV.mmkvWithID(USER_GOLD)
kv.encode(USER_GOLD, gold)
}
/**
* 获取用户零钱
*/
fun getUserCash(): String {
val kv = MMKV.mmkvWithID(USER_CASH)
return kv.decodeString(USER_CASH, "")
}
fun getGameInfo(): String {
val kv = MMKV.mmkvWithID(GAME_INFO)
return kv.decodeString(GAME_INFO, "")
}
fun getWxName(): String { fun getWxName(): String {
val kv = MMKV.mmkvWithID(WX_NAME) val kv = MMKV.mmkvWithID(WX_NAME)
return kv.decodeString(WX_NAME, "") return kv.decodeString(WX_NAME, "")
...@@ -292,21 +166,6 @@ class UserManager { ...@@ -292,21 +166,6 @@ class UserManager {
return kv.decodeString(WX_OPENID, "") return kv.decodeString(WX_OPENID, "")
} }
/**
* 设置用户零钱
*
* @param cash
*/
fun setUserCash(cash: String?) {
val kv = MMKV.mmkvWithID(USER_CASH)
kv.encode(WX_OPENID, cash)
}
fun setGameInfo(gameInfo: String?) {
val kv = MMKV.mmkvWithID(GAME_INFO)
kv.encode(GAME_INFO, gameInfo)
}
fun setWxName(wxName: String?) { fun setWxName(wxName: String?) {
val kv = MMKV.mmkvWithID(WX_NAME) val kv = MMKV.mmkvWithID(WX_NAME)
kv.encode(WX_NAME, wxName) kv.encode(WX_NAME, wxName)
...@@ -327,25 +186,14 @@ class UserManager { ...@@ -327,25 +186,14 @@ class UserManager {
kv.encode(MOBILE, mobile) kv.encode(MOBILE, mobile)
} }
fun setAdShowFlag(adShowFlag: Boolean) {
val kv = MMKV.mmkvWithID(AD_SHOW_FLAG)
kv.encode(AD_SHOW_FLAG, adShowFlag)
}
fun userLogout() { fun userLogout() {
MMKV.mmkvWithID(USER_ID).remove(USER_ID) MMKV.mmkvWithID(USER_ID).remove(USER_ID)
MMKV.mmkvWithID(CODE_ID).remove(CODE_ID) MMKV.mmkvWithID(CODE_ID).remove(CODE_ID)
MMKV.mmkvWithID(TOKEN_ID).remove(TOKEN_ID) MMKV.mmkvWithID(TOKEN_ID).remove(TOKEN_ID)
MMKV.mmkvWithID(REAL_NAME).remove(REAL_NAME) MMKV.mmkvWithID(REAL_NAME).remove(REAL_NAME)
MMKV.mmkvWithID(IS_TEMP_USER).remove(IS_TEMP_USER)
MMKV.mmkvWithID(ALIPAY_ACCOUNT).remove(ALIPAY_ACCOUNT)
MMKV.mmkvWithID(USER_GOLD).remove(USER_GOLD)
MMKV.mmkvWithID(USER_CASH).remove(USER_CASH)
MMKV.mmkvWithID(USER_OLD).remove(USER_OLD)
MMKV.mmkvWithID(WX_OPENID).remove(WX_OPENID) MMKV.mmkvWithID(WX_OPENID).remove(WX_OPENID)
MMKV.mmkvWithID(WX_NAME).remove(WX_NAME) MMKV.mmkvWithID(WX_NAME).remove(WX_NAME)
MMKV.mmkvWithID(WX_HEADER).remove(WX_HEADER) MMKV.mmkvWithID(WX_HEADER).remove(WX_HEADER)
// MMKV.mmkvWithID(GAME_INFO).remove(GAME_INFO)
} }
} }
\ No newline at end of file
...@@ -13,6 +13,16 @@ import retrofit2.Response ...@@ -13,6 +13,16 @@ import retrofit2.Response
* Created by 冯瑞雨 on 2021/7/2. * Created by 冯瑞雨 on 2021/7/2.
*/ */
object ApiModel { object ApiModel {
/**
* 发送验证码
*/
fun sendMobileCode(lifecycleProvider: LifecycleProvider<Any>?
,map: Map<String, Any>): Observable<Response<BaseResponse<Any>>> {
return HttpManager.getInstance()
.execute(lifecycleProvider,MainApi.newInstance().sendMobileCode(map))
}
/** /**
* 登录 * 登录
*/ */
...@@ -21,13 +31,13 @@ object ApiModel { ...@@ -21,13 +31,13 @@ object ApiModel {
return HttpManager.getInstance() return HttpManager.getInstance()
.execute(lifecycleProvider,MainApi.newInstance().mobileLogin(map)) .execute(lifecycleProvider,MainApi.newInstance().mobileLogin(map))
} }
/** /**
* 获取用户配置信息 * 设备信息
*
*/ */
fun saveTerminalInfo(lifecycleProvider: LifecycleProvider<Any>?
fun coinMsg(lifecycleProvider: LifecycleProvider<Any>?): Observable<Response<BaseResponse<AwardBean>>> { ,map: Map<String, Any>): Observable<Response<BaseResponse<Any>>> {
return HttpManager.getInstance() return HttpManager.getInstance()
.execute(lifecycleProvider,MainApi.newInstance().getCoinMsg()) .execute(lifecycleProvider,MainApi.newInstance().saveTerminalInfo(map))
} }
} }
\ No newline at end of file
...@@ -7,6 +7,9 @@ import androidx.annotation.NonNull; ...@@ -7,6 +7,9 @@ import androidx.annotation.NonNull;
import com.fry.base.BuildConfig; import com.fry.base.BuildConfig;
import com.mints.street.netwrok.common.GsonConverterFactory; import com.mints.street.netwrok.common.GsonConverterFactory;
import com.mints.street.netwrok.common.OkHttpInterceptor;
import com.mints.street.utils.encry.AESUtils;
import com.orhanobut.logger.Logger;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -23,6 +26,7 @@ import okhttp3.ConnectionPool; ...@@ -23,6 +26,7 @@ import okhttp3.ConnectionPool;
import okhttp3.Interceptor; import okhttp3.Interceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.internal.platform.Platform; import okhttp3.internal.platform.Platform;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
...@@ -56,28 +60,49 @@ public class RetrofitClient { ...@@ -56,28 +60,49 @@ public class RetrofitClient {
.connectionPool(new ConnectionPool(8, 15, TimeUnit.SECONDS)); .connectionPool(new ConnectionPool(8, 15, TimeUnit.SECONDS));
// 这里你可以根据自己的机型设置同时连接的个数和时间,我这里8个,和每个保持时间为10s // 这里你可以根据自己的机型设置同时连接的个数和时间,我这里8个,和每个保持时间为10s
if (configuation.getInterceptors() != null) { // if (configuation.getInterceptors() != null) {
for (Interceptor interceptor : configuation.getInterceptors()) { // for (Interceptor interceptor : configuation.getInterceptors()) {
clientBuilder.addInterceptor(interceptor); // clientBuilder.addInterceptor(interceptor);
} // }
} // }
if(BuildConfig.IS_DEV) { // if(BuildConfig.IS_DEV) {
clientBuilder.addInterceptor(new LoggingInterceptor // clientBuilder.addInterceptor(new LoggingInterceptor
.Builder() // .Builder()
//是否开启日志打印 // //是否开启日志打印
.loggable(BuildConfig.DEBUG) // .loggable(BuildConfig.DEBUG)
//打印的等级 // //打印的等级
.setLevel(Level.BASIC) // .setLevel(Level.BASIC)
// 打印类型 // // 打印类型
.log(Platform.INFO) // .log(Platform.INFO)
// request的Tag // // request的Tag
.request("Request") // .request("Request")
// Response的Tag // // Response的Tag
.response("Request") // .response("Request")
// .addHeader("log-header", "I am the log request header.") // 添加打印头, 注意 key 和 value 都不能是中文 //// .addHeader("log-header", "I am the log request header.") // 添加打印头, 注意 key 和 value 都不能是中文
.build() // .build()
); // );
// }
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
if (TextUtils.isEmpty(message)) return;
String s = message.substring(0, 1);
String request = message.substring(0, 4);
if ("{".equals(s) || "[".equals(s)) {
Logger.json(message);
} else if (request.contains("-->") || request.contains("<--")) {
Logger.d("Method" + message);
} else {
Logger.d("params:" + message);
}
});
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
clientBuilder.interceptors().add(logging);
} }
OkHttpInterceptor okHttpInterceptor = new OkHttpInterceptor(AESUtils.getDefaultKey());
clientBuilder.interceptors().add(okHttpInterceptor);
mOkHttpClient = clientBuilder.build(); mOkHttpClient = clientBuilder.build();
mRetrofit = new Retrofit.Builder() mRetrofit = new Retrofit.Builder()
.client(mOkHttpClient) .client(mOkHttpClient)
......
...@@ -42,7 +42,6 @@ public class HttpManager { ...@@ -42,7 +42,6 @@ public class HttpManager {
private HttpManager() { private HttpManager() {
mDefaultClient = new RetrofitClient( mDefaultClient = new RetrofitClient(
HttpConfiguation.create(Constants.getBaseUrl()) HttpConfiguation.create(Constants.getBaseUrl())
.addInterceptor(new OkHttpInterceptor(AESUtils.getDefaultKey()))
); );
} }
......
...@@ -165,10 +165,6 @@ class OkHttpInterceptor(aesKey: String) : Interceptor { ...@@ -165,10 +165,6 @@ class OkHttpInterceptor(aesKey: String) : Interceptor {
// 解密 // 解密
try { try {
val json = JSONObject(rspString) val json = JSONObject(rspString)
// if(!json.isNull("status")&& TextUtils.equals(json["status"].toString(),"401")){
// return
// }
if (!json.isNull("data")) { if (!json.isNull("data")) {
val data = json["data"] val data = json["data"]
rspString = AESUtils.detrypt(data.toString(), aesKey) rspString = AESUtils.detrypt(data.toString(), aesKey)
......
package com.mints.street.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import com.mints.street.AppApplication;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
/**
* 描述:google生成android设备UUID
* 作者:孟崔广
* 时间:2018/5/9 20:03
* 邮箱:mengcg@xiaojinqb.cn
*/
public class DeviceUuidFactory {
protected static final String PREFS_FILE = "device_id.xml";
protected static final String PREFS_DEVICE_ID = "device_id";
protected static UUID uuid;
public DeviceUuidFactory() {
Context context= AppApplication.Companion.getContext();
if (uuid == null) {
synchronized (DeviceUuidFactory.class) {
if (uuid == null) {
final SharedPreferences prefs = context.getSharedPreferences(PREFS_FILE, 0);
final String id = prefs.getString(PREFS_DEVICE_ID, null);
if (id != null) {
// Use the ids previously computed and stored in the prefs file
uuid = UUID.fromString(id);
} else {
final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
// Use the Android ID unless it's broken, in which case fallback on deviceId,
// unless it's not available, then fallback on a random number which we store
// to a prefs file
try {
if (!"9774d56d682e549c".equals(androidId)) {
uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
} else {
final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
uuid = deviceId != null ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")) : UUID.randomUUID();
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
// Write the value out to the prefs file
prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString()).commit();
}
}
}
}
}
/**
* Returns a unique UUID for the current android device. As with all UUIDs, this unique ID is "very highly likely"
* to be unique across all Android devices. Much more so than ANDROID_ID is.
* <p>
* The UUID is generated by using ANDROID_ID as the base key if appropriate, falling back on
* TelephonyManager.getDeviceID() if ANDROID_ID is known to be incorrect, and finally falling back
* on a random UUID that's persisted to SharedPreferences if getDeviceID() does not return a
* usable value.
* <p>
* In some rare circumstances, this ID may change. In particular, if the device is factory reset a new device ID
* may be generated. In addition, if a user upgrades their phone from certain buggy implementations of Android 2.2
* to a newer, non-buggy version of Android, the device ID may change. Or, if a user uninstalls your app on
* a device that has neither a proper Android ID nor a Device ID, this ID may change on reinstallation.
* <p>
* Note that if the code falls back on using TelephonyManager.getDeviceId(), the resulting ID will NOT
* change after a factory reset. Something to be aware of.
* <p>
* Works around a bug in Android 2.2 for many devices when using ANDROID_ID directly.
*
* @return a UUID that may be used to uniquely identify your device for most purposes.
* @see //http://code.google.com/p/android/issues/detail?id=10603
*/
public UUID getDeviceUuid() {
return uuid;
}
}
package com.mints.street.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.TintTypedArray;
import com.mints.street.R;
import java.util.ArrayList;
import java.util.List;
/**
* Created by 孟崔广
*/
public class HorizontalselectedView extends View {
private Context context;
private List<String> strings = new ArrayList<String>();//数据源字符串数组
private int seeSize = 5;//可见个数
private int anInt;//每个字母所占的大小;
private TextPaint textPaint;
private boolean firstVisible = true;
private int width;//控件宽度
private int height;//控件高度
private Paint selectedPaint;//被选中文字的画笔
private int n;
private float downX;
private float anOffset;
private float selectedTextSize;
private int selectedColor;
private float textSize;
private int textColor;
private Rect rect = new Rect();
;
private int textWidth = 0;
private int textHeight = 0;
private int centerTextHeight = 0;
public HorizontalselectedView(Context context) {
this(context, null);
}
public HorizontalselectedView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public HorizontalselectedView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
setWillNotDraw(false);
setClickable(true);
initAttrs(attrs);//初始化属性
initPaint();//初始化画笔
}
/**
* 初始化画笔
*/
private void initPaint() {
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(textSize);
textPaint.setColor(textColor);
selectedPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
selectedPaint.setColor(selectedColor);
selectedPaint.setTextSize(selectedTextSize);
}
/**
* 初始化属性
* @param attrs
*/
private void initAttrs(AttributeSet attrs) {
TintTypedArray tta = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.HorizontalselectedView);
//两种字体颜色和字体大小
seeSize = tta.getInteger(R.styleable.HorizontalselectedView_HorizontalselectedViewSeesize, 5);
selectedTextSize = tta.getFloat(R.styleable.HorizontalselectedView_HorizontalselectedViewSelectedTextSize, 50);
selectedColor = tta.getColor(R.styleable.HorizontalselectedView_HorizontalselectedViewSelectedTextColor, context.getResources().getColor(android.R.color.black));
textSize = tta.getFloat(R.styleable.HorizontalselectedView_HorizontalselectedViewTextSize, 40);
textColor = tta.getColor(R.styleable.HorizontalselectedView_HorizontalselectedViewTextColor, context.getResources().getColor(android.R.color.darker_gray));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.e("action", "onTouchEvent: " + event.getAction());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = event.getX();//获得点下去的x坐标
break;
case MotionEvent.ACTION_MOVE://复杂的是移动时的判断
float scrollX = event.getX();
if (n != 0 && n != strings.size() - 1)
anOffset = scrollX - downX;//滑动时的偏移量,用于计算每个是数据源文字的坐标值
else {
anOffset = (float) ((scrollX - downX) / 1.5);//当滑到两端的时候添加一点阻力
}
if (scrollX > downX) {
//向右滑动,当滑动距离大于每个单元的长度时,则改变被选中的文字。
if (scrollX - downX >= anInt) {
if (n > 0) {
anOffset = 0;
n = n - 1;
downX = scrollX;
}
}
} else {
//向左滑动,当滑动距离大于每个单元的长度时,则改变被选中的文字。
if (downX - scrollX >= anInt) {
if (n < strings.size() - 1) {
anOffset = 0;
n = n + 1;
downX = scrollX;
}
}
}
invalidate();
break;
case MotionEvent.ACTION_UP:
//抬起手指时,偏移量归零,相当于回弹。
anOffset = 0;
invalidate();
break;
default:
break;
}
return super.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (firstVisible) {//第一次绘制的时候得到控件 宽高;
width = getWidth();
height = getHeight();
anInt = width / seeSize;
firstVisible = false;
}
if (n >= 0 && n <= strings.size() - 1) {//加个保护;防止越界
String s = strings.get(n);//得到被选中的文字
/**
* 得到被选中文字 绘制时所需要的宽高
*/
selectedPaint.getTextBounds(s, 0, s.length(), rect);
//3从矩形区域中读出文本内容的宽高
int centerTextWidth = rect.width();
centerTextHeight = rect.height();
canvas.drawText(strings.get(n), getWidth() / 2 - centerTextWidth / 2 + anOffset, getHeight() / 2 + centerTextHeight / 2, selectedPaint);//绘制被选中文字,注意点是y坐标
for (int i = 0; i < strings.size(); i++) {//遍历strings,把每个地方都绘制出来,
if (n > 0 && n < strings.size() - 1) {//这里主要是因为strings数据源的文字长度不一样,为了让被选中两边文字距离中心宽度一样,我们取得左右两个文字长度的平均值
textPaint.getTextBounds(strings.get(n - 1), 0, strings.get(n - 1).length(), rect);
int width1 = rect.width();
textPaint.getTextBounds(strings.get(n + 1), 0, strings.get(n + 1).length(), rect);
int width2 = rect.width();
textWidth = (width1 + width2) / 2;
}
if (i == 0) {//得到高,高度是一样的,所以无所谓
textPaint.getTextBounds(strings.get(0), 0, strings.get(0).length(), rect);
textHeight = rect.height();
}
if (i != n)
canvas.drawText(strings.get(i), (i - n) * anInt + getWidth() / 2 - textWidth / 2 + anOffset, getHeight() / 2 + textHeight / 2, textPaint);//画出每组文字
}
}
}
/**
* 改变中间可见文字的数目
*
* @param seeSizes 可见数
*/
public void setSeeSize(int seeSizes) {
if (seeSize > 0) {
seeSize = seeSizes;
invalidate();
}
}
/**
* 向左移动一个单元
*/
public void setAnLeftOffset() {
if (n < strings.size() - 1) {
n = n + 1;
invalidate();
}
}
/**
* 向右移动一个单元
*/
public void setAnRightOffset() {
if (n > 0) {
n = n - 1;
invalidate();
}
}
/**
* 设置个数据源
*
* @param strings 数据源String集合
*/
public void setData(List<String> strings) {
this.strings = strings;
n = strings.size() / 2;
invalidate();
}
/**
* 获得被选中的文本
*
* @return 被选中的文本
*/
public String getSelectedString() {
if (strings.size() != 0) {
return strings.get(n);
}
return null;
}
}
...@@ -8,10 +8,92 @@ ...@@ -8,10 +8,92 @@
name="viewModel" name="viewModel"
type="com.mints.street.main.home.HistoricalimageModel" /> type="com.mints.street.main.home.HistoricalimageModel" />
</data> </data>
<LinearLayout <LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="wrap_content"
android:layout_height="match_parent"> android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center"
android:textColor="@color/black"
android:text="V" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/darker_gray"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="@+id/iv_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:gravity="center"
android:text="<"
android:textSize="16sp" />
<com.mints.street.widget.HorizontalselectedView
android:id="@+id/hsMain"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="30"
app:HorizontalselectedViewSeesize="5"
app:HorizontalselectedViewSelectedTextColor="@color/black"
app:HorizontalselectedViewSelectedTextSize="60"
app:HorizontalselectedViewTextColor="@color/gray"
app:HorizontalselectedViewTextSize="40" />
<TextView
android:id="@+id/iv_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:gravity="center"
android:text=">"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/darker_gray"></View>
<Button
android:id="@+id/bt_main"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
android:text="点击获得被选文本" />
<TextView
android:padding="5dp"
android:gravity="center"
android:id="@+id/tvMain"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textSize="20sp"
android:layout_marginTop="20dp"
android:background="@color/gray" />
</LinearLayout> </LinearLayout>
</layout> </layout>
\ No newline at end of file
...@@ -4,4 +4,16 @@ ...@@ -4,4 +4,16 @@
<attr name="border_width" format="dimension" /> <attr name="border_width" format="dimension" />
<attr name="border_color" format="color" /> <attr name="border_color" format="color" />
</declare-styleable> </declare-styleable>
<declare-styleable name="HorizontalselectedView">
<!--可见数目-->
<attr name="HorizontalselectedViewSeesize" format="integer"></attr>
<!--被选择文字的大小和颜色-->
<attr name="HorizontalselectedViewSelectedTextSize" format="float"></attr>
<attr name="HorizontalselectedViewSelectedTextColor" format="color|reference"></attr>
<!--未被被选择文字的大小和颜色-->
<attr name="HorizontalselectedViewTextSize" format="float"></attr>
<attr name="HorizontalselectedViewTextColor" format="color|reference"></attr>
</declare-styleable>
</resources> </resources>
\ No newline at end of file
...@@ -20,7 +20,7 @@ android.enableJetifier=true ...@@ -20,7 +20,7 @@ android.enableJetifier=true
isBuildModule=false isBuildModule=false
DEBUG_URL="http://test.mints-id.com/camera-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/gc-api/"
RELEASE_KEY_PASSWORD=mints.street RELEASE_KEY_PASSWORD=mints.street
......
...@@ -70,6 +70,7 @@ dependencies { ...@@ -70,6 +70,7 @@ 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库引用
......
...@@ -43,7 +43,7 @@ public class BaseResponse<T> { ...@@ -43,7 +43,7 @@ public class BaseResponse<T> {
} }
public boolean isOk() { public boolean isOk() {
return status >= 200 && status < 300; return status == 200 && status < 700;
} }
public String getMessage() { public String getMessage() {
......
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