finish the authorize logic

This commit is contained in:
unknown
2020-03-27 15:54:21 +08:00
parent d8351af5c5
commit 10a77cf8bb
39 changed files with 451 additions and 130 deletions

View File

@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mogo.launcher">
<!-- android:sharedUserId="android.uid.system">-->
package="com.mogo.launcher"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name=".MogoApplication"
android:allowBackup="true"
@@ -22,4 +20,6 @@
android:value="a36b9f7b086fa3951bb35338a5a06dd3" />
</application>
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

View File

@@ -1,6 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: "config.gradle"
apply from: "javadoc.gradle"
buildscript {
ext.kotlin_version = '1.3.41'
@@ -23,6 +24,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.alibaba:arouter-register:1.0.2"
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

View File

@@ -133,5 +133,6 @@ ext {
coroutinescore : "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1",
coroutinesandroid : "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1",
aspectj : "org.aspectj:aspectjrt:1.8.9",
]
}

View File

@@ -0,0 +1,4 @@
package com.mogo.module.authorize.aspectj
class VoiceForbiddenTrackPoint {
}

View File

@@ -3,14 +3,14 @@ package com.mogo.module.authorize.authprovider.biz
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener
import com.mogo.module.authorize.model.BaseResponse
import com.mogo.module.authorize.model.IMogoAuthorizeModel
import com.mogo.module.authorize.model.bean.UserAgreement
import com.mogo.module.authorize.model.bean.AgreementData
import com.mogo.module.authorize.net.request
import com.mogo.utils.logger.Logger
open class IMogoAuthorizeController {
companion object {
const val TAG = "IMogoAuthorizeController"
const val TAG = "AuthorizeController"
}
private val authorizeModel: IMogoAuthorizeModel by lazy { IMogoAuthorizeModel() }
@@ -24,15 +24,14 @@ open class IMogoAuthorizeController {
})
}
try {
request<BaseResponse<UserAgreement>> {
request<BaseResponse<AgreementData>> {
loader {
authorizeModel.invokeAuthorizeContent(1)
authorizeModel.invokeAuthorizeContent(agreementType)
}
onSuccess {
Logger.d(TAG, "invokeAuthorizeContent onSuccess data: ${it.result}")
getAuthorizeContentListener(tag, { listener ->
if (it.result != null) {
listener.requestContentSuccess(it.result)
if (it.result != null && it.result.agreement.agreementContent != null) {
listener.requestContentSuccess(it.result.agreement)
} else {
listener.requestContentFailed("request authorize content success ,but result data is :${it.result}")
}
@@ -49,7 +48,7 @@ open class IMogoAuthorizeController {
})
}
}
}catch (e:Exception){
} catch (e: Exception) {
e.printStackTrace()
}
}

View File

@@ -1,13 +1,13 @@
package com.mogo.module.authorize.authprovider.invoke
import com.mogo.module.authorize.model.bean.UserAgreement
import com.mogo.module.authorize.model.bean.Agreement
/**
* 获取授权信息回调
*/
interface IMogoAuthorizeContentListener {
fun requestContentSuccess(userAgreement: UserAgreement)
fun requestContentSuccess(userAgreement: Agreement)
fun requestContentFailed(errorMsg: String)
}

View File

@@ -9,11 +9,16 @@ interface IAuthorizeMainInvoke : IMogoAuthorizeInvoke {
* 同意授权
* tag:透传模块ID
*/
fun agreeAuthorize(tag: String, agrId: Long)
fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit))
/**
* 不同意授权
* tag:透传模块ID
*/
fun disAgreeAuthorize(tag: String, agrId: Long)
fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit))
/**
* 是否已经注册回调
*/
fun hasRegister(tag: String): Boolean
}

View File

