code style opt, reduce build time : 1m30s

This commit is contained in:
unknown
2020-11-10 16:18:36 +08:00
parent 8b59221f71
commit b2af80dce8
42 changed files with 184 additions and 399 deletions

View File

@@ -61,7 +61,7 @@ open class IMogoAuthorizeController {
})
}
private fun realInvokeAuthorizeContent(agreementType: Int, onStart: (() -> Unit), onSuccess: ((BaseResponse<AgreementData>) -> Unit), onError: ((String) -> Unit), needContent: Boolean = false) {
private fun realInvokeAuthorizeContent(agreementType: Int, onStart: (() -> Unit), onSuccess: ((BaseResponse<AgreementData?>) -> Unit), onError: ((String) -> Unit), needContent: Boolean = false) {
onStart.invoke()
try {
request<BaseResponse<AgreementData>> {

View File

@@ -8,7 +8,7 @@ import com.mogo.module.authorize.model.proxy.toAuthorizeType
import com.mogo.module.authorize.util.SharedPreferenceUtil.needAuthorization
import com.mogo.utils.logger.Logger
open abstract class MogoAuthorizeManagerImpl : IMogoAuthorizeInvoke {
abstract class MogoAuthorizeManagerImpl : IMogoAuthorizeInvoke {
companion object {
const val TAG = "AuthorizeManagerImpl"

View File

@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")
package com.mogo.module.authorize.authprovider.biz
import android.content.Context
@@ -11,7 +13,6 @@ import com.mogo.map.marker.IMogoMarkerClickListener
import com.mogo.map.navi.IMogoNaviListener
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant.Companion.PATH_AGREEMENT_MODULE_NAME
import com.mogo.module.authorize.authprovider.invoke.AuthorizeInvokerConstant.Companion.AUTHORIZE_TYPE_LAUNCHER_MAIN
import com.mogo.module.authorize.authprovider.launcher.MogoMainAuthorize
import com.mogo.module.authorize.authprovider.launcher.MogoMainAuthorize.Companion.mogoAuthShow
import com.mogo.module.authorize.util.SharedPreferenceUtil.hasGuide
import com.mogo.service.MogoServicePaths

View File

@@ -42,9 +42,9 @@ class AuthorizeController {
agreementContent: (id: Long, content: String, title: String, bottomContent: String, lastContent: String) -> Unit,
agreementError: () -> Unit) {
Logger.d(TAG, "requestContentSuccess userAgreement:$userAgreement")
if (userAgreement.agreementContent.isNotEmpty()) {
if (userAgreement.agreementContent!= null && userAgreement.agreementContent!!.isNotEmpty()) {
val id = userAgreement.tUserAgreementEntity.id
val content = userAgreement.agreementContent[0]
val content = userAgreement.agreementContent!![0]
val title = userAgreement.tUserAgreementEntity.title
val bottomContent = userAgreement.tUserAgreementEntity.agreementButtonFirst
val lastContent = userAgreement.tUserAgreementEntity.agreementButtonSecond

View File

@@ -10,6 +10,7 @@ import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.debug.DebugConfig
import com.mogo.module.authorize.R
import com.mogo.module.authorize.util.AnalyticsUtil
import com.mogo.module.authorize.util.HtmlUtil
import com.mogo.module.authorize.voice.IVoiceAuthorizeIntentListener
import com.mogo.module.authorize.voice.IVoiceCommandListener
import com.mogo.module.authorize.voice.VoiceUtil
@@ -22,14 +23,15 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
class AuthorizeDialog : BaseFloatDialog, View.OnClickListener, IVoiceCommandListener, IVoiceAuthorizeIntentListener {
class AuthorizeDialog(invokeTag: String, context: Context) : BaseFloatDialog(context),
View.OnClickListener, IVoiceCommandListener, IVoiceAuthorizeIntentListener {
companion object {
const val TAG = "AuthorizeDialog"
}
private var mContext: Context? = null
private var invokeTag: String? = null
private var mContext: Context? = context
private var invokeTag: String? = invokeTag
private var agreementId: Long = 0L
@@ -48,9 +50,7 @@ class AuthorizeDialog : BaseFloatDialog, View.OnClickListener, IVoiceCommandList
private var authorizeController: AuthorizeController? = null
constructor(invokeTag: String, context: Context) : super(context) {
mContext = context
this.invokeTag = invokeTag
init {
initView()
}
@@ -62,24 +62,24 @@ class AuthorizeDialog : BaseFloatDialog, View.OnClickListener, IVoiceCommandList
private fun setWrapContent() {
val mWindow = window
if(DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_BYD){
if (mWindow != null && CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X) {
val lp = mWindow.attributes
lp.width = 1920
lp.height = 1080
mWindow.attributes = lp
}else{
val lp = mWindow.attributes
lp.width = 1024
lp.height = 600
mWindow.attributes = lp
}
}else{
if (mWindow != null) {
val lp = mWindow.attributes
mWindow?.let {
if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_BYD) {
if (CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X) {
val lp = it.attributes
lp.width = 1920
lp.height = 1080
it.attributes = lp
} else {
val lp = it.attributes
lp.width = 1024
lp.height = 600
it.attributes = lp
}
} else {
val lp = it.attributes
lp.width = 1920
lp.height = 1000
mWindow.attributes = lp
it.attributes = lp
}
}
}
@@ -132,15 +132,15 @@ class AuthorizeDialog : BaseFloatDialog, View.OnClickListener, IVoiceCommandList
this.agreementId = agreementId
clLoadAuthorizeContainer?.visibility = View.GONE
clContainer?.visibility = View.VISIBLE
tvTitle?.text = Html.fromHtml(agreementTitle)
tvTitle?.text = HtmlUtil.getSpanned(agreementTitle)
GlobalScope.async(Dispatchers.IO) {
val spannable = Html.fromHtml(agreementContent)
val spannable = HtmlUtil.getSpanned(agreementContent)
withContext(Dispatchers.Main) {
tvContent?.text = spannable
}
}
tvButtonContent?.text = Html.fromHtml(agreementBottom)
tvLastContent?.text = Html.fromHtml(agreementLast)
tvButtonContent?.text = HtmlUtil.getSpanned(agreementBottom)
tvLastContent?.text = HtmlUtil.getSpanned(agreementLast)
}
private fun showAuthorizationError() {

View File

@@ -1,179 +0,0 @@
package com.mogo.module.authorize.layout
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.commons.AbsMogoApplication
import com.mogo.module.authorize.R
import com.mogo.module.authorize.util.AnalyticsUtil
import com.mogo.module.authorize.util.AnalyticsUtil.INVOKE_TRACK_AUTHORIZE_CLICK
import com.mogo.module.authorize.util.AnalyticsUtil.INVOKE_TRACK_AUTHORIZE_SHOW
import com.mogo.module.authorize.voice.IVoiceAuthorizeIntentListener
import com.mogo.module.authorize.voice.IVoiceCommandListener
import com.mogo.module.authorize.voice.VoiceUtil
import com.mogo.utils.logger.Logger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
class AuthorizeLayout(private val invokeTag: String) : View.OnClickListener, IVoiceCommandListener, IVoiceAuthorizeIntentListener {
companion object {
const val TAG = "AuthorizeLayout"
}
private var agreementId: Long = 0L
private var clTopParent: ConstraintLayout? = null
private var clErrorContainer: ConstraintLayout? = null
private var clLoadAuthorizeContainer: ConstraintLayout? = null
private var clContainer: ConstraintLayout? = null
private var clAuthorizeLoading: ConstraintLayout? = null
private var btnAgree: Button? = null
private var btnDisAgree: Button? = null
private var btnLoadingError: Button? = null
private var tvTitle: TextView? = null
private var tvContent: TextView? = null
private var tvButtonContent: TextView? = null
private var tvLastContent: TextView? = null
private lateinit var layoutInflater: View
private var authorizeController: AuthorizeController? = null
fun getLayoutView(): View {
layoutInflater = LayoutInflater.from(AbsMogoApplication.getApp().applicationContext).inflate(getLayoutId(), null)
initViews(layoutInflater)
return layoutInflater
}
fun getLayoutId(): Int {
return R.layout.module_authorize_fragment
}
fun initViews(mRootView: View) {
Logger.d(TAG, "initView ")
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_SHOW)
init(mRootView)
Logger.d(TAG, "invokeTag :$invokeTag")
authorizeController = AuthorizeController(invokeTag)
invokeAuthorizationContent()
VoiceUtil.registerAll(this, this)
}
private fun init(mRootView: View) {
clTopParent = mRootView.findViewById(R.id.clAuthorizeTopParent)
clErrorContainer = mRootView.findViewById(R.id.clLoadingErrorContainer)
clLoadAuthorizeContainer = mRootView.findViewById(R.id.clLoadingAuthorizeContainer)
clContainer = mRootView.findViewById(R.id.clAuthorizeContainer)
clAuthorizeLoading = mRootView.findViewById(R.id.clAuthorizeLoading)
btnAgree = mRootView.findViewById(R.id.btnAuthorizeAgree)
btnDisAgree = mRootView.findViewById(R.id.btnAuthorizeDisAgree)
btnLoadingError = mRootView.findViewById(R.id.btnAuthorizeLoadingError)
tvTitle = mRootView.findViewById(R.id.tvAuthorizeTitle)
tvContent = mRootView.findViewById(R.id.tvAuthorizeContent)
tvButtonContent = mRootView.findViewById(R.id.tvAuthorizeButtonContent)
tvLastContent = mRootView.findViewById(R.id.tvAuthorizeLastContent)
btnAgree?.setOnClickListener(this)
btnDisAgree?.setOnClickListener(this)
btnLoadingError?.setOnClickListener(this)
clTopParent?.setOnClickListener(this)
clContainer?.setOnClickListener(this)
clErrorContainer?.setOnClickListener(this)
clLoadAuthorizeContainer?.setOnClickListener(this)
clAuthorizeLoading?.setOnClickListener(this)
}
private fun readyToAuthorize() {
clErrorContainer?.visibility = View.GONE
clLoadAuthorizeContainer?.visibility = View.VISIBLE
}
private fun showAuthorizationAgreementContent(
agreementId: Long,
agreementContent: String,
agreementTitle: String,
agreementBottom: String,
agreementLast: String) {
VoiceUtil.speak(AbsMogoApplication.getApp().applicationContext.resources.getString(R.string.module_authorize_agreement_tip), AbsMogoApplication.getApp().applicationContext, this)
this.agreementId = agreementId
clLoadAuthorizeContainer?.visibility = View.GONE
clContainer?.visibility = View.VISIBLE
tvTitle?.text = Html.fromHtml(agreementTitle)
GlobalScope.async(Dispatchers.IO) {
val spannable = Html.fromHtml(agreementContent)
withContext(Dispatchers.Main) {
tvContent?.text = spannable
}
}
tvButtonContent?.text = Html.fromHtml(agreementBottom)
tvLastContent?.text = Html.fromHtml(agreementLast)
}
private fun showAuthorizationError() {
clLoadAuthorizeContainer?.visibility = View.GONE
clErrorContainer?.visibility = View.VISIBLE
}
private fun voiceAuthorizeError() {
VoiceUtil.speak(AbsMogoApplication.getApp().applicationContext.getString(R.string.module_authorize_failed), AbsMogoApplication.getApp().applicationContext, this)
Logger.d(TAG, "onDestroy")
VoiceUtil.unregisterAll(AbsMogoApplication.getApp().applicationContext, this)
}
override fun onClick(v: View) {
when (v.id) {
R.id.btnAuthorizeAgree -> {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 1, "operation_result" to 1))
agreeAuthorize()
}
R.id.btnAuthorizeDisAgree -> {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 1, "operation_result" to 2))
disAgreeAuthorize()
}
R.id.clLoadingErrorContainer, R.id.btnAuthorizeLoadingError -> {
invokeAuthorizationContent()
}
R.id.clAuthorizeTopParent-> {
Logger.i(TAG,"dismiss authorizeView")
authorizeController?.onDestroy()
}
}
}
override fun onVoiceCmdAgree() {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 2, "operation_result" to 1))
agreeAuthorize()
}
override fun onVoiceCmdDisAgree() {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 2, "operation_result" to 2))
disAgreeAuthorize()
}
private fun agreeAuthorize() {
authorizeController?.agreeAuthorize(invokeTag, agreementId) {
voiceAuthorizeError()
}
}
private fun disAgreeAuthorize() {
authorizeController?.disAgreeAuthorize(invokeTag, agreementId) {
voiceAuthorizeError()
}
}
private fun invokeAuthorizationContent() {
authorizeController?.invokeAuthorizationContent(invokeTag, {
readyToAuthorize()
}, { id: Long, content: String, title: String, bottomContent: String, lastContent: String ->
showAuthorizationAgreementContent(id, content, title, bottomContent, lastContent)
}, {
showAuthorizationError()
})
}
}

View File

@@ -21,7 +21,7 @@ data class AgreementStatus(val agreementStatus:Int)
data class AgreementData(val agreement: Agreement)
data class Agreement(var tUserAgreementEntity: TUserAgreementEntity, var agreementContent: List<String>)
data class Agreement(var tUserAgreementEntity: TUserAgreementEntity, var agreementContent: List<String>?)
data class TUserAgreementEntity(
val id: Long, //协议ID

View File

@@ -62,7 +62,7 @@ class Request<T> {
}
} catch (e: Exception) {
e.printStackTrace()
if (e == null) {
if (e.message == null) {
onError?.invoke(NULL_EXCEPTION)
return@launch
}

View File

@@ -4,6 +4,7 @@ import java.util.*
object DateUtil {
@Suppress("DEPRECATION")
fun parseDateToTime(tmpDate: String): Long {
val time = Date(tmpDate)
return time.time

View File

@@ -0,0 +1,20 @@
package com.mogo.module.authorize.util
import android.os.Build
import android.text.Html
import android.text.Spanned
class HtmlUtil {
companion object{
fun getSpanned(content: String): Spanned {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY)
} else {
@Suppress("DEPRECATION")
Html.fromHtml(content)
}
}
}
}

View File

@@ -1,53 +0,0 @@
package com.mogo.module.authorize.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.widget.TextView
class AutoSplitTextView : TextView {
private var textShowWidth: Float = 0f
private var paint: Paint? = null
constructor(context: Context?) : super(context, null)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
init()
}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
private fun init() {
paint = Paint()
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
textShowWidth = (this.measuredWidth - paddingLeft - paddingRight).toFloat()
var lineCount = 0
if (text.toString().isNullOrBlank()) return
val textCharArray = text.toString().toCharArray()
var drawWidth = 0f
var charWidth: Float
for (i in 0..textCharArray.size) {
charWidth = paint!!.measureText(textCharArray, i, 1)
if (textCharArray[i] == '\n') {
lineCount++
drawWidth = 0f
continue
}
if (textShowWidth - drawWidth < charWidth) {
lineCount++
drawWidth = 0f
}
canvas.drawText(textCharArray, i, 1, paddingLeft + drawWidth, (lineCount + 1) * textSize, paint)
drawWidth += charWidth
}
height = (lineCount + 1) * textSize as Int
}
}

View File

@@ -11,7 +11,7 @@ interface IVoiceAuthorizeIntentListener : IMogoIntentListener, IVoiceBusinessLis
override fun onIntentReceived(cmd: String?, intent: Intent?) {
Logger.i(IVoiceIntentTAG, "cmd -> $cmd")
if (intent != null && cmd != null) {
VoiceManager.handleOnIntentCmd(cmd, intent, this)
VoiceManager.handleOnIntentCmd(cmd,this)
}
}

View File

@@ -25,7 +25,7 @@ object VoiceManager {
}
}
fun handleOnIntentCmd(cmd: String, intent: Intent, listener: IVoiceAuthorizeIntentListener) {
fun handleOnIntentCmd(cmd: String, listener: IVoiceAuthorizeIntentListener) {
Logger.i(TAG, "handleOnIntentCmd: cmd -> $cmd")
when (cmd) {
VOICE_INTENT_AGREE -> {