@@ -9,6 +9,10 @@ import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListen
@Route(path = AuthorizeConstant.PROVIDER_LAUNCHER)
class IMogoAuthorizeMainManager : IMogoAuthorizeMainProvider {
override fun hasRegister(tag: String): Boolean {
return mogoAuthShow.hasRegister(tag)
}
override fun needAuthorize(): Boolean {
return mogoAuthShow.needAuthorize()
}
@@ -17,12 +21,12 @@ class IMogoAuthorizeMainManager : IMogoAuthorizeMainProvider {
mogoAuthShow.invokeAuthorizeContent(tag)
}
override fun agreeAuthorize(tag: String, agrId: Long) {
mogoAuthShow.agreeAuthorize(tag, agrId)
override fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {
mogoAuthShow.agreeAuthorize(tag, agrId, onSuccess, onError)
}
override fun disAgreeAuthorize(tag: String, agrId: Long) {
mogoAuthShow.disAgreeAuthorize(tag, agrId)
override fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {
mogoAuthShow.disAgreeAuthorize(tag, agrId, onSuccess, onError)
}
override fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) {

View File

@@ -13,25 +13,31 @@ object MogoAuthorizeMainController : IMogoAuthorizeController() {
private val authorizeShowModel: MogoAuthorizeMainModel by lazy { MogoAuthorizeMainModel() }
@Synchronized
fun agreeAuthorize(tag: String, agrId: Long) {
fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {
val acquireAuthListener = MogoAuthorizeRegisterHandler.getAuthorizeListener(tag)
updateAuthorize(agrId, AGREEMENT_EFFECT, {
if (acquireAuthListener != null) {
onSuccess.invoke()
acquireAuthListener.authorizeSuccess()
} else {
Logger.d(TAG, "agreeAuthorize --- can not find listener by this tag :$tag ")
}
}, {
authorizeFailed(tag, it ?: "agreeAuthorize failed,please check network")
val errorMsg = it ?: "agreeAuthorize failed,please check network"
onError.invoke(errorMsg)
authorizeFailed(tag, errorMsg)
})
}
@Synchronized
fun disAgreeAuthorize(tag: String, agrId: Long) {
fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {
updateAuthorize(agrId, AGREEMENT_NOT_EFFECT, {
onSuccess.invoke()
authorizeFailed(tag, "UserDisAgree authorize")
}, {
authorizeFailed(tag, it ?: "disAgreeAuthorize failed,please check network")
val errorMsg = it ?: "disAgreeAuthorize failed,please check network"
onError.invoke(errorMsg)
authorizeFailed(tag, errorMsg)
})
}

View File

@@ -26,12 +26,18 @@ class MogoMainAuthorize private constructor() : MogoAuthorizeManagerImpl(), IMog
@Volatile
private var showAuthorizeView: Boolean = false
override fun agreeAuthorize(tag: String, agrId: Long) {
MogoAuthorizeMainController.agreeAuthorize(tag, agrId)
override fun hasRegister(tag: String): Boolean {
if (tag.isNullOrBlank()) return false
val listener = MogoAuthorizeRegisterHandler.getAuthorizeContentListener(tag)
return listener != null
}
override fun disAgreeAuthorize(tag: String, agrId: Long) {
MogoAuthorizeMainController.disAgreeAuthorize(tag, agrId)
override fun agreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {
MogoAuthorizeMainController.agreeAuthorize(tag, agrId, onSuccess, onError)
}
override fun disAgreeAuthorize(tag: String, agrId: Long, onSuccess: (() -> Unit), onError: ((String) -> Unit)) {
MogoAuthorizeMainController.disAgreeAuthorize(tag, agrId, onSuccess, onError)
}
fun invokeAuthorizeForShow() {

View File

@@ -19,6 +19,7 @@ class MogoModuleAuthorize private constructor() : MogoAuthorizeManagerImpl(), IM
override fun invokeAuthorization(tag: String) {
mogoAuthShow.showAuthorizeView(tag, {
//todo SP存储状态
}, { errorMsg ->
val listener = MogoAuthorizeRegisterHandler.getAuthorizeListener(tag)
listener?.authorizeFailed(errorMsg)

View File

@@ -13,10 +13,11 @@ class AuthorizeContract {
}
interface Biz {
fun invokeAuthorize(invokeTag: String)
fun invokeAuthorizationContent(invokeTag: String)
fun agreeAuthorize(tag: String, agreementId: Long)
fun disAgreeAuthorize(tag: String, agreementId: Long)
}
}

View File

@@ -4,10 +4,16 @@ import android.text.Html
import android.view.View
import com.mogo.commons.mvp.MvpFragment
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.IVoiceCommandListener
import com.mogo.module.authorize.voice.IVoiceIntentListener
import com.mogo.module.authorize.voice.VoiceUtil
import com.mogo.utils.logger.Logger
import kotlinx.android.synthetic.main.module_authorize_fragment.*
class AuthorizeFragment(private val invokeTag: String) : MvpFragment<AuthorizeContract.View, AuthorizePresenter>(), AuthorizeContract.View, View.OnClickListener {
class AuthorizeFragment(private val invokeTag: String) : MvpFragment<AuthorizeContract.View, AuthorizePresenter>(), AuthorizeContract.View, View.OnClickListener, IVoiceCommandListener, IVoiceIntentListener {
companion object {
const val TAG = "AuthorizeFragment"
@@ -20,11 +26,13 @@ class AuthorizeFragment(private val invokeTag: String) : MvpFragment<AuthorizeCo
}
override fun initViews() {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_SHOW)
btnAuthorizeAgree.setOnClickListener(this)
btnAuthorizeDisAgree.setOnClickListener(this)
btnAuthorizeLoadingError.setOnClickListener(this)
clLoadingErrorContainer.setOnClickListener(this)
Logger.d(TAG, "invokeTag :$invokeTag")
VoiceUtil.registerAll(context!!, this, this)
}
override fun createPresenter(): AuthorizePresenter {
@@ -42,6 +50,7 @@ class AuthorizeFragment(private val invokeTag: String) : MvpFragment<AuthorizeCo
agreementTitle: String,
agreementBottom: String,
agreementLast: String) {
VoiceUtil.speak(context!!.resources.getString(R.string.module_authorize_agreement_tip), context!!, this)
clLoadingContainer.visibility = View.GONE
clAuthorizeContainer.visibility = View.VISIBLE
this.agreementId = agreementId
@@ -59,16 +68,32 @@ class AuthorizeFragment(private val invokeTag: String) : MvpFragment<AuthorizeCo
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))
mPresenter.agreeAuthorize(invokeTag, agreementId)
}
R.id.btnAuthorizeDisAgree -> {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 1, "operation_result" to 2))
mPresenter.disAgreeAuthorize(invokeTag, agreementId)
}
R.id.clLoadingErrorContainer, R.id.btnAuthorizeLoadingError -> {
mPresenter.invokeAuthorize(invokeTag)
mPresenter.invokeAuthorizationContent(invokeTag)
}
}
}
override fun onVoiceCmdAgree() {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 2, "operation_result" to 1))
mPresenter.agreeAuthorize(invokeTag, agreementId)
}
override fun onVoiceCmdDisAgree() {
AnalyticsUtil.track(INVOKE_TRACK_AUTHORIZE_CLICK, hashMapOf("operation_type" to 2, "operation_result" to 2))
mPresenter.disAgreeAuthorize(invokeTag, agreementId)
}
override fun onDestroy() {
super.onDestroy()
VoiceUtil.unregisterAll(context!!, this)
}
}

View File

@@ -4,12 +4,10 @@ import androidx.lifecycle.LifecycleOwner
import com.mogo.commons.mvp.Presenter
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener
import com.mogo.module.authorize.authprovider.launcher.MogoMainAuthorize.Companion.mogoAuthShow
import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener
import com.mogo.module.authorize.model.bean.UserAgreement
import com.mogo.module.authorize.model.proxy.AuthorizeProxy
import com.mogo.module.authorize.model.bean.Agreement
import com.mogo.utils.logger.Logger
class AuthorizePresenter : Presenter<AuthorizeContract.View>, AuthorizeContract.Biz, IMogoAuthorizeContentListener, IMogoAcquireAuthorizeListener {
class AuthorizePresenter : Presenter<AuthorizeContract.View>, AuthorizeContract.Biz, IMogoAuthorizeContentListener {
companion object {
const val TAG = "AuthorizePresenter"
@@ -24,51 +22,54 @@ class AuthorizePresenter : Presenter<AuthorizeContract.View>, AuthorizeContract.
override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)
Logger.d(TAG, "onCreate invokeTag:$invokeTag")
invokeAuthorize(invokeTag!!)
invokeAuthorizationContent(invokeTag!!)
}
override fun invokeAuthorize(invokeTag: String) {
override fun invokeAuthorizationContent(invokeTag: String) {
mView.readyToAuthorize()
this.invokeTag = invokeTag
mogoAuthShow.registerInvokeAuthorizeContentListener(invokeTag, this)
mogoAuthShow.registerAuthorizeListener(invokeTag, this)
if (!mogoAuthShow.hasRegister(invokeTag)) {
mogoAuthShow.registerInvokeAuthorizeContentListener(invokeTag, this)
}
mogoAuthShow.invokeAuthorizeContent(invokeTag)
}
override fun requestContentSuccess(userAgreement: UserAgreement) {
val id = userAgreement.agreementEntity.id
val content = userAgreement.agreementContent[0]
val title = userAgreement.agreementEntity.title
val bottomContent = userAgreement.agreementEntity.agreementButtonFirst
val lastContent = userAgreement.agreementEntity.agreementButtonSecond
mView.showAuthorizationAgreementContent(id, content, title, bottomContent, lastContent)
override fun requestContentSuccess(userAgreement: Agreement) {
Logger.d(TAG, "requestContentSuccess userAgreement:$userAgreement")
if (userAgreement?.agreementContent != null && userAgreement?.agreementContent.isNotEmpty()) {
val id = userAgreement.tUserAgreementEntity.id
val content = userAgreement.agreementContent[0]
val title = userAgreement.tUserAgreementEntity.title
val bottomContent = userAgreement.tUserAgreementEntity.agreementButtonFirst
val lastContent = userAgreement.tUserAgreementEntity.agreementButtonSecond
mView.showAuthorizationAgreementContent(id, content, title, bottomContent, lastContent)
} else {
mView.showAuthorizationError()
}
}
override fun requestContentFailed(errorMsg: String) {
Logger.d(TAG, "requestContentFailed errorMsg:$errorMsg")
// mView.showAuthorizationAgreementContent(0, "123", "123456", "34234", "3543535")
mView.showAuthorizationError()
}
override fun agreeAuthorize(tag: String, agreementId: Long) {
mogoAuthShow.agreeAuthorize(tag, agreementId)
mogoAuthShow.agreeAuthorize(tag, agreementId, {
Logger.d(TAG, "agreeAuthorize success")
closeAuthorizeView()
}, { s: String ->
Logger.d(TAG, "agreeAuthorize failed")
closeAuthorizeView()
})
}
override fun disAgreeAuthorize(tag: String, agreementId: Long) {
mogoAuthShow.disAgreeAuthorize(tag, agreementId)
}
override fun authorizeSuccess() {
mogoAuthShow.authorizeSuccess(invokeTag!!)
closeAuthorizeView()
}
override fun authorizeFailed(errorMsg: String) {
mogoAuthShow.authorizeFailed(invokeTag!!, errorMsg)
closeAuthorizeView()
}
override fun forbiddenVoiceWhenAuthorize(cmd: String) {
//do nothing
mogoAuthShow.disAgreeAuthorize(tag, agreementId, {
closeAuthorizeView()
}, { s: String ->
closeAuthorizeView()
})
}
private fun closeAuthorizeView() {

View File

@@ -1,6 +1,6 @@
package com.mogo.module.authorize.model
class BaseResponse<out T>(val code: Int, val msg: String, val result: T) {
class BaseResponse<out T>(val code: Int, val msg: String, val detailMsg: String, val result: T) {
}

View File

@@ -3,7 +3,8 @@ package com.mogo.module.authorize.model
import com.google.gson.Gson
import com.mogo.commons.network.Utils.getSn
import com.mogo.module.authorize.model.bean.RequestUserAgreement
import com.mogo.module.authorize.model.bean.UserAgreement
import com.mogo.module.authorize.model.bean.Agreement
import com.mogo.module.authorize.model.bean.AgreementData
open class IMogoAuthorizeModel : BaseRepository() {
@@ -11,7 +12,7 @@ open class IMogoAuthorizeModel : BaseRepository() {
const val TAG = "IMogoAuthorizeModel"
}
suspend fun invokeAuthorizeContent(agreementType: Int): BaseResponse<UserAgreement> {
suspend fun invokeAuthorizeContent(agreementType: Int): BaseResponse<AgreementData> {
val requestUserAgreement = Gson().toJson(RequestUserAgreement(agreementType))
val map = mapOf("sn" to getSn(), "data" to requestUserAgreement)
return apiCall { getNetWorkApi().getAuthorizeContent(map) }

View File

@@ -3,9 +3,11 @@ package com.mogo.module.authorize.model.bean
const val AGREEMENT_EFFECT = 1 //用户协议生效
const val AGREEMENT_NOT_EFFECT = 2 //用户协议不生效
class RequestUserAgreement(val agreementType:Int)
class RequestUserAgreement(val agreementType: Int)
data class UserAgreement(var agreementEntity: TUserAgreementEntity, var agreementContent: List<String>)
data class AgreementData(val agreement: Agreement)
data class Agreement(var tUserAgreementEntity: TUserAgreementEntity, var agreementContent: List<String>)
data class TUserAgreementEntity(
val id: Long, //协议ID
@@ -18,4 +20,4 @@ data class TUserAgreementEntity(
val agreementUserType: String, //协议适用用户
val agreementStatus: Int, //协议状态 1生效 2未生效
val createTime: String, //协议创建时间
val updateTime: String) //协议更新时间
val updateTime: String) //协议更新时间

View File

@@ -1,7 +1,8 @@
package com.mogo.module.authorize.net
import com.mogo.module.authorize.model.BaseResponse
import com.mogo.module.authorize.model.bean.UserAgreement
import com.mogo.module.authorize.model.bean.Agreement
import com.mogo.module.authorize.model.bean.AgreementData
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
@@ -10,12 +11,12 @@ interface AuthorizeApi {
//获取授权内容·
@FormUrlEncoded
@POST("yycp-channelManager/user/agreement/findUserAgreement")
suspend fun getAuthorizeContent(@FieldMap authorizeContent: Map<String, String>): BaseResponse<UserAgreement>
@POST("yycp-channelManager/agreement/findUserAgreement")
suspend fun getAuthorizeContent(@FieldMap authorizeContent: Map<String, String>): BaseResponse<AgreementData>
//更新授权状态
@FormUrlEncoded
@POST("yycp-channelManager/user/agreement/updateStatus")
@POST("yycp-channelManager/agreement/updateStatus")
suspend fun updateAuthorize(@FieldMap updateStatus: Map<String, String>): BaseResponse<Any>
}

View File

@@ -5,7 +5,6 @@ import com.mogo.module.authorize.exception.ApiException.Companion.NULL_REQUEST_D
import com.mogo.module.authorize.exception.CommonException.Companion.NETWORK_EXCEPTION
import com.mogo.module.authorize.exception.CommonException.Companion.NULL_EXCEPTION
import com.mogo.module.authorize.model.BaseResponse
import com.mogo.utils.logger.Logger
import kotlinx.coroutines.*
import java.net.SocketTimeoutException
import java.net.UnknownHostException
@@ -63,7 +62,7 @@ class Request<T> {
}
} catch (e: Exception) {
e.printStackTrace()
if(e == null){
if (e == null) {
onError?.invoke(NULL_EXCEPTION)
return@launch
}
@@ -71,7 +70,7 @@ class Request<T> {
is UnknownHostException -> onError?.invoke(NETWORK_EXCEPTION)
is TimeoutException -> onError?.invoke(NETWORK_EXCEPTION)
is SocketTimeoutException -> onError?.invoke(NETWORK_EXCEPTION)
else -> onError?.invoke(java.lang.Exception(e.message?:""))
else -> onError?.invoke(java.lang.Exception(e.message ?: ""))
}
} finally {
onComplete?.invoke()

View File

@@ -0,0 +1,24 @@
package com.mogo.module.authorize.util
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.service.analytics.IMogoAnalytics
object AnalyticsUtil {
const val INVOKE_TRACK_AUTHORIZE_SHOW = "Launcher_Privacy_protocol_Show"
const val INVOKE_TRACK_AUTHORIZE_CLICK = "Launcher_Privacy_protocol_click"
private var trackRouter: IMogoAnalytics? = null
fun track(eventType: String, data: MutableMap<String, Any>? = hashMapOf()) {
if (trackRouter == null) {
val arouter = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation()
if (arouter is IMogoServiceApis) {
trackRouter = arouter.analyticsApi
}
}
trackRouter!!.track(eventType, data)
}
}

View File

@@ -0,0 +1,8 @@
package com.mogo.module.authorize.voice
interface IVoiceBusinessListener {
fun onVoiceCmdAgree()
fun onVoiceCmdDisAgree()
}

View File

@@ -0,0 +1,35 @@
package com.mogo.module.authorize.voice
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
import com.mogo.utils.logger.Logger
private const val IVoiceCommandTAG = "IVoiceCommandTAG"
interface IVoiceCommandListener : IMogoVoiceCmdCallBack, IVoiceBusinessListener {
override fun onCmdSelected(cmd: String?) {
Logger.i(
IVoiceCommandTAG, "onCmdSelected cmd:${cmd ?: "cmd is null"}"
)
cmd?.let {
VoiceManager.handleOnCmdSelected(cmd, this)
}
}
override fun onCmdAction(speakText: String?) {
}
override fun onCmdCancel(speakText: String?) {
}
override fun onSpeakSelectTimeOut(speakText: String?) {
}
override fun onSpeakEnd(speakText: String?) {
Logger.i(IVoiceCommandTAG, "onSpeakEnd --- speakText : $speakText")
}
}

View File

@@ -0,0 +1,18 @@
package com.mogo.module.authorize.voice
import android.content.Intent
import com.mogo.service.intent.IMogoIntentListener
import com.mogo.utils.logger.Logger
private const val IVoiceIntentTAG = "IVoiceIntentListener"
interface IVoiceIntentListener : IMogoIntentListener, IVoiceBusinessListener {
override fun onIntentReceived(cmd: String?, intent: Intent?) {
Logger.i(IVoiceIntentTAG, "cmd -> $cmd")
if (intent != null && cmd != null) {
VoiceManager.handleOnIntentCmd(cmd, intent, this)
}
}
}

View File

@@ -0,0 +1,40 @@
package com.mogo.module.authorize.voice
import android.content.Intent
import com.mogo.module.authorize.voice.VoiceUtil.VOICE_REGISTER_AUTHORIZE_AGREE
import com.mogo.module.authorize.voice.VoiceUtil.VOICE_REGISTER_AUTHORIZE_DISAGREE
import com.mogo.utils.logger.Logger
object VoiceManager {
private const val TAG = "VoiceManager"
fun handleOnCmdSelected(cmd: String, listener: IVoiceCommandListener) {
Logger.i(TAG, "handleOnCmdSelected: cmd ---> $cmd")
when (cmd) {
VOICE_REGISTER_AUTHORIZE_AGREE -> {
Logger.i(TAG, "语音免唤醒 同意")
listener.onVoiceCmdAgree()
}
VOICE_REGISTER_AUTHORIZE_DISAGREE -> {
Logger.i(TAG, "语音免唤醒 不同意")
listener.onVoiceCmdDisAgree()
}
}
}
fun handleOnIntentCmd(cmd: String, intent: Intent, listener: IVoiceIntentListener) {
Logger.i(TAG, "handleOnIntentCmd: cmd -> $cmd")
when (cmd) {
VOICE_REGISTER_AUTHORIZE_AGREE -> {
Logger.i(TAG, "语音唤醒 同意")
listener.onVoiceCmdAgree()
}
VOICE_REGISTER_AUTHORIZE_DISAGREE -> {
Logger.i(TAG, "语音免唤醒 不同意")
listener.onVoiceCmdDisAgree()
}
}
}
}

View File

@@ -0,0 +1,93 @@
package com.mogo.module.authorize.voice
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.commons.voice.AIAssist
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.service.intent.IMogoIntentManager
import com.mogo.utils.logger.Logger
object VoiceUtil {
private const val TAG = "VoiceUtil"
private var intentRegister: IMogoIntentManager? = null
init {
Logger.i(TAG, "init")
val register =
ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation()
if (register is IMogoServiceApis) {
intentRegister = register.intentManagerApi
}
}
//WakeUp Command (Intent)
const val VOICE_INTENT_AGREE = "system.application.operation" //同意
const val VOICE_INTENT_DISAGREE = "system.application.operation" //不同意
//unWakeUp Command
const val VOICE_REGISTER_AUTHORIZE_AGREE = "CMD_AUTHORIZATION_AGREE"
private val agreeArray: Array<String> = arrayOf("同意", "调整", "好的")
const val VOICE_REGISTER_AUTHORIZE_DISAGREE = "CMD_AUTHORIZATION_DISAGREE"
private val disAgreeArray: Array<String> = arrayOf("不同意", "不调整")
private var hasRegister = false
fun speak(content: String, context: Context, listener: IVoiceCommandListener) {
AIAssist.getInstance(context).speakTTSVoice(content, listener)
}
fun registerAll(
context: Context,
voiceCommand: IVoiceCommandListener,
intentCommand: IVoiceIntentListener
) {
if (!hasRegister) {
hasRegister = true
registerAgree(context, voiceCommand, intentCommand)
registerDisAgree(context, voiceCommand, intentCommand)
}
}
private fun registerAgree(
context: Context,
voiceCommand: IVoiceCommandListener,
intentCommand: IVoiceIntentListener
) {
Logger.i(TAG, "registerAgree")
AIAssist.getInstance(context)
.registerUnWakeupCommand(
VOICE_REGISTER_AUTHORIZE_AGREE,
agreeArray, voiceCommand
)
// intentRegister?.registerIntentListener(VOICE_INTENT_AGREE, intentCommand)
}
private fun registerDisAgree(
context: Context,
voiceCommand: IVoiceCommandListener,
intentCommand: IVoiceIntentListener
) {
Logger.i(TAG, "registerDisAgree")
AIAssist.getInstance(context)
.registerUnWakeupCommand(
VOICE_REGISTER_AUTHORIZE_DISAGREE,
disAgreeArray, voiceCommand
)
// intentRegister?.registerIntentListener(VOICE_INTENT_DISAGREE, intentCommand)
}
fun unregisterAll(context: Context, listener: IVoiceIntentListener) {
Logger.i(TAG, "unregister All")
AIAssist.getInstance(context).unregisterUnWakeupCommand(VOICE_REGISTER_AUTHORIZE_AGREE)
AIAssist.getInstance(context).unregisterUnWakeupCommand(VOICE_REGISTER_AUTHORIZE_DISAGREE)
hasRegister = false
Logger.i(TAG, "unregister IntentVoiceCommand --- intentRegister:$intentRegister")
intentRegister?.let {
it.unregisterIntentListener(VOICE_INTENT_AGREE, listener)
it.unregisterIntentListener(VOICE_INTENT_DISAGREE, listener)
}
}
}

View File

@@ -50,11 +50,25 @@
android:layout_marginRight="@dimen/dp_330"
android:layout_marginBottom="@dimen/dp_90"
android:background="@drawable/module_authorize_selector_dark_corner"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/btnAuthorizeLoadingError"
android:layout_width="@dimen/dp_461"
android:layout_height="@dimen/dp_97"
android:layout_marginTop="@dimen/dp_33"
android:background="@drawable/module_authorize_selector_blue_corner"
android:gravity="center"
android:text="@string/module_authorize_agreement_retry"
android:textColor="@android:color/white"
android:textSize="@dimen/dp_44"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvAuthorizeLoadingError" />
<ImageView
android:id="@+id/ivAuthorizeLoadingError"
android:layout_width="@dimen/dp_147"
@@ -76,20 +90,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ivAuthorizeLoadingError" />
<Button
android:id="@+id/btnAuthorizeLoadingError"
android:layout_width="@dimen/dp_461"
android:layout_height="@dimen/dp_97"
android:layout_marginTop="@dimen/dp_33"
android:text="@string/module_authorize_agreement_retry"
android:textColor="@android:color/white"
android:gravity="center"
android:background="@drawable/module_authorize_selector_blue_corner"
android:textSize="@dimen/dp_44"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvAuthorizeLoadingError" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
@@ -101,7 +101,7 @@
android:layout_marginRight="@dimen/dp_330"
android:layout_marginBottom="@dimen/dp_90"
android:background="@drawable/module_authorize_shape_drak_top_corner"
android:visibility="gone"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@@ -144,6 +144,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dp_55"
android:layout_marginRight="@dimen/dp_55"
android:orientation="vertical">
<TextView

View File

@@ -5,4 +5,5 @@
<string name="module_authorize_agreement_loading">正在加载,请稍等...</string>
<string name="module_authorize_agreement_error">加载失败</string>
<string name="module_authorize_agreement_retry">点击重试</string>
<string name="module_authorize_agreement_tip">您还没有授权,不可分享,您可以说“同意”进行授权。</string>
</resources>

View File

@@ -1,24 +1,2 @@
package com.mogo.module.guide.agreement
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mogo.module.guide.agreement.test", appContext.packageName)
}
}

View File

@@ -1,8 +1,11 @@
package com.mogo.module.guide
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant
import com.mogo.module.authorize.authprovider.module.IMogoAuthorizeModuleManager
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.SharedPreferenceUtil.hasGuide
import com.mogo.module.guide.util.SharedPreferenceUtil.setGuideFinish
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.service.fragmentmanager.FragmentDescriptor
@@ -15,7 +18,7 @@ object GuideBizManager {
fun init() {
Logger.d("GuideBizManager", "init===================================")
initService()
// addGuideFragmentToStack()
addGuideFragmentToStack()
}
private fun initService() {
@@ -35,8 +38,19 @@ object GuideBizManager {
}
fun removeGuideFragmentToStack() {
Logger.d("GuideBizManager", "removeGuideFragmentToStack")
setGuideFinish()
serviceApi?.let {
it.fragmentManagerApi.pop()
}
}
fun invokeAuthorize() {
val authorizeInvoke = ARouter.getInstance().build(AuthorizeConstant.PROVIDER_MODULE).navigation()
if (authorizeInvoke is IMogoAuthorizeModuleManager) {
if (authorizeInvoke.needAuthorize()) {
authorizeInvoke.invokeAuthorizeForShow()
}
}
}
}

View File

@@ -1,9 +1,6 @@
package com.mogo.module.guide.fragment
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.commons.mvp.MvpFragment
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant
import com.mogo.module.authorize.authprovider.module.IMogoAuthorizeModuleManager
import com.mogo.module.guide.GuideBizManager
import com.mogo.module.guide.R
import com.mogo.utils.logger.Logger
@@ -44,17 +41,15 @@ class GuideFragment : MvpFragment<GuideConstract.View, GuidePresenter>(), GuideC
fun closeGuideFragment() {
Logger.d(TAG, "closeGuideFragment")
val authorizeInvoke = ARouter.getInstance().build(AuthorizeConstant.PROVIDER_MODULE).navigation()
if (authorizeInvoke is IMogoAuthorizeModuleManager) {
if (authorizeInvoke.needAuthorize()) {
authorizeInvoke.invokeAuthorizeForShow()
} else {
destroy()
}
}
destroy()
invokeAuthorize()
}
private fun destroy() {
GuideBizManager.removeGuideFragmentToStack()
}
private fun invokeAuthorize() {
GuideBizManager.invokeAuthorize()
}
}

View File

@@ -6,6 +6,7 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.AnalyticsUtil
import kotlinx.android.synthetic.main.module_guide_item_app_list.*
class GuideAppListFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickListener {
@@ -25,6 +26,7 @@ class GuideAppListFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickL
}
override fun initViews() {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 6))
moduleGuideAppListNext.setOnClickListener(this)
moduleGuideAppListSkip.setOnClickListener(this)
}
@@ -32,9 +34,11 @@ class GuideAppListFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickL
override fun onClick(v: View) {
when (v.id) {
R.id.moduleGuideAppListNext -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 6, "button_type" to 1))
containerFragment?.moveToNext()
}
R.id.moduleGuideAppListSkip -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 6, "button_type" to 2))
containerFragment?.moveToLast()
}
}

View File

@@ -6,13 +6,16 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.AnalyticsUtil
import com.mogo.module.guide.util.AnalyticsUtil.INVOKE_TRACK_CLICK
import com.mogo.module.guide.util.AnalyticsUtil.INVOKE_TRACK_SHOW
import kotlinx.android.synthetic.main.module_guide_item_card.*
class GuideCardFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickListener {
private var containerFragment:GuideFragment? = null
private var containerFragment: GuideFragment? = null
constructor(containerFragment:GuideFragment){
constructor(containerFragment: GuideFragment) {
this.containerFragment = containerFragment
}
@@ -25,6 +28,7 @@ class GuideCardFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickList
}
override fun initViews() {
AnalyticsUtil.track(INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 2))
moduleGuideCardNext.setOnClickListener(this)
moduleGuideCardSkip.setOnClickListener(this)
}
@@ -32,9 +36,11 @@ class GuideCardFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickList
override fun onClick(v: View) {
when (v.id) {
R.id.moduleGuideCardNext -> {
AnalyticsUtil.track(INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 2, "button_type" to 1))
containerFragment?.moveToNext()
}
R.id.moduleGuideCardSkip -> {
AnalyticsUtil.track(INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 2, "button_type" to 2))
containerFragment?.moveToLast()
}
}

View File

@@ -6,9 +6,10 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.AnalyticsUtil
import kotlinx.android.synthetic.main.module_guide_item_entry_main.*
class GuideEntryMainFragment : MvpFragment<IView, Presenter<IView>>,View.OnClickListener {
class GuideEntryMainFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickListener {
private var containerFragment: GuideFragment? = null
@@ -25,12 +26,14 @@ class GuideEntryMainFragment : MvpFragment<IView, Presenter<IView>>,View.OnClick
}
override fun initViews() {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 7))
moduleGuideEntryMain.setOnClickListener(this)
}
override fun onClick(v: View) {
when(v.id){
when (v.id) {
R.id.moduleGuideEntryMain -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 7, "button_type" to 3))
containerFragment?.closeGuideFragment()
}
}

View File

@@ -6,6 +6,7 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.AnalyticsUtil
import kotlinx.android.synthetic.main.module_guide_item_location.*
class GuideLocationFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickListener {
@@ -25,6 +26,7 @@ class GuideLocationFragment : MvpFragment<IView, Presenter<IView>>, View.OnClick
}
override fun initViews() {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 5))
moduleGuideLocationNext.setOnClickListener(this)
moduleGuideLocationSkip.setOnClickListener(this)
}
@@ -32,9 +34,11 @@ class GuideLocationFragment : MvpFragment<IView, Presenter<IView>>, View.OnClick
override fun onClick(v: View) {
when (v.id) {
R.id.moduleGuideLocationNext -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 5, "button_type" to 1))
containerFragment?.moveToNext()
}
R.id.moduleGuideLocationSkip -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 5, "button_type" to 2))
containerFragment?.moveToLast()
}
}

View File

@@ -6,6 +6,7 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.AnalyticsUtil
import kotlinx.android.synthetic.main.module_guide_item_navigation.*
class GuideNavigationFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickListener {
@@ -25,6 +26,7 @@ class GuideNavigationFragment : MvpFragment<IView, Presenter<IView>>, View.OnCli
}
override fun initViews() {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 4))
moduleGuideNavigationNext.setOnClickListener(this)
moduleGuideNavigationSkip.setOnClickListener(this)
}
@@ -32,9 +34,11 @@ class GuideNavigationFragment : MvpFragment<IView, Presenter<IView>>, View.OnCli
override fun onClick(v: View) {
when (v.id) {
R.id.moduleGuideNavigationNext -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 4, "button_type" to 1))
containerFragment?.moveToNext()
}
R.id.moduleGuideNavigationSkip -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 4, "button_type" to 2))
containerFragment?.moveToLast()
}
}

View File

@@ -6,6 +6,7 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.fragment.GuideFragment
import com.mogo.module.guide.util.AnalyticsUtil
import kotlinx.android.synthetic.main.module_guide_item_online_car.*
class GuideOnLineCarFragment : MvpFragment<IView, Presenter<IView>>, View.OnClickListener {
@@ -25,6 +26,7 @@ class GuideOnLineCarFragment : MvpFragment<IView, Presenter<IView>>, View.OnClic
}
override fun initViews() {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 3))
moduleGuideOnLineCarNext.setOnClickListener(this)
moduleGuideOnLineCarSkip.setOnClickListener(this)
}
@@ -32,9 +34,11 @@ class GuideOnLineCarFragment : MvpFragment<IView, Presenter<IView>>, View.OnClic
override fun onClick(v: View) {
when (v.id) {
R.id.moduleGuideOnLineCarNext -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 3, "button_type" to 1))
containerFragment?.moveToNext()
}
R.id.moduleGuideOnLineCarSkip -> {
AnalyticsUtil.track(AnalyticsUtil.INVOKE_TRACK_CLICK, hashMapOf("pages_num" to 3, "button_type" to 2))
containerFragment?.moveToLast()
}
}

View File

@@ -4,6 +4,8 @@ import com.mogo.commons.mvp.IView
import com.mogo.commons.mvp.MvpFragment
import com.mogo.commons.mvp.Presenter
import com.mogo.module.guide.R
import com.mogo.module.guide.util.AnalyticsUtil
import com.mogo.module.guide.util.AnalyticsUtil.INVOKE_TRACK_SHOW
class GuideStartFragment : MvpFragment<IView, Presenter<IView>>() {
@@ -16,7 +18,7 @@ class GuideStartFragment : MvpFragment<IView, Presenter<IView>>() {
}
override fun initViews() {
AnalyticsUtil.track(INVOKE_TRACK_SHOW, hashMapOf("pages_num" to 1))
}
class GuideStartPresenter : Presenter<IView> {

View File

@@ -0,0 +1,24 @@
package com.mogo.module.guide.util
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.service.analytics.IMogoAnalytics
object AnalyticsUtil {
const val INVOKE_TRACK_SHOW = "newhand_show"
const val INVOKE_TRACK_CLICK = "newhand_click"
private var trackRouter: IMogoAnalytics? = null
fun track(eventType: String, data: MutableMap<String, Any>? = hashMapOf()) {
if (trackRouter == null) {
val arouter = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation()
if (arouter is IMogoServiceApis) {
trackRouter = arouter.analyticsApi
}
}
trackRouter!!.track(eventType, data)
}
}

View File

@@ -11,4 +11,8 @@ object SharedPreferenceUtil {
return SharedPrefsMgr.getInstance(AbsMogoApplication.getApp()).getBoolean(HAS_GUIDE, false)
}
fun setGuideFinish() {
SharedPrefsMgr.getInstance(AbsMogoApplication.getApp()).putBoolean(HAS_GUIDE, true)
}
}