merge tanlu

This commit is contained in:
lixiaopeng
2021-12-22 19:51:04 +08:00
69 changed files with 512 additions and 1957 deletions

View File

@@ -1,11 +1,39 @@
// 网约车服务:仅小巴车、出租车渠道用
project.dependencies {
f8xxImplementation rootProject.ext.dependencies.mogoochnoop
f80xImplementation rootProject.ext.dependencies.mogoochnoop
f8AmapImplementation rootProject.ext.dependencies.mogoochnoop
fochtaxiImplementation rootProject.ext.dependencies.mogoochtaxi
fochbusImplementation rootProject.ext.dependencies.mogoochbus
f8xxImplementation (rootProject.ext.dependencies.mogoochnoop){
exclude group: 'com.mogo.commons' //by group
exclude group: 'com.mogo.map' //by group
exclude group: 'com.mogo.eagle.core' //by group
exclude group: 'com.mogo.eagle.core.function' //by group
}
f80xImplementation (rootProject.ext.dependencies.mogoochnoop){
exclude group: 'com.mogo.commons' //by group
exclude group: 'com.mogo.module' //by group
exclude group: 'com.mogo.map' //by group
exclude group: 'com.mogo.eagle.core' //by group
exclude group: 'com.mogo.eagle.core.function' //by group
}
f8AmapImplementation (rootProject.ext.dependencies.mogoochnoop){
exclude group: 'com.mogo.commons' //by group
exclude group: 'com.mogo.module' //by group
exclude group: 'com.mogo.map' //by group
exclude group: 'com.mogo.eagle.core' //by group
exclude group: 'com.mogo.eagle.core.function' //by group
}
fochtaxiImplementation (rootProject.ext.dependencies.mogoochtaxi){
exclude group: 'com.mogo.commons' //by group
exclude group: 'com.mogo.module' //by group
exclude group: 'com.mogo.map' //by group
exclude group: 'com.mogo.eagle.core' //by group
exclude group: 'com.mogo.eagle.core.function' //by group
}
fochbusImplementation (rootProject.ext.dependencies.mogoochbus){
exclude group: 'com.mogo.commons' //by group
exclude group: 'com.mogo.module' //by group
exclude group: 'com.mogo.map' //by group
exclude group: 'com.mogo.eagle.core' //by group
exclude group: 'com.mogo.eagle.core.function' //by group
}
fPadLenovoImplementation (rootProject.ext.dependencies.mogoochnoop){
exclude group: 'com.mogo.commons' //by group

View File

@@ -69,7 +69,6 @@ dependencies {
api rootProject.ext.dependencies.mogoservice
api rootProject.ext.dependencies.moduleV2x
api rootProject.ext.dependencies.moduleshare
api rootProject.ext.dependencies.tanluupload
api rootProject.ext.dependencies.mogomonitor
api rootProject.ext.dependencies.moduleextensions
api rootProject.ext.dependencies.modulemap
@@ -103,7 +102,6 @@ dependencies {
api project(':modules:mogo-module-service')
api project(':modules:mogo-module-v2x')
api project(':modules:mogo-module-share')
api project(':modules:tanlulib')
api project(':modules:mogo-module-monitor')
api project(':modules:mogo-module-extensions')
api project(':modules:mogo-module-map')

View File

@@ -38,7 +38,6 @@
:modules:mogo-module-main
:modules:mogo-module-push-base
:modules:mogo-module-push
:modules:tanlulib
:modules:mogo-module-monitor
:core:function-impl:mogo-core-function-autopilot
:core:function-impl:mogo-core-function-hmi

View File

@@ -91,7 +91,6 @@ class MogoMainService extends Service implements IMogoLocationListener {
private void startTanluService() {
UiThreadHandler.postDelayed(() -> {
Logger.d(TAG, "startTanluService ---------- ");
if (mServiceApis != null) {
mServiceApis.getTanluApi().startTanluService();
}

View File

@@ -37,6 +37,10 @@ android {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
@@ -46,7 +50,7 @@ dependencies {
implementation rootProject.ext.dependencies.androidxrecyclerview
implementation rootProject.ext.dependencies.androidxccorektx
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.okhttpinterceptor
implementation rootProject.ext.dependencies.arouter
kapt rootProject.ext.dependencies.aroutercompiler
@@ -54,21 +58,26 @@ dependencies {
implementation rootProject.ext.dependencies.rxandroid
implementation rootProject.ext.dependencies.mogoaicloudtanlu
implementation rootProject.ext.dependencies.analytics
implementation rootProject.ext.dependencies.eventbus
implementation rootProject.ext.dependencies.coroutinescore
implementation rootProject.ext.dependencies.coroutinesandroid
// implementation rootProject.ext.dependencies.retrofit
// implementation rootProject.ext.dependencies.retrofitconvertergson
implementation 'com.zhidaoauto.controller:api:1.0.8'
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
implementation rootProject.ext.dependencies.mogoutils
implementation rootProject.ext.dependencies.mogocommons
implementation rootProject.ext.dependencies.modulecommon
implementation rootProject.ext.dependencies.moduleservice
implementation rootProject.ext.dependencies.mogo_core_utils
implementation rootProject.ext.dependencies.mogo_core_data
} else {
implementation project(":foudations:mogo-utils")
implementation project(":foudations:mogo-commons")
implementation project(':modules:mogo-module-common')
implementation project(':modules:mogo-module-service')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-data')
}

View File

@@ -3,5 +3,10 @@
<application>
<service android:name=".VoiceCmdService" />
<!--获取图片和视频的服务-->
<service
android:name=".service.MainService"
android:enabled="true" />
</application>
</manifest>

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition;
package com.mogo.module.share;
import android.content.Context;
import android.util.ArrayMap;
@@ -7,23 +7,23 @@ import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.analytics.AnalyticsUtils;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.share.service.MainService;
import com.mogo.module.share.service.UploadParams;
import com.mogo.service.share.IMogoTanluProvider;
import com.mogo.service.share.TanluUploadParams;
import com.mogo.utils.logger.Logger;
import com.zhidao.roadcondition.service.MainService;
import com.zhidao.roadcondition.service.UploadParams;
import java.util.Map;
import static com.zhidao.roadcondition.constant.ConstKt.API_MODULE_NAME;
import static com.zhidao.roadcondition.constant.ConstKt.API_MODULE_PATH;
import static com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_TANLU_API;
import static com.mogo.module.share.constant.StrategyShareConstKt.S_TAG;
/**
* 探路api
*
* @author tongchenfei
*/
@Route(path = API_MODULE_PATH)
@Route(path = PATH_TANLU_API)
public class MogoTanluApiProvider implements IMogoTanluProvider {
private Context context;
@@ -34,8 +34,8 @@ public class MogoTanluApiProvider implements IMogoTanluProvider {
*/
@Override
public void uploadRoadCondition(TanluUploadParams params) {
if(params!=null) {
Logger.d(API_MODULE_NAME, "uploadRoadCondition: " + params);
if (params != null) {
Logger.d(S_TAG, "uploadRoadCondition: " + params);
Map<String, Object> properties = new ArrayMap<>();
properties.put("type", params.getEventType());
properties.put("from", params.getFromType());
@@ -44,8 +44,8 @@ public class MogoTanluApiProvider implements IMogoTanluProvider {
MainService.Companion.launchService(context, new UploadParams(params.getEventType(),
params.getFromType(), params.getDuration(), params.getParentId(),
params.getLocation().lat, params.getLocation().lon, location.getAddress(), location.getBearing(), location.getAdCode(), location.getCityCode()));
}else{
Logger.e(API_MODULE_NAME,"params为空无法上报情报");
} else {
Logger.e(S_TAG, "params为空无法上报情报");
}
}
@@ -54,13 +54,13 @@ public class MogoTanluApiProvider implements IMogoTanluProvider {
*/
@Override
public void startTanluService() {
Logger.d(API_MODULE_NAME, "startTanluService");
Logger.d(S_TAG, "startTanluService");
MainService.Companion.launchService(context, null);
}
@Override
public void init(Context context) {
this.context = context;
Logger.d(API_MODULE_NAME,"新TanluApi模块 init====");
Logger.d(S_TAG, "新TanluApi模块 init====");
}
}

View File

@@ -3,30 +3,38 @@
package com.mogo.module.share
import android.content.Context
import android.util.ArrayMap
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.template.IProvider
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.commons.analytics.AnalyticsUtils
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.network.utils.GsonUtil
import com.mogo.module.common.MogoApisHandler
import com.mogo.module.share.adas.AdasFrontCarDistanceY
import com.mogo.module.share.constant.ACCIDENT_STRATEGY_SHARE_PUSH_TYPE
import com.mogo.module.share.constant.S_TAG
import com.mogo.module.share.service.MainService.Companion.launchService
import com.mogo.module.share.service.UploadParams
import com.mogo.module.share.strategyreceiver.AccidentStrategyReceiver
import com.mogo.module.share.strategyreceiver.BlockStrategy
import com.mogo.service.IMogoServiceApis
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.network.utils.GsonUtil
import com.mogo.service.share.TanluUploadParams
import com.mogo.utils.logger.Logger
import org.json.JSONObject
/**
* 策略上报入口服务端策略上报Push的接收地接收后再调用tanlu相关接口进行视频抓取
*
* @author tongchenfei
* @author lixiaopeng
*/
@Route(path = MogoServicePaths.PATH_STRATEGY_SHARE)
class StrategyShareProvider : IProvider {
private lateinit var blockStrategy: BlockStrategy
private var mContext: Context? = null
override fun init(context: Context) {
mContext = context
Logger.d(S_TAG, "策略上报Provider初始化====")
val apis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
blockStrategy = BlockStrategy(context, apis)
@@ -58,5 +66,4 @@ class StrategyShareProvider : IProvider {
// }
}
}

View File

@@ -2,4 +2,5 @@ package com.mogo.module.share.bean
import com.mogo.eagle.core.data.BaseData
data class BaseDataCompat<T>(var result:T?): BaseData()

View File

@@ -1,6 +1,4 @@
package com.zhidao.roadcondition.base
import com.zhidao.roadcondition.model.BaseResponse
package com.mogo.module.share.bean
open class BaseRepository {

View File

@@ -1,11 +1,12 @@
package com.zhidao.roadcondition.model
package com.mogo.module.share.bean
import com.mogo.module.share.constant.HttpConstant
import com.zhidao.roadcondition.constant.HttpConstants
class BaseResponse<out T>(val code: Int, val msg: String, val result: T) {
fun isSuccess(baseUrl: String): Boolean {
return when (baseUrl) {
HttpConstants.getBaseUrl() -> true
HttpConstant.getNetHost() -> true
else -> false
}
}

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.model
package com.mogo.module.share.bean
class CityStrategy(video: Video, pic: Pic) {
var video: Video? = video

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.model
package com.mogo.module.share.bean
data class InformationBody(
val data: String,

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.model
package com.mogo.module.share.bean
import com.mogo.eagle.core.data.map.MogoLatLng

View File

@@ -0,0 +1,3 @@
package com.mogo.module.share.bean
class Results(var cityStrategy: CityStrategy)

View File

@@ -1,12 +1,10 @@
package com.zhidao.roadcondition.model
package com.mogo.module.share.bean
import android.util.Log
import com.google.gson.Gson
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.module.common.constants.HostConst
import com.zhidao.roadcondition.base.BaseRepository
import com.zhidao.roadcondition.net.HttpClient
import com.zhidao.roadcondition.util.LocationUtil
import com.mogo.module.share.net.HttpClient
import com.mogo.module.share.utils.LocationUtil
class StrategyServiceModel : BaseRepository() {
@@ -26,12 +24,4 @@ class StrategyServiceModel : BaseRepository() {
}
}
suspend fun uploadInformation(informationBody: InformationBody): BaseResponse<UploadResult> {
return apiCall {
val informationBodyStr = Gson().toJson(informationBody)
Log.d("MainServiceController", "uploadInformation informationBody = $informationBodyStr")
HttpClient.getInstance(HostConst.DEVA_HOST).getHttpApi()
.uploadInformation(mapOf("sn" to MoGoAiCloudClientConfig.getInstance().getSn(), "data" to informationBodyStr))
}
}
}

View File

@@ -1,6 +1,5 @@
package com.mogo.module.share.bean
import com.mogo.module.share.constant.*
import com.mogo.module.share.constant.ShareConstants.*

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.event
package com.mogo.module.share.bean.event
import org.greenrobot.eventbus.EventBus

View File

@@ -29,6 +29,7 @@ public class ShareConstants {
public static final String TAG = "/tanlu/ui";
public static final String NAVI_INFO = "navi_info";
public static final String MODEL_NAME = "CARD_TYPE_ROAD_CONDITION";
public static final String TANLU = "TanLu";
/**
* 免唤醒词上报拥堵

View File

@@ -5,4 +5,44 @@ const val S_TAG = "StrategyShare"
/**
* 目前两个策略上报事故拥堵都是走的这个push
*/
const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013
const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013
const val TANLU_ROAD_CURRENT = "10015" //实时路况
/**
* 默认视频抓取时长,单位是秒
*/
const val DEFAULT_VIDEO_DURATION = 10
/**
* 数据策略:交通事故上报
*/
const val UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO = "5"
/**
* 数据策略:已有事件云端校验
*/
const val UPLOAD_FROM_STRATEGY_CLOUD_CHECK = "4"
/**
* 数据策略:拥堵自动上报
*/
const val UPLOAD_FROM_STRATEGY_BLOCK_AUTO = "3"
/**
* 策略上报集合
*/
val STRATEGY_UPLOAD_TYPE_ARRAY = arrayOf(UPLOAD_FROM_STRATEGY_BLOCK_AUTO,
UPLOAD_FROM_STRATEGY_CLOUD_CHECK, UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO)
val AlarmTypePic: Int = 1 //定时任务类型 1照片
val AlarmTypeVideo: Int = 2 //定时任务类型 2视频
val alarmBroadAction: String = "com.zhidao.roadCondition.AlarmBroadCast" //定时广播
val sendInformationAction: String = "com.zhidao.roadCondition.SendInformation" //主动上报广播
val customResultAction: String = "com.zhidao.roadCondition.CustomResult" //主动上报结果广播
const val INFO_TYPE_IMG = 0 //图片
const val INFO_TYPE_VIDEO = 1
const val INFO_TYPE_VOICE = 2
const val INFO_TYPE_WORD = 3

View File

@@ -0,0 +1,16 @@
package com.mogo.module.share.net
import com.mogo.module.share.bean.BaseResponse
import com.mogo.module.share.bean.Results
import retrofit2.http.*
/**
* 接口声明
*/
interface HttpApi {
//获取城市策略
@FormUrlEncoded
@POST("yycp-geo-fence-carService/car/carStrategy/no/getCityStrategy/v1")
suspend fun getCityStrategy(@FieldMap cityStrategy: Map<String, String>): BaseResponse<Results>
}

View File

@@ -1,8 +1,8 @@
package com.zhidao.roadcondition.net
package com.mogo.module.share.net
import com.mogo.commons.AbsMogoApplication
import com.mogo.eagle.core.network.NetConfig
import com.zhidao.roadcondition.constant.HttpConstants
import com.mogo.module.share.constant.HttpConstant
import okhttp3.Cache
import okhttp3.Dns
import okhttp3.OkHttpClient
@@ -24,7 +24,7 @@ class HttpClient private constructor(baseUrl: String) {
private var baseUrlClientMap = HashMap<String, HttpClient>()
fun getInstance(): HttpClient {
val baseUrl = HttpConstants.getBaseUrl()
val baseUrl = HttpConstant.getNetHost()
var httpClient = baseUrlClientMap[baseUrl]
if (httpClient == null) {
synchronized(HttpClient::class.java) {

View File

@@ -1,25 +0,0 @@
package com.mogo.module.share.net;
import com.mogo.module.share.bean.BaseDataCompat;
import com.mogo.module.share.bean.RoadInfos;
import java.util.Map;
import io.reactivex.Observable;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface ShareLsApiService {
/**
* 查询(搜索)道路事件信息
* 接口文档http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=42305842
* 文档中有些参数暂时没有用到包括radius,limit
*
* @return
*/
// @FormUrlEncoded
// @POST("/yycp-launcherSnapshot/launcherSnapshot/searchRoadEventsSync")
// Observable<BaseDataCompat<RoadInfos>> queryRoadInfos(@FieldMap Map<String, Object> params);
}

View File

@@ -1,7 +1,6 @@
package com.zhidao.roadcondition.service
package com.mogo.module.share.service
import android.text.TextUtils
import android.util.Log
import com.hw.videoprocessor.VideoProcessor
import com.mogo.cloud.network.BaseData
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
@@ -11,17 +10,19 @@ import com.mogo.cloud.tanlu.bean.UploadInfo
import com.mogo.cloud.tanlu.bean.UploadResult
import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.debug.DebugConfig
import com.mogo.module.share.bean.event.GetImageSuccessEvent
import com.mogo.module.share.bean.event.LatLngStickyEventBus
import com.mogo.module.share.constant.STRATEGY_UPLOAD_TYPE_ARRAY
import com.mogo.module.share.constant.ShareConstants.TANLU
import com.mogo.module.share.utils.*
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMaxSpeed
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyMinSpeed
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType
import com.mogo.utils.NetworkUtils
import com.mogo.utils.logger.Logger
import com.zhidao.auto.carcorder.callback.TakePhotoCallback
import com.zhidao.auto.carcorder.callback.TakeVideoCallback
import com.zhidao.auto.carcorder.controller.ZdCarCoderController
import com.zhidao.roadcondition.constant.STRATEGY_UPLOAD_TYPE_ARRAY
import com.zhidao.roadcondition.event.GetImageSuccessEvent
import com.zhidao.roadcondition.event.LatLngStickyEventBus
import com.zhidao.roadcondition.util.*
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyMaxSpeed
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyMinSpeed
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyType
import java.io.File
import kotlin.math.abs
@@ -32,7 +33,6 @@ import kotlin.math.abs
* @since 2019-10-30
*/
object CarCorderController : TakePhotoCallback, TakeVideoCallback {
const val TAG: String = "CarCorderController"
private lateinit var zdCarCoderController: ZdCarCoderController
private var outputVideoPath: String = ""
private var mType: String = "" //1 上报拥堵, 2 封路和查车
@@ -49,24 +49,11 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
private var getVideoFailed: (() -> Unit)? = null
private var interceptors: ArrayList<TakePhotoInterceptor> = ArrayList(1)
fun getVideoFailed(getVideoFailed: (() -> Unit)) {
this.getVideoFailed = getVideoFailed
}
fun registerTakePhotoInterceptor(interceptor: TakePhotoInterceptor) {
interceptor.apply {
interceptors.add(this)
}
}
fun unregisterTakePhotoInterceptor(interceptor: TakePhotoInterceptor) {
interceptor.apply {
interceptors.remove(interceptor)
}
}
fun initCarCorderController() {
try {
zdCarCoderController =
@@ -96,7 +83,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
areaCode: String,
cityCode: String
) {
Log.d(TAG, "takePhoto ---------- type = $type --- mType = $mType ---fromType = $fromType")
Logger.d(TANLU, "takePhoto ---------- type = $type --- mType = $mType ---fromType = $fromType")
this.mType = type
this.mainInfoId = mainInfoId
this.mFromType = fromType
@@ -133,7 +120,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
areaCode: String,
cityCode: String
) {
Log.d(TAG, "takeVideo -------- isCustom = $isCustom ---mFromType = $mFromType ---type = $type ---speed = $speed")
Logger.d(TANLU, "takeVideo -------- isCustom = $isCustom ---mFromType = $mFromType ---type = $type ---speed = $speed")
this.mType = type
this.mainInfoId = mainInfoId
this.mFromType = fromType
@@ -151,26 +138,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
zdCarCoderController.takeVideo(cameraId, duration)
trackGetVideo(1)
} else { //比亚迪
Log.d(TAG, "takeVideo ------ isnet = " + NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext))
// if (!NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext)) {
// TipToast.shortTip("分享失败,请检查网络")
// } else {
//失败了,传空地址,发起请求
// videoAndThumbMap["video"] = ""
// videoAndThumbMap["thumb"] = ""
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_VIDEO,
// videoAndThumbMap,
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
Logger.d(TANLU, "takeVideo ------ isnet = " + NetworkUtils.isConnected(AbsMogoApplication.getApp().applicationContext))
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) }
//地图上打点
@@ -188,31 +156,15 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
fun release() {
zdCarCoderController.release()
interceptors.clear()
}
//拍照失败回调
override fun onTakePhotoFail(photoType: Int, camera: Int) {
trackGetPhoto(3)
interceptors.forEach {
it.onTakePhotoFail(photoType, camera)
}
val isCustom = CustomStatusHandler.pollPhotoStatus()
Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom")
Logger.e(TANLU, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom")
//获取图片失败也上报,图片不打点
if (isCustom) {
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_IMG,
// mutableMapOf("pic" to ""),
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
@@ -222,7 +174,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
//拍照成功回调返回图片本地路径
override fun onTakePhotoSuccess(photoType: Int, camera: Int, photoPath: String?) {
trackGetPhoto(2)
Log.d(TAG, "onTakePhotoSuccess -----mType = $mType --- mainInfoId = $mainInfoId")
Logger.d(TANLU, "onTakePhotoSuccess -----mType = $mType --- mainInfoId = $mainInfoId")
val isCustom = CustomStatusHandler.pollPhotoStatus()
if (!isCustom) {
@@ -230,10 +182,6 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
}
var interceptor = false
interceptors.forEach {
interceptor = it.intercept()
it.onTakePhotoSuccess(photoType, camera, photoPath)
}
if (interceptor) {
return
}
@@ -253,34 +201,20 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
val speed = LocationUtil.getInstance().getSpeed()
if (!TextUtils.isEmpty(mType)) {
Log.d(TAG, "onTakePhotoSuccess mType != null")
// CosStatusController().uploadFile(mutableListOf(photoPath as String), entity, mType, mainInfoId, mFromType, mLongitude,
// mLatitude, mSpeed)
Logger.d(TANLU, "onTakePhotoSuccess mType != null")
if (photoPath != null) {
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
} else {
Log.d(TAG, "onTakePhotoSuccess mType == null")
Log.d(
TAG,
Logger.d(TANLU, "onTakePhotoSuccess mType == null")
Logger.d(
TANLU,
"onTakePhotoSuccess maxSpeedPic = $maxSpeedPic ---> speed = $speed ---->minSpeedPic= $minSpeedPic"
)
if (maxSpeedPic == -1) {
if (speed >= (abs(minSpeedPic) / 3.6f)) {
Log.d(TAG, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f))
// CosStatusController().uploadFile(
// mutableListOf(photoPath as String),
// entity,
// mType,
// mainInfoId,
// mFromType,
// mLongitude,
// mLatitude,
// mSpeed
// )
Logger.d(TANLU, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f))
if (photoPath != null) {
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
@@ -288,36 +222,23 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
}
if (minSpeedPic > 0 && maxSpeedPic > 0) {
Log.d(TAG, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed")
Logger.d(TANLU, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed")
if ((speed >= (minSpeedPic / 3.6f)) && speed <= (maxSpeedPic / 3.6f)) {
// CosStatusController().uploadFile(
// mutableListOf(photoPath as String),
// entity,
// mType,
// mainInfoId,
// mFromType,
// mLongitude,
// mLatitude,
// mSpeed
// )
if (photoPath != null) {
getInfo(photoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
}
}
}
//获取视频成功
override fun onTakeVideoSuccess(camera: Int, videoPath: String?) {
val thumbnailPath =
AbsMogoApplication.getApp().applicationContext.filesDir.parent + File.separator + "Thumbnail${System.currentTimeMillis()}.jpg"
val isSuccess = getVideoThumbnail(videoPath!!, thumbnailPath)
Log.d(
TAG,
Logger.d(
TANLU,
"getVideo onTakeVideoSuccess===$videoPath -----> isSuccess= $isSuccess ----> mType = $mType --- mainInfoId = $mainInfoId"
)
@@ -349,12 +270,12 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
compressVideo(videoPath, thumbnailPath, it)
} else {
Log.d(
TAG,
Logger.d(
TANLU,
"onTakeVideoSuccess maxSpeedVideo = $maxSpeedVideo --->speed= $speed + minSpeedVideo = $minSpeedVideo"
)
if (maxSpeedVideo == -1) {
Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f))
Logger.d(TANLU, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f))
if (speed >= (abs(minSpeedVideo) / 3.6f)) {
//获取视频以及缩略图成功,开始上报
compressVideo(videoPath, thumbnailPath, it)
@@ -362,7 +283,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
}
if (minSpeedVideo > 0 && maxSpeedVideo > 0) {
Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
Logger.d(TANLU, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) {
compressVideo(videoPath, thumbnailPath, it)
} else {
@@ -371,7 +292,6 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
}
}
}
trackGetVideo(2)
}
}
@@ -380,35 +300,6 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
//获取视频失败
override fun onTakeVideoFail(camera: Int) {
// trackGetVideo(3)
// Log.e(TAG, "getVideo onTakeVideoFail")
// getVideoFailed?.invoke()
// val entity = CustomStatusHandler.pollVideoStatus()
//
// entity?.let {
// InformationUploadController.release(it.id)
// Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + it.isCustom)
//// if (it.isCustom) {
//// sendGetInfoFailedReceiver(mType)
//// }
// }
//失败了,传空地址,发起请求
// videoAndThumbMap["video"] = ""
// videoAndThumbMap["thumb"] = ""
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_VIDEO,
// videoAndThumbMap,
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
//地图上打点
@@ -425,8 +316,8 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
* 压缩视频并且上传
*/
private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) {
Log.d(
TAG,
Logger.d(
TANLU,
"outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}"
)
val startTime = System.currentTimeMillis()
@@ -441,24 +332,12 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
.bitrate(2000 * 1024)
.frameRate(25)
.process()
Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime))
// CosStatusController().uploadFile(
// mutableListOf(outputVideoPath, thumbnailPath),
// entity,
// mType,
// mainInfoId,
// mFromType,
// mLongitude,
// mLatitude,
// mSpeed
// )
Logger.d(TANLU, "compress cost time =" + (System.currentTimeMillis() - startTime))
getInfo(outputVideoPath, mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
//删除压缩前的视频
deletePicFile(videoPath)
} catch (e: Exception) {
Log.e(TAG, "compressVideo e = $e")
Logger.e(TANLU, "compressVideo e = $e")
//删除压缩前的视频
deletePicFile(videoPath)
e.printStackTrace()
@@ -473,16 +352,16 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback {
override fun onSuccess(result: BaseData<UploadResult>) {
if (result.result != null) {
Log.d(TAG, "result =" + result.result);
Logger.d(TANLU, "result =" + result.result)
}
}
override fun onFailure(code: Int) {
Logger.e(TANLU, "onFailure code = $code")
}
override fun onError(e: Throwable) {
Logger.e(TANLU, "onError e = $e")
}
})
}
@@ -509,29 +388,16 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
}
override fun onTakePhotoCancel(photoType: Int, camera: Int) {
Log.d(TAG, "onTakePhotoCancel -----photoType = $photoType")
Logger.d(TANLU, "onTakePhotoCancel -----photoType = $photoType")
}
override fun onTakeVideoCancel(camera: Int) {
Log.d(TAG, "onTakeVideoCancel -----camera = $camera")
Logger.d(TANLU, "onTakeVideoCancel -----camera = $camera")
//失败了,传空地址,发起请求
videoAndThumbMap["video"] = ""
videoAndThumbMap["thumb"] = ""
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_VIDEO,
// videoAndThumbMap,
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", mAddress, mLongitude, mLatitude, mType, mDirection, mAreaCode, mCityCode, 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
//获取图片

View File

@@ -1,9 +1,9 @@
package com.zhidao.roadcondition.service
package com.mogo.module.share.service
import java.util.*
/**
* @author congtaowang
* @author lixiaopeng
* @since 2019-11-25
*
* 拍照拍视频手动被动状态队列

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.service
package com.mogo.module.share.service
import android.app.AlarmManager
import android.app.PendingIntent
@@ -8,7 +8,6 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.IBinder
import android.util.Log
import com.alibaba.android.arouter.launcher.ARouter
import com.elegant.analytics.Analytics
import com.mogo.commons.AbsMogoApplication
@@ -16,21 +15,19 @@ import com.mogo.commons.debug.DebugConfig
import com.mogo.module.common.MogoApisHandler
import com.mogo.service.IMogoServiceApis
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.module.share.bean.event.GetImageSuccessEvent
import com.mogo.module.share.bean.event.LatLngStickyEventBus
import com.mogo.utils.logger.Logger
import com.mogo.utils.storage.SharedPrefsMgr
import com.zhidao.cosupload.manager.CosUploadManagerImpl
import com.zhidao.roadcondition.BuildConfig
import com.zhidao.roadcondition.constant.DEFAULT_VIDEO_DURATION
import com.zhidao.roadcondition.constant.TANLU_ROAD_CURRENT
import com.zhidao.roadcondition.constant.UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO
import com.zhidao.roadcondition.constant.UPLOAD_FROM_STRATEGY_BLOCK_AUTO
import com.zhidao.roadcondition.event.GetImageSuccessEvent
import com.zhidao.roadcondition.event.LatLngStickyEventBus
import com.zhidao.roadcondition.util.*
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.clearStrategyType
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyFrequency
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyInterval
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyType
import com.mogo.module.share.BuildConfig
import com.mogo.module.share.constant.*
import com.mogo.module.share.constant.ShareConstants.TANLU
import com.mogo.module.share.utils.*
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.clearStrategyType
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyFrequency
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyInterval
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import org.greenrobot.eventbus.Subscribe
@@ -45,9 +42,8 @@ class MainService : Service() {
companion object {
fun launchService(context: Context, params: UploadParams?) {
val intent = Intent(context, MainService::class.java).apply {
Log.e("MainService", "launchService type = $params")
Logger.d(TANLU, "launch type = $params")
putExtra("params", params)
}
context.startService(intent)
@@ -60,8 +56,6 @@ class MainService : Service() {
//是否已经获取过策略
var isGetStrategies: Boolean = false
private val TAG: String = this.javaClass.simpleName
//1是一次性2是周期性
private var picType: Int = 0
private var videoType: Int = 0
@@ -75,11 +69,11 @@ class MainService : Service() {
private var mLongitude: Double = 0.0
private var mLatitude: Double = 0.0
private lateinit var serviceApis: IMogoServiceApis
private var mAddress: String = ""
private var mDirection: Float = 0f
private var mAreaCode: String = ""
private var mCityCode: String = ""
private var id: Long = System.currentTimeMillis()
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@@ -94,7 +88,7 @@ class MainService : Service() {
if (serviceApis.mapServiceApi.getSingletonLocationClient(this) != null &&
serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation != null) {
speed = serviceApis.mapServiceApi.getSingletonLocationClient(this).lastKnowLocation.speed
Log.d(TAG, "onStartCommand speed = $speed")
Logger.d(TANLU, "onStartCommand speed = $speed")
}
if (intent != null) {
@@ -110,7 +104,7 @@ class MainService : Service() {
mAreaCode = it.areaCode
mCityCode = it.cityCode
Log.d(TAG, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ")
Logger.d(TANLU, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ")
if (fromType == UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO || fromType == UPLOAD_FROM_STRATEGY_BLOCK_AUTO) {
// 如果是策略上报isCustom = false
takeVideo(it.duration)
@@ -119,7 +113,7 @@ class MainService : Service() {
}
}
} else {
Log.e(TAG, "intent == null ")
Logger.e(TANLU, "intent == null ")
}
return super.onStartCommand(intent, flags, startId)
@@ -128,7 +122,7 @@ class MainService : Service() {
//定时任务回调广播
private var mAlarmBroadCast: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent) {
Log.d(TAG, "receive alarm!!!!!!!!!!AlarmType===${p1.getIntExtra("AlarmType", 1)}")
Logger.d(TANLU, "receive alarm!!!!!!!!!!AlarmType===${p1.getIntExtra("AlarmType", 1)}")
if (p1.action == alarmBroadAction) {
if (p1.getIntExtra("AlarmType", 1) == AlarmTypePic) {
//拍照
@@ -164,7 +158,6 @@ class MainService : Service() {
LocationUtil.getInstance().initLocation()
initLocationListener()
loadConfigurations()
LatLngStickyEventBus.getInstance().register(this)
trackNormalEvent(CarNet_MainService_Start, null)
}
@@ -174,45 +167,23 @@ class MainService : Service() {
CarCorderController.initCarCorderController()
mainServiceHttpModel = MainServiceController()
registReceiver()
// CosStatusController().registerCos(this)
CosCallbackMapController.init(this)
// CosCallbackMapController.init(this)
}
/**
* 加载各种配置
*/
private fun loadConfigurations() {
// mainServiceHttpModel.getAuthorization()
// mainServiceHttpModel.getNeedAuth { authStatus ->
// // isNeedAuth = authStatus
// }
// mainServiceHttpModel.getSplashConfig()
}
private var id: Long = System.currentTimeMillis()
/**
* 获取图片成功
*/
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 98)
fun getImageEvent(getImageSuccessEvent: GetImageSuccessEvent) {
val info = LocationUtil.getInstance().getLocationInfo()
Log.d("MainService", "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}")
Log.d(
"MainService",
Logger.d(TANLU, "getImageEvent long = ${info.longitude} ----> lat= ${info.latitude}")
Logger.d(TANLU,
"getImageEvent url = " + getImageSuccessEvent.getImageUrl() + ">>>>type =" + getImageSuccessEvent.getType()
)
if (!DebugConfig.isMapBased()) {
MogoApisHandler.getInstance().apis.statusManagerApi.setUploadingStatus("CARD_TYPE_ROAD_CONDITION", false)
}
// sendMarkerInfoReceiver(
// info.latitude,
// info.longitude,
// getImageSuccessEvent.getImageUrl(),
// getImageSuccessEvent.getType()
// )
}
@@ -221,7 +192,7 @@ class MainService : Service() {
*/
private fun initLocationListener() {
val isOpen = SharedPrefsMgr.getInstance(AbsMogoApplication.getApp().applicationContext).getBoolean("KEY_SERVER_REPORTSTRATEGY_SWITCH", false)
Logger.d("EntrancePresenter", " initLocationListener ---- isOpen = $isOpen")
Logger.d(TANLU, " initLocationListener ---- isOpen = $isOpen")
//开始开始监听速度,只要超过一次5公里每小时则即开始获取策略进行本地上报 只有release才加此判断qa环境方便测试
LocationUtil.getInstance().setonSpeedlistenner(object : LocationUtil.SpeedListener {
override fun onSpeedGet(speed: Float) {
@@ -230,7 +201,7 @@ class MainService : Service() {
mainServiceHttpModel.initStrategies {
handleReportStrategy()
}
Log.d("MainService", "initLocationListener more than 5 start upload speed = $speed")
Logger.d(TANLU, "initLocationListener more than 5 start upload speed = $speed")
isGetStrategies = true
}
}
@@ -253,7 +224,7 @@ class MainService : Service() {
"video",
getStrategyType("video")
)
Log.d("MainService", "handleReportStrategy picType = $picType ---videoType = $videoType")
Logger.d(TANLU, "handleReportStrategy picType = $picType ---videoType = $videoType")
shareType = TANLU_ROAD_CURRENT
if (picType == 1) {
takePhoto()
@@ -275,14 +246,11 @@ class MainService : Service() {
intentFilter.addAction("com.zhidao.takevideo.test")
intentFilter.addAction("com.zhidao.takepic.test")
registerReceiver(mAlarmBroadCast, intentFilter)
//注册主动上报广播
// var customSendIntentFilter = IntentFilter(sendInformationAction)
// registerReceiver(mCustomSendBroadCast, customSendIntentFilter)
}
//获取图片
private fun takePhoto(isInterval: Boolean = false, isCustom: Boolean = false) {
Log.d("MainService", "takePhoto -----1----->")
Logger.d(TANLU, "takePhoto -----1----->")
//判断是否授权
// if (isAuthorization(BaseApplication.getAppContext())) {
//目前不支持连拍只能定时2秒拍一张 第一期每次只拍一张
@@ -305,7 +273,7 @@ class MainService : Service() {
isCustom: Boolean = false,
id: Long = 0
) {
Log.d("MainService", "takeVideo --------1----> fromType = $fromType --isCustom = $isCustom")
Logger.d(TANLU, "takeVideo --------1----> fromType = $fromType --isCustom = $isCustom")
// if (isAuthorization(BaseApplication.getAppContext())) {
CarCorderController.takeVideo(1, duration, isCustom, id, shareType, mainInfoId, fromType, mLongitude, mLatitude, speed, mAddress, mDirection, mAreaCode, mCityCode)
// }
@@ -322,8 +290,7 @@ class MainService : Service() {
intent.putExtra("number", getLong(PIC_NUMBER, PIC_NUMBER_DEFAULT))
intent.putExtra("AlarmType", AlarmTypePic)
val pendingIntent = PendingIntent.getBroadcast(this, AlarmTypePic, intent, 0)
Log.d(
"MainService",
Logger.d(TANLU,
"postPhotoAlarmTask time =" + getStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
"pic",
@@ -355,8 +322,7 @@ class MainService : Service() {
videoIntent.putExtra("AlarmType", AlarmTypeVideo)
val videoPendingIntent =
PendingIntent.getBroadcast(this, AlarmTypeVideo, videoIntent, 0)
Log.d(
"MainService",
Logger.d(TANLU,
"postVideoAlarmTask time =" + getStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
"video",
@@ -381,7 +347,7 @@ class MainService : Service() {
unregisterReceiver(mAlarmBroadCast)
// unregisterReceiver(mCustomSendBroadCast)
CarCorderController.release()
CosCallbackMapController.release()
// CosCallbackMapController.release()
LatLngStickyEventBus.getInstance().unregister(this)
LatLngStickyEventBus.getInstance().removeAllStickyEvents()
trackNormalEvent(CarNet_MainService_Destory, null)

View File

@@ -0,0 +1,259 @@
package com.mogo.module.share.service
import com.mogo.commons.AbsMogoApplication
import com.mogo.eagle.core.network.request
import com.mogo.module.share.bean.*
import com.mogo.module.share.constant.ShareConstants
import com.mogo.module.share.constant.ShareConstants.TANLU
import com.mogo.module.share.utils.CarNet_Get_Strategy
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyFrequency
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyInterval
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyMaxSpeed
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyMinSpeed
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyType
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.setStrategyValidity
import com.mogo.module.share.utils.trackNormalEvent
import com.mogo.utils.logger.Logger
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class MainServiceController {
companion object {
// const val TAG = "MainServiceController"
}
//逆地理编码是否重试
private var geoRetry = false
private var mFromType: String = ""
private var mPoiType: String = ""
private val strategyModel by lazy { StrategyServiceModel() }
fun initStrategies(initFinish: (() -> Unit)? = null) {
request<BaseResponse<Results>> {
loader {
strategyModel.getCityStrategy()
}
onSuccess {
it.result.let { strategy ->
trackNormalEvent(CarNet_Get_Strategy, null)
Logger.d(TANLU, "pic =" + strategy.cityStrategy.pic)
Logger.d(TANLU, "video =" + strategy.cityStrategy.video)
syncStrategiesData(strategy.cityStrategy)
initFinish?.invoke()
}
}
onError {
reInitStrategies()
Logger.e(TANLU, "initStrategies onError ${it.message}")
}
}
}
private fun reInitStrategies() = runBlocking {
launch {
initStrategies()
}
}
/**
* 将数据同步到sharePreference中
*/
private fun syncStrategiesData(strategy: CityStrategy) {
if (strategy.pic != null && strategy.video!=null) {
setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.pic!!.strategyType, "pic")
setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.video!!.strategyType, "video")
setStrategyFrequency(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.reportType
)
setStrategyFrequency(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.reportType
)
setStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.reportTimeInterval * 60 * 1000L
)
setStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.reportTimeInterval * 60 * 1000L
)
setStrategyValidity(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.infoTimeout
)
setStrategyValidity(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.infoTimeout
)
setStrategyMaxSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.getMaxSpeed()
)
setStrategyMaxSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.getMaxSpeed()
)
setStrategyMinSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.minSpeed
)
setStrategyMinSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.minSpeed
)
} else {
Logger.d(TANLU, "strategy Data is null")
}
}
//上传情报数据
// fun sendInformationMessage(
// fromType: String,
// type: Int,
// url: Map<String, String>,
// isCustom: Boolean = false,
// trafficInfoType:String = "",
// isShare:Boolean = false,
// poiType:String,
// mainInfoId:Long,
// speed: Float,
// longitude: Double,
// latitude: Double,
// customSend: ((Boolean) -> Unit)? = null
// ) {
// Log.d(TAG, " sendInformationMessage poiType = $poiType -- fromType = $fromType")
// mFromType = fromType
// mPoiType = poiType
//
// val locationInfo = LocationUtil.getInstance().getLocationInfo()
// if (locationInfo.address.isEmpty()) {
// Log.d(TAG, " sendInformationMessage locationInfo.address = $locationInfo.address")
// trackUploadGeo(1)
// geoLocation(type, url, locationInfo, isCustom,trafficInfoType, isShare, customSend,poiType,mainInfoId,speed, longitude,latitude)
// } else {
// postInformationMessage(
// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare,poiType,mainInfoId,longitude,latitude, speed, mFromType),
// customSend
// )
// }
// }
//如果address为空则逆地理编码
// private fun geoLocation(
// type: Int,
// url: Map<String, String>,
// locationInfo: LocationInfo,
// isCustom: Boolean,
// trafficInfoType:String,
// isShare: Boolean,
// customSend: ((Boolean) -> Unit)? = null,
// poiType: String,
// mainInfoId: Long,
// speed: Float,
// longitude: Double,
// latitude: Double
// ) {
// Log.d(TAG, " geoLocation -- poiType = $poiType")
// LocationUtil.getInstance()
// .geoCodeLocation(locationInfo.toLatLngPoint(), {
// Log.d(TAG, "geoLocation -------start -->")
// postInformationMessage(
// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude, speed, mFromType),
// customSend
// )
// }, {
// //转换失败的情况下再重试一次
// Log.d(TAG, "geoLocation -------true-->")
// geoRetry = if (!geoRetry) {
// geoLocation(type, url, locationInfo, isCustom, trafficInfoType, isShare, customSend, poiType,mainInfoId,speed, longitude,latitude)
// true
// } else {
// //如果两次都失败,直接上报服务端
// Log.d(TAG, "geoLocation ---- postInformationMessage ---false-->")
// postInformationMessage(
// getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude,speed, mFromType),
// customSend
// )
// false
// }
// })
// }
// private fun postInformationMessage(
// informationBody: InformationBody,
// customSend: ((Boolean) -> Unit)? = null
// ) {
// trackUploadServer(3)
// request<BaseResponse<UploadResult>> {
// loader {
// strategyModel.uploadInformation(informationBody)
// }
// onSuccess {
// Log.i(TAG, "upload success id = " + it.result.id)
// if (mFromType == "6") {
// sendUgcStatusReceiver(it.result.id, mPoiType, mFromType)
// }
// trackUploadServer(1)
// customSend?.invoke(true)
// }
// onError {
// Log.i(TAG, "$it upload message ${it.message}")
// trackUploadServer(2)
// if (mFromType == "6") {
// sendUgcStatusReceiver(0, mPoiType, mFromType)
// }
// customSend?.invoke(false)
// }
// }
// }
// private fun sendUgcStatusReceiver(id: Long, type: String?, fromType: String?) {
// Log.d(TAG, "sendUgcStatusReceiver id = $id ---type = $type --fromType = $fromType ")
// val intent = Intent()
// intent.action = "com.v2x.ugc.upload.status"
// intent.putExtra("id", id)
// intent.putExtra("type", type)
// intent.putExtra("fromType", fromType)
// AbsMogoApplication.getApp().applicationContext.sendBroadcast(intent)
// }
//
// //上传服务器
// private fun trackUploadServer(type: Int) {
// trackNormalEvent(
// CarNet_Servers_Upload, mutableMapOf("type" to type)
// )
// }
//
// //上传
// private fun trackUploadGeo(type: Int) {
// trackNormalEvent(
// CarNet_Geo, mutableMapOf("type" to type)
// )
// }
}

View File

@@ -1,8 +1,11 @@
package com.zhidao.roadcondition.service
package com.mogo.module.share.service
import android.os.Parcel
import android.os.Parcelable
/**
* 上报参数
*/
class UploadParams(val eventType: String, val fromType: String, val duration: Int, val parentId: Long, val lat: Double, val lon: Double,val addr:String,val direction:Float,val areaCode:String,val cityCode:String) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import android.content.Context
import com.elegant.analytics.Analytics

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import android.graphics.Bitmap
import android.media.MediaMetadataRetriever

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import android.util.Log
import com.mogo.commons.AbsMogoApplication
@@ -8,7 +8,8 @@ import com.mogo.map.search.geo.MogoRegeocodeAddress
import com.mogo.map.search.geo.MogoRegeocodeResult
import com.mogo.map.search.geo.query.MogoRegeocodeQuery
import com.mogo.module.common.MogoApisHandler
import com.zhidao.roadcondition.model.LocationInfo
import com.mogo.module.share.bean.LocationInfo
private fun toLocInfo(
address: MogoRegeocodeAddress,
@@ -120,10 +121,8 @@ class LocationUtil private constructor() {
regeocodeQuery.radius = 200
geocoderSearch.getFromLocationAsyn(regeocodeQuery)
geocoderSearch.setGeoSearchListener(object : IMogoGeoSearchListener {
override fun onRegeocodeSearched(regeocodeResult: MogoRegeocodeResult?) {
super.onRegeocodeSearched(regeocodeResult)
// super.onRegeocodeSearched(regeocodeResult)
if( regeocodeResult == null ){
trackUploadGeo(3)
onError.invoke("geoCode")

View File

@@ -1,30 +1,31 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import android.util.Log
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.commons.AbsMogoApplication
import com.zhidao.roadcondition.model.InformationBody
import com.zhidao.roadcondition.model.LocationInfo
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_IMG
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_VIDEO
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyType
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.getStrategyValidity
import com.mogo.module.share.bean.InformationBody
import com.mogo.module.share.bean.LocationInfo
import com.mogo.module.share.constant.INFO_TYPE_IMG
import com.mogo.module.share.constant.INFO_TYPE_VIDEO
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyType
import com.mogo.module.share.utils.StrategyPreferenceUtil.Companion.getStrategyValidity
fun getInformationBody(
types: Int,
urls: Map<String, String>,
locationInfo: LocationInfo,
isCustom: Boolean,
trafficInfoType:String = "",
isShare:Boolean,
poiType: String,
mainInfoId: Long,
longitude: Double,
latitude: Double,
speed: Float,
fromType: String
types: Int,
urls: Map<String, String>,
locationInfo: LocationInfo,
isCustom: Boolean,
trafficInfoType:String = "",
isShare:Boolean,
poiType: String,
mainInfoId: Long,
longitude: Double,
latitude: Double,
speed: Float,
fromType: String
): InformationBody {
val jsonArray = JsonArray()
val type: Int

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import android.content.Context
import androidx.core.content.edit

View File

@@ -1,4 +1,4 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import android.content.Context
import android.util.Log

View File

@@ -1,5 +1,6 @@
package com.zhidao.roadcondition.util
package com.mogo.module.share.utils
import bolts.Task.delay
import kotlinx.coroutines.*
@ObsoleteCoroutinesApi
@@ -8,15 +9,6 @@ internal var ThreadPool =
newFixedThreadPoolContext(Runtime.getRuntime().availableProcessors() * 2, "ThreadPool")
/**
* 在主线程中顺序执行协程函数一般用于最外层
* 该函数会阻塞代码继续执行
*/
//inline fun taskBlockOnMainThread(delayTime: Long = 0, noinline job: suspend () -> Unit) = runBlocking {
// delay(delayTime)
// job()
//}
/**
* 并发执行常用于最外层
* 特点带返回值

View File

@@ -1 +0,0 @@
/build

View File

@@ -1,94 +0,0 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.alibaba.arouter'
}
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
// buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode Integer.valueOf(VERSION_CODE)
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
//ARouter apt 参数
kapt {
useBuildCache = false
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
}
buildTypes {
release {
minifyEnabled false
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation rootProject.ext.dependencies.kotlinstdlibjdk7
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.androidxccorektx
implementation rootProject.ext.dependencies.aiassist
implementation rootProject.ext.dependencies.okhttpinterceptor
implementation 'com.zhidaoauto.controller:api:1.0.8'
implementation 'com.zhidao.cosupload:cosuploadsdk:1.1.6', {
exclude group: 'com.zhidao.utils', module: 'utils'
}
implementation 'com.zhidao.video:video-processor:1.0.2.1'
implementation rootProject.ext.dependencies.eventbus
implementation rootProject.ext.dependencies.coroutinescore
implementation rootProject.ext.dependencies.coroutinesandroid
implementation rootProject.ext.dependencies.retrofit
implementation rootProject.ext.dependencies.retrofitconvertergson
implementation rootProject.ext.dependencies.gson
implementation rootProject.ext.dependencies.rxjava
implementation rootProject.ext.dependencies.rxandroid
implementation rootProject.ext.dependencies.analytics
implementation rootProject.ext.dependencies.arouter
kapt rootProject.ext.dependencies.aroutercompiler
implementation rootProject.ext.dependencies.mogoaicloudtanlu
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
implementation rootProject.ext.dependencies.mogoutils
implementation rootProject.ext.dependencies.modulecommon
implementation rootProject.ext.dependencies.mogomap
implementation rootProject.ext.dependencies.mogoserviceapi
implementation rootProject.ext.dependencies.mogo_core_data
} else {
implementation project(":foudations:mogo-utils")
implementation project(':modules:mogo-module-common')
implementation project(':libraries:mogo-map')
implementation project(':services:mogo-service-api')
implementation project(':core:mogo-core-data')
}
}
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()

View File

@@ -1,4 +0,0 @@
-keep class com.zhidao.roadcondition.model.**{*;}
-keep class com.zhidao.roadcondition.service.*{*;}
-keep class com.zhidao.roadcondition.ShareRoadReceiver.*{*;}

View File

@@ -1,3 +0,0 @@
GROUP=com.mogo.module
POM_ARTIFACT_ID=module-tanlu-upload
VERSION_CODE=1

View File

@@ -1,27 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.zhidao.roadcondition.model.**{*;}
-keep class com.zhidao.roadcondition.service.*{*;}
-keep class com.zhidao.roadcondition.ShareRoadReceiver.*{*;}

View File

@@ -1,25 +0,0 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zhidao.roadcondition">
<application>
<!--分享相关广播-->
<receiver
android:name=".receiver.ShareRoadReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.zhidao.share.roadcondition.action" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<!--获取图片和视频的服务-->
<service
android:name=".service.MainService"
android:enabled="true" />
<service
android:name=".service.DelayService"
android:exported="false" />
</application>
</manifest>

View File

@@ -1,39 +0,0 @@
package com.zhidao.roadcondition.base
import android.app.IntentService
import android.content.Intent
import android.os.IBinder
open class BaseIntentService : IntentService("BaseIntentService") {
protected var tag: String = this.javaClass.simpleName
override fun onHandleIntent(p0: Intent?) {
tag = this.javaClass.simpleName
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
override fun onCreate() {
super.onCreate()
}
override fun onStart(intent: Intent?, startId: Int) {
super.onStart(intent, startId)
}
override fun onBind(intent: Intent?): IBinder? {
return super.onBind(intent)
}
override fun setIntentRedelivery(enabled: Boolean) {
super.setIntentRedelivery(enabled)
}
override fun onDestroy() {
super.onDestroy()
}
}

View File

@@ -1,87 +0,0 @@
package com.zhidao.roadcondition.constant
public val STRATEGY_TYPE_PHOTO: String = "0FOoOuB7" //拍照的策略ID
public val STRATEGY_TYPE_VIDEO: String = "gVCl9VdW" //拍视频的策略ID
public val SOCKET_MSG_TYPE: Int = 0x040001 //长连接消息类型
public val SOCKET_PRODUCT_LINE: Int = 0x04 //长连接消息产品线id目前SDK是写死的
const val INFORMATION_DATA_SIZE_LIMIT = 50
const val INFORMATION_DEFAULT_MAP_RADIUS = 10
const val REQUESTCODE_MAINACTIVITY = 0
const val REQUESTCODE_MEDIAACTIVITY = 1
const val CUSTOM_SEND_CMD = "custom_send_cmd" //主动上报语音命令
const val VOICE_PREVIOUS_INFO_CMD = "voice_previous_info_cmd" //上一条
const val VOICE_NEXT_INFO_CMD = "voice_next_info_cmd" //下一条
const val SCHEME_SPLASH_TYPE = "channelType"
const val SCHEME_MAIN_TYPE = "type"
const val PARAM_MAIN_PAGE_ACTION = "action" // 判断主页该干什么
const val VAL_ACTION_TQZ = "tqz" //通勤族
const val VAL_ACTION_PLAY_DIRECTLY = "play" //直接播放情报
const val VAL_ACTION_DHLX = "dhlx" //导航路线
const val CONFIG_NEED_AUTH = "0001" //公共配置 是否查询授权
const val CONFIG_ACTIVE_POSITION = "0002" //公共配置 查询运营位配置
//广播action、key
const val AUTONAVI_STANDARD_BROADCAST_SEND = "AUTONAVI_STANDARD_BROADCAST_SEND"
const val AUTONAVI_STANDARD_BROADCAST_ROAD_INFO = "EXTRA_ROAD_INFO"
const val AUTONAVI_STANDARD_BROADCAST_EXTRA_STATE = "EXTRA_STATE"
//EXTRA_STATE
const val AUTO_NAVI_START = 8 //开始导航
const val AUTO_NAVI_END = 9 //结束导航
const val VALUE_DICT_DATA_TYPE = "deva_infomation_type" // dict 数据请求类型:情报类型数据
//事件类型
const val TANLU_TRAFFIC_CHECK = "10002" //交通检查
const val TANLU_ROAD_CLOSURE = "10003" //封路
const val TANLU_ROAD_WORK = "10006" //施工
const val TANLU_ROAD_CONGESTION = "10007" //拥堵
const val TANLU_ROAD_PONDING = "10008" //积水
const val TANLU_ROAD_HEAVY_FOG = "10010" //大雾
const val TANLU_ROAD_ICING = "10011" //积冰
const val TANLU_ROAD_ACCIDENT = "10013" //事故
const val TANLU_ROAD_CURRENT = "10015" //实时路况
// 上报类型
/**
* 用户手点上报
*/
const val UPLOAD_FROM_USER = "1"
/**
* 用户语音上报
*/
const val UPLOAD_FROM_VOICE = "2"
/**
* 数据策略:拥堵自动上报
*/
const val UPLOAD_FROM_STRATEGY_BLOCK_AUTO = "3"
/**
* 数据策略:已有事件云端校验
*/
const val UPLOAD_FROM_STRATEGY_CLOUD_CHECK = "4"
/**
* 数据策略:交通事故上报
*/
const val UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO = "5"
/**
* 策略上报集合
*/
val STRATEGY_UPLOAD_TYPE_ARRAY = arrayOf(UPLOAD_FROM_STRATEGY_BLOCK_AUTO,
UPLOAD_FROM_STRATEGY_CLOUD_CHECK, UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO)
/**
* 默认视频抓取时长,单位是秒
*/
const val DEFAULT_VIDEO_DURATION = 10
const val DEF_NEWS_LABEL = "拥堵"
const val DEF_NEWS_VALUE = "traffic_jam"
const val DEF_NEWS_TYPE = "0"
const val API_MODULE_NAME = "MogoTanluApi"
const val API_MODULE_PATH = "/tanlulib/api"

View File

@@ -1,24 +0,0 @@
package com.zhidao.roadcondition.constant
import com.mogo.commons.debug.DebugConfig
class HttpConstants {
companion object {
const val DEV_BASE_URL_OWNER = "http://dzt-test.zhidaozhixing.com/"
const val RELEASE_BASE_URL_OWNER = "http://dzt.zhidaozhixing.com/"
const val SHOW_BASE_URL_OWNER = "http://dzt-show.zhidaozhixing.com/"
fun getBaseUrl(): String {
return when (DebugConfig.getNetMode()) {
DebugConfig.NET_MODE_QA -> DEV_BASE_URL_OWNER
DebugConfig.NET_MODE_RELEASE -> RELEASE_BASE_URL_OWNER
DebugConfig.NET_MODE_DEMO -> SHOW_BASE_URL_OWNER
else -> DEV_BASE_URL_OWNER
}
}
}
}

View File

@@ -1,19 +0,0 @@
package com.zhidao.roadcondition.exception
class ApiException : Exception {
companion object{
val NETWORK_API_EXCEPTION = ApiException(1, "network is error")
val NULL_REQUEST_DATA_API_EXCEPTION = ApiException(2, "request data is null")
}
private var code: Int = 0
private var msg: String = ""
constructor(code: Int, msg: String) : super(msg) {
this.code = code
this.msg = msg
}
}

View File

@@ -1,5 +0,0 @@
package com.zhidao.roadcondition.model
class BaseRequest<T>(var sn: String, var data: T?) {
}

View File

@@ -1,47 +0,0 @@
package com.zhidao.roadcondition.model
class CommonConfig {
var active:Active //活动配置
// var promotion:Promotion //Splash页面图片以及语音推广配置
var auth:Auth //授权配置
constructor(active: Active, auth: Auth) {
this.active = active
// this.promotion = promotion
this.auth = auth
}
}
class Active{
var imageUrl:String
var webUrl:String
var status:Int
constructor(imageUrl: String, webUrl: String, status: Int) {
this.imageUrl = imageUrl
this.webUrl = webUrl
this.status = status
}
}
class Promotion{
var imageUrl:String
var voiceContent:String
var status:Int
constructor(imageUrl: String, voiceContent: String, status: Int) {
this.imageUrl = imageUrl
this.voiceContent = voiceContent
this.status = status
}
}
class Auth{
var isNeedAuth:Int
constructor(isNeedAuth: Int) {
this.isNeedAuth = isNeedAuth
}
}

View File

@@ -1,41 +0,0 @@
package com.zhidao.roadcondition.model
/**
* @author congtaowang
* @since 2019-11-22
*
* 一次情报的数据
*/
class InformationResource {
var id: Long
var isCosResourceReady: Boolean = false
var isInformationSelected: Boolean = false
var sourceType: Int = 0 // 情报载体类型:图片、视频
var cosParameter: Map<String, String>? = null // 情报参数
var informationType: InformationType? = null //情报类型
var isCustomSend: Boolean = false // 自动上传
var callback: ((customSend: Boolean) -> Unit)? = null
lateinit var newsType: String // 埋点:情报类型
lateinit var operType: String // 埋点:操作类型
constructor(id: Long) {
this.id = id
}
fun isReady() = isCosResourceReady and isInformationSelected
fun release() {
cosParameter = null
informationType = null
callback = null
}
override fun toString(): String {
return "upload information: sourceType=${sourceType}, informationType={${informationType?.dictLabel}, ${informationType?.dictValue}}"
}
}

View File

@@ -1,29 +0,0 @@
package com.zhidao.roadcondition.model
import com.google.gson.Gson
import com.zhidao.roadcondition.constant.DEF_NEWS_LABEL
import com.zhidao.roadcondition.constant.DEF_NEWS_TYPE
import com.zhidao.roadcondition.constant.DEF_NEWS_VALUE
/**
* @author congtaowang
* @since 2019-11-18
*
* 情报类型
*/
data class InformationType(var dictLabel: String, var dictValue: String, var remark: String) {
companion object {
val def = InformationType(DEF_NEWS_LABEL, DEF_NEWS_VALUE, DEF_NEWS_TYPE)
}
override fun equals(other: Any?): Boolean {
when (other) {
is InformationType -> return other.dictValue.compareTo(dictValue) == 0
}
return super.equals(other)
}
override fun toString(): String {
return Gson().toJson(this)
}
}

View File

@@ -1,9 +0,0 @@
package com.zhidao.roadcondition.model
/**
* @author congtaowang
* @since 2019-11-18
*
* 描述
*/
data class InformationTypeResult(var types: List<InformationType>)

View File

@@ -1,63 +0,0 @@
package com.zhidao.roadcondition.model
import android.os.Parcel
import android.os.Parcelable
class Informations(
var type: Int,
var lon: Double,
var lat: Double,
var addr: String?,
var generateTime: Long,
var cityName: String?,
// var items: ArrayList<Items>,
var distance: Int,
var nickName: String?,
var headImgUrl: String?
) :
Parcelable {
var position = 0
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readDouble(),
parcel.readDouble(),
parcel.readString(),
parcel.readLong(),
parcel.readString(),
// parcel.readArrayList(Items::class.java.classLoader) as ArrayList<Items>,
parcel.readInt(),
parcel.readString(),
parcel.readString()
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(type)
parcel.writeDouble(lon)
parcel.writeDouble(lat)
parcel.writeString(addr)
parcel.writeLong(generateTime)
parcel.writeString(cityName)
// parcel.writeList(items)
parcel.writeInt(distance)
parcel.writeString(nickName)
parcel.writeString(headImgUrl)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Informations> {
override fun createFromParcel(parcel: Parcel): Informations {
return Informations(parcel)
}
override fun newArray(size: Int): Array<Informations?> {
return arrayOfNulls(size)
}
}
}

View File

@@ -1,33 +0,0 @@
package com.zhidao.roadcondition.model
import android.os.Parcel
import android.os.Parcelable
class Items(var url: String?, var thumbnail: String? = null) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readString()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(url)
parcel.writeString(thumbnail)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Items> {
override fun createFromParcel(parcel: Parcel): Items {
return Items(parcel)
}
override fun newArray(size: Int): Array<Items?> {
return arrayOfNulls(size)
}
}
}

View File

@@ -1,6 +0,0 @@
package com.zhidao.roadcondition.model
/**
* 城市策略实体
*/
class Results(var cityStrategy: CityStrategy)

View File

@@ -1,8 +0,0 @@
package com.zhidao.roadcondition.model
/**
* 上报成功返回
*/
class UploadResult(var id: Long) {
}

View File

@@ -1,19 +0,0 @@
package com.zhidao.roadcondition.model.proxy
import androidx.annotation.IntDef
const val INFO_TYPE_GONE = 0
const val INFO_TYPE_SHOW = 1
@IntDef(INFO_TYPE_GONE, INFO_TYPE_SHOW)
@Retention(AnnotationRetention.SOURCE)
annotation class ActiveInfoType
fun isActiveShow(@ActiveInfoType type: Int): Boolean {
return when (type) {
INFO_TYPE_GONE -> false
INFO_TYPE_SHOW -> true
else -> false
}
}

View File

@@ -1,14 +0,0 @@
package com.zhidao.roadcondition.model.proxy
import androidx.annotation.IntDef
const val INFO_TYPE_IMG = 0 //图片
const val INFO_TYPE_VIDEO = 1
const val INFO_TYPE_VOICE = 2
const val INFO_TYPE_WORD = 3
@IntDef(INFO_TYPE_IMG, INFO_TYPE_VIDEO, INFO_TYPE_VOICE, INFO_TYPE_WORD)
@Retention(AnnotationRetention.SOURCE)
annotation class InformationsType

View File

@@ -1,71 +0,0 @@
package com.zhidao.roadcondition.net
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import com.zhidao.roadcondition.exception.ApiException
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Main
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.util.concurrent.TimeoutException
/**
* 后续考虑加入Lifecycle管理暂时不做扩展
*/
class CoroutineChain {
internal class CoroutineLifecycleListener(private val deferred: Deferred<*>, private val lifecycle: Lifecycle) :
LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun cancelCoroutine() {
if (deferred.isActive) {
deferred.cancel()
}
lifecycle.removeObserver(this)
}
}
infix fun LifecycleOwner.start(start: (() -> Unit)): LifecycleOwner {
start()
return this
}
infix fun <T> LifecycleOwner.request(loader: suspend () -> T): Deferred<T> {
return request(loader, true)
}
private fun <T> LifecycleOwner.request(loader: suspend () -> T, needAutoCancel: Boolean = true): Deferred<T> {
val deferred = GlobalScope.async(Dispatchers.IO, start = CoroutineStart.LAZY) {
loader()
}
if (needAutoCancel) {
lifecycle.addObserver(CoroutineLifecycleListener(deferred, lifecycle))
}
return deferred
}
fun <T> Deferred<T>.then(
onSuccess: suspend (T) -> Unit,
onError: suspend (java.lang.Exception) -> Unit,
onComplete: (() -> Unit)? = null
): Job {
return GlobalScope.launch(context = Main) {
try {
val result = this@then.await()
onSuccess(result)
} catch (e: Exception) {
e.printStackTrace()
when (e) {
is UnknownHostException -> onError.invoke(ApiException.NETWORK_API_EXCEPTION)
is TimeoutException -> onError.invoke(ApiException.NETWORK_API_EXCEPTION)
is SocketTimeoutException -> onError.invoke(ApiException.NETWORK_API_EXCEPTION)
else -> onError(e)
}
} finally {
onComplete?.invoke()
}
}
}
}

View File

@@ -1,104 +0,0 @@
package com.zhidao.roadcondition.net
import androidx.lifecycle.LifecycleOwner
import com.zhidao.roadcondition.exception.ApiException
import com.zhidao.roadcondition.exception.ApiException.Companion.NETWORK_API_EXCEPTION
import com.zhidao.roadcondition.exception.ApiException.Companion.NULL_REQUEST_DATA_API_EXCEPTION
import com.zhidao.roadcondition.model.BaseResponse
import kotlinx.coroutines.*
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.util.concurrent.TimeoutException
class Request<T> {
private lateinit var loader: suspend () -> T
private var start: (() -> Unit)? = null
private var onSuccess: ((T) -> Unit)? = null
private var onError: ((java.lang.Exception) -> Unit)? = null
private var onComplete: (() -> Unit)? = null
private var addLifecycle: LifecycleOwner? = null
infix fun loader(loader: suspend () -> T) {
this.loader = loader
}
infix fun start(start: (() -> Unit)?) {
this.start = start
}
infix fun onSuccess(onSuccess: ((T) -> Unit)?) {
this.onSuccess = onSuccess
}
infix fun onError(onError: ((java.lang.Exception) -> Unit)?) {
this.onError = onError
}
infix fun onComplete(onComplete: (() -> Unit)?) {
this.onComplete = onComplete
}
infix fun addLifecycle(addLifecycle: LifecycleOwner?) {
this.addLifecycle = addLifecycle
}
fun request() {
request(addLifecycle)
}
fun request(addLifecycle: LifecycleOwner?) {
GlobalScope.launch(context = Dispatchers.Main) {
start?.invoke()
try {
val deferred = GlobalScope.async(Dispatchers.IO, start = CoroutineStart.LAZY) {
loader()
}
addLifecycle?.apply {
lifecycle.addObserver(
CoroutineChain.CoroutineLifecycleListener(
deferred,
lifecycle
)
)
}
val result = deferred.await()
if (result != null && result is BaseResponse<*>) {
if (result.code == 0) {
onSuccess?.invoke(result)
} else {
throw ApiException(result.code, result.msg)
}
} else {
throw NULL_REQUEST_DATA_API_EXCEPTION
}
} catch (e: Exception) {
e.printStackTrace()
//数据打点
when (e) {
is UnknownHostException -> onError?.invoke(NETWORK_API_EXCEPTION)
is TimeoutException -> onError?.invoke(NETWORK_API_EXCEPTION)
is SocketTimeoutException -> onError?.invoke(NETWORK_API_EXCEPTION)
else -> onError?.invoke(java.lang.Exception(e.message))
}
} finally {
onComplete?.invoke()
}
}
}
}
inline fun <T> request(buildRequest: Request<T>.() -> Unit) {
Request<T>().apply(buildRequest).request()
}
inline fun <T> LifecycleOwner.request(buildRequest: Request<T>.() -> Unit) {
Request<T>().apply(buildRequest).request(this)
}

View File

@@ -1,22 +0,0 @@
package com.zhidao.roadcondition.net
import com.zhidao.roadcondition.model.BaseResponse
import com.zhidao.roadcondition.model.Results
import com.zhidao.roadcondition.model.UploadResult
import retrofit2.http.*
/**
* 接口声明
*/
interface HttpApi {
//获取城市策略
@FormUrlEncoded
@POST("yycp-geo-fence-carService/car/carStrategy/no/getCityStrategy/v1")
suspend fun getCityStrategy(@FieldMap cityStrategy: Map<String, String>): BaseResponse<Results>
//上报情报数据
@FormUrlEncoded
@POST("/deva/car/path/no/addInfomation/v2")
suspend fun uploadInformation(@FieldMap information: Map<String, String>): BaseResponse<UploadResult>
}

View File

@@ -1,18 +0,0 @@
package com.zhidao.roadcondition.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
class ShareRoadReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d("MainService", "ShareRoadReceiver ------> intent.action = " + intent.action)
if (intent.action == "com.zhidao.share.roadcondition.action") {
val type = intent.getStringExtra("type")
Log.e("MainService", "ShareRoadReceiver type ----> $type ----> 此方法已经废弃了,无法调起服务")
// MainService.launchService(context, type)
}
}
}

View File

@@ -1,79 +0,0 @@
package com.zhidao.roadcondition.service
import com.zhidao.cosupload.callback.CosStatusCallback
import com.zhidao.cosupload.callback.CosStatusCallbackManager
/**
* @author congtaowang
* @since 2019-11-25
*
*/
object CosCallbackMapController : CosStatusCallback {
private val map: MutableMap<String, CosStatusCallback> = mutableMapOf()
var uploadFailed: (() -> Unit)? = null
var mainService: MainService? = null
fun init(mainService: MainService) {
this.mainService = mainService
CosStatusCallbackManager.getInstance().register(this)
}
fun uploadFailed(uploadFailed: (() -> Unit)) {
this.uploadFailed = uploadFailed
}
fun registerCallback(paths: List<String?>?, callback: CosStatusCallback) {
paths?.let { list ->
list.forEach { path ->
path?.let {
map[it] = callback
}
}
}
}
fun unregisterCallback(path: String?) {
path?.let {
map.remove(path)
}
}
fun unregisterCallbacks(paths: Map<String, String>?) {
paths?.let {
it.keys.let { keys ->
keys.forEach { path ->
unregisterCallback(path)
}
}
}
}
override fun onStartUpload(eventId: String?, localPath: String?) {
map[localPath]?.onStartUpload(eventId, localPath)
}
override fun uploadCosFailed(cosPath: String?, eventId: String?, localPath: String?) {
map[localPath]?.uploadCosFailed(cosPath, eventId, localPath)
}
override fun uploadCosCompleted(
cosPath: String?,
eventId: String?,
downloadUrl: String?,
localPath: String?
) {
map[localPath]?.uploadCosCompleted(cosPath, eventId, downloadUrl, localPath)
}
override fun onProgress(localPath: String?, progress: Float) {
map[localPath]?.onProgress(localPath, progress)
}
fun release() {
CosStatusCallbackManager.getInstance().unregister(this)
map.clear()
uploadFailed = null
}
}

View File

@@ -1,240 +0,0 @@
package com.zhidao.roadcondition.service
import android.content.Intent
import android.os.Environment
import android.util.Log
import com.google.gson.Gson
import com.mogo.commons.AbsMogoApplication
import com.zhidao.cosupload.DbPriorityConfig
import com.zhidao.cosupload.callback.CosStatusCallback
import com.zhidao.cosupload.manager.CosUploadManagerImpl
import com.zhidao.roadcondition.event.GetImageSuccessEvent
import com.zhidao.roadcondition.event.LatLngStickyEventBus
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_IMG
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_VIDEO
import com.zhidao.roadcondition.util.*
import java.io.File
/**
* @description cos上传操作
*
* @author lixiaopeng
* @since 2019-10-30
*/
class CosStatusController : CosStatusCallback {
companion object{
const val TAG: String = "CosStatusController"
}
//存储单次请求的视频和缩略图url
private var videoAndThumbMap: MutableMap<String, String> = mutableMapOf()
//图片上传的eventId
private lateinit var mPicEventId: String
private var isRetry = false //是否重试上传过图片
private var mainServiceHttpModel = MainServiceController()
private lateinit var entity: TakeEntity
private var mType: String = ""
private var mainInfoId: Long = 0
private var mFromType: String = ""
private var mLongitude: Double = 0.0
private var mLatitude: Double = 0.0
private var mSpeed: Float = 0f
val moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES + File.separator
)
//上传文件
fun uploadFile(picPath: MutableList<String?>?, entity: TakeEntity, type: String, mainInfoId: Long,
fromType: String, longitude: Double, latitude: Double, speed: Float) {
CosCallbackMapController.registerCallback(picPath, this)
// CosLogger.setLogStatus(true)
this.entity = entity
this.mType = type
this.mainInfoId = mainInfoId
this.mFromType = fromType
this.mLongitude = longitude
this.mLatitude = latitude
this.mSpeed = speed
Log.d(TAG, "uploadFile type===$type ---- mainInfoId =$mainInfoId ----mFromType = $mFromType ---- picPath = $picPath --speed = $speed")
trackUploadCos(3)
if(picPath == null){
return
}
if (picPath.contains("backPic")) return
//参数说明: paths本地文件路径上传的本地路径不要重复config文件上传的优先级
mPicEventId =
CosUploadManagerImpl.getInstance(AbsMogoApplication.getApp().applicationContext).eventId
CosUploadManagerImpl.getInstance(AbsMogoApplication.getApp().applicationContext)
.upload(picPath, mPicEventId, DbPriorityConfig.PRIORITY_HIGH)
}
override fun onStartUpload(eventId: String?, localPath: String?) {
}
private fun sendGetInfoFailedReceiver(type: String) {
Log.d(CarCorderController.TAG, "sendGetInfoFailedReceiver ------>")
val intent = Intent()
intent.action = "com.zhidao.roadcondition.getinfo.failed"
intent.putExtra("type", type)
AbsMogoApplication.getApp().applicationContext.sendBroadcast(intent)
}
override fun uploadCosFailed(cosPath: String?, eventId: String?, localPath: String?) {
Log.d(TAG, "uploadCosFailed = $localPath")
trackUploadCos(2)
//语音播报 1上报路况2交通检查3封路 默认 mType 应该为null
if (!isRetry) {
isRetry = true
// taskAsync(30_000) { //去掉重试
// try {
// uploadFile(mutableListOf(localPath as String), entity, mType)
// } catch (e: Exception) {
// e.printStackTrace()
// }
// }
} else {
if (localPath!!.endsWith("mp4") || localPath.contains("Thumbnail")) {
CosCallbackMapController.uploadFailed?.invoke()
}
CosCallbackMapController.unregisterCallback(localPath)
InformationUploadController.release(entity.id)
// deletePicFile(localPath)
deleteCompressVideoFile(moviesDir.toString())
}
}
override fun uploadCosCompleted(
cosPath: String?,
eventId: String?,
downloadUrl: String?,
localPath: String?
) {
Log.d(TAG, "uploadCosCompleted localPath = $localPath")
Log.d(TAG, "uploadCosCompleted downloadUrl = $downloadUrl")
Log.d(TAG, "uploadCosCompleted cosPath = $cosPath")
trackUploadCos(1)
if (localPath!!.endsWith("mp4") || localPath.contains("Thumbnail")) {
//如果是视频文件或者缩略图文件
if (localPath.endsWith("mp4")) {
videoAndThumbMap["video"] = downloadUrl!!
Log.i(TAG, "videoAndThumbMap add mp4")
} else {
videoAndThumbMap["thumb"] = downloadUrl!!
Log.i(TAG, "videoAndThumbMap add thumb")
}
Log.d(TAG, "videoAndThumbMap $videoAndThumbMap")
if (videoAndThumbMap.size == 2) {
trackUploadCos(4)
Log.d(TAG, "videoAndThumbMap.size == 2 ")
val locationInfo = LocationUtil.getInstance().getLocationInfo()
val locationStr: String = Gson().toJson(locationInfo)
Log.d(TAG, "locationStr = $locationStr")
//上传录像以及缩略图成功
sendInformation(INFO_TYPE_VIDEO, videoAndThumbMap)
} else {
trackUploadCos(5)
}
} else {
//上传图片成功, 如果是上报路况,直接上传
Log.d(TAG, "uploadCosCompleted 分享成功 ---- mType = $mType")
sendInformationDirectly(
INFO_TYPE_IMG,
mutableMapOf("pic" to downloadUrl as String),
mType,
entity,
mainInfoId,
mLongitude,
mLatitude,
mSpeed,
mFromType
)
}
Log.d(TAG, "delete file: $localPath")
CosCallbackMapController.unregisterCallback(localPath)
// deletePicFile(localPath)
deleteCompressVideoFile(moviesDir.toString())
}
private fun sendInformation(type: Int, map: Map<String, String>) {
Log.d(TAG, "isCustomSend = ${entity.isCustom}")
// if (entity?.isCustom) {
// InformationUploadController.cosResourceReady(type, map, entity?.isCustom, entity?.id) {
// CosCallbackMapController.mainService?.sendCustomResult(it)
// }
// } else {
sendInformationDirectly(type, map, mType, entity, mainInfoId, mLongitude, mLatitude, mSpeed,mFromType)
// }
}
/**
* 被动上报时直接上报,不用等待、选择情报类型
*/
fun sendInformationDirectly(
type: Int,
map: Map<String, String>,
poiType: String,
entity: TakeEntity?,
mainInfoId: Long,
longitude: Double,
latitude: Double,
speed: Float,
fromType: String
) {
Log.d(TAG, "sendInformationDirectly poiType= $poiType --fromType =$fromType ---- mainInfoId= $mainInfoId --- isCustom = ${entity?.isCustom}")
//开始上传
entity?.isCustom?.let {
mainServiceHttpModel.sendInformationMessage(
fromType = fromType,
type = type,
url = map,
isCustom = it,
poiType = poiType,
mainInfoId = mainInfoId,
speed = speed,
longitude = longitude,
latitude = latitude
) { success ->
CosCallbackMapController.unregisterCallbacks(map)
// CosCallbackMapController.mainService?.let {
// CosCallbackMapController.mainService?.sendCustomResult(success)
// }
Log.d(TAG, "type = $type ----success = $success ----fromType = $mFromType ----poiType = $poiType")
if (success) {
//分享成功并打点如果是上报拥堵需要takeVideo
if (type == INFO_TYPE_VIDEO) {
try {
LatLngStickyEventBus.getInstance()
.postSticky(GetImageSuccessEvent("", poiType))
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
}
} else {
}
}
}
}
override fun onProgress(localPath: String?, progress: Float) {
}
//上传COS
private fun trackUploadCos(type: Int) {
trackNormalEvent(
CarNet_Cos_Upload, mutableMapOf("type" to type),
AbsMogoApplication.getApp().applicationContext
)
}
}

View File

@@ -1,67 +0,0 @@
package com.zhidao.roadcondition.service
import android.app.IntentService
import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.util.Log
import com.zhidao.roadcondition.util.*
import java.io.File
import java.lang.Exception
class DelayService : IntentService("DelayService") {
companion object {
const val TAG = "DelayService"
fun launchService(context: Context) {
context.startService(Intent(context, DelayService::class.java))
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
override fun onCreate() {
super.onCreate()
}
override fun onStart(intent: Intent?, startId: Int) {
super.onStart(intent, startId)
}
override fun onBind(intent: Intent?): IBinder? {
return super.onBind(intent)
}
override fun setIntentRedelivery(enabled: Boolean) {
super.setIntentRedelivery(enabled)
}
override fun onDestroy() {
super.onDestroy()
}
override fun onHandleIntent(intent: Intent?) {
Log.d(TAG, "start delay ----> ")
taskAsync(20_000) {
try {
Log.d(TAG, "delay finish, start Service")
// MainService.launchService(this@DelayService, "0")
//删除一个原始视频(可能没删除的)文件夹下的所有文件(包括子目录内的文件)
val file = File("/mnt/sdcard/DCIM/Camera/video/small/") //输入要删除文件目录的绝对路径
deleteAllFile(file)
val compressFile = File("/mnt/sdcard/Movies/") //压缩过的视频
deleteAllFile(compressFile)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}

View File

@@ -1,124 +0,0 @@
package com.zhidao.roadcondition.service
import android.util.Log
import com.zhidao.roadcondition.model.InformationResource
import com.zhidao.roadcondition.model.InformationType
import com.zhidao.roadcondition.util.*
/**
* @author congtaowang
* @since 2019-11-20
*
* 情报上报控制
*/
object InformationUploadController {
private val TAG : String = this.javaClass.simpleName
private var mainServiceHttpModel = MainServiceController()
private val locker: Any = Any()
/**
* 情报
* Long -> 一个情报的id
* InformationResource -> 一个情报的资源
*/
private val informationCache = mutableMapOf<Long, InformationResource>()
/**
* 情报已上传到cos
*/
fun cosResourceReady(
sourceType: Int,
cosParameter: Map<String, String>,
isCustomSend: Boolean,
id: Long,
callback: ((customSend: Boolean) -> Unit)
) {
Log.d(TAG, "cos resource ready. id=${id}")
val ir = getInformationResourceById(id)
ir?.let {
it.isCosResourceReady = true
it.sourceType = sourceType
it.cosParameter = cosParameter
it.isCustomSend = isCustomSend
it.callback = callback
// tryUploadInformation(it)
}
}
private fun getInformationResourceById(id: Long): InformationResource? {
if (!informationCache.containsKey(id)) {
informationCache[id] = InformationResource(id)
}
return informationCache[id]
}
/**
* 已选择情报类型
*/
fun informationSelected(
informationType: InformationType,
newsType: String,
operType: String,
id: Long
) {
Log.d(TAG, "information type selected id=${id}, type=${informationType}")
val ir = getInformationResourceById(id)
ir?.let {
it.isInformationSelected = true
it.informationType = informationType
it.newsType = newsType
it.operType = operType
// tryUploadInformation(it)
}
}
// private fun tryUploadInformation(ir: InformationResource?) {
// synchronized(locker) {
// ir?.let {
// if (!it.isReady()) {
// log(TAG, "source isn't ready.")
// return@let
// }
// mainServiceHttpModel.sendInformationMessage(
// it.sourceType,
// it.cosParameter!!,
// it.isCustomSend,
// it.informationType?.dictValue!!,
// isShare = true
// ) { success ->
// log(TAG, "上传成功!" + ir?.toString())
// trackNormalEvent(
// CarNet_user_upload,
// mutableMapOf(
// TRACK_KEY_TYPE to it.operType,
// TRACK_KEY_NEWS_TYPE to it.newsType
// )
// )
// if (it.isCustomSend) {
// it.callback?.invoke(success)
// }
// informationCache.remove(it.id)
// it.release()
// recordUploadTime()
// }
// }
// }
// }
fun release(id: Long) {
val target = informationCache.remove(id)
target?.release()
}
private fun recordUploadTime() {
putLong("lastUploadTime", System.currentTimeMillis())
}
fun isUpload2Frequently(): Boolean {
val lastUploadTime = getLong("lastUploadTime", 0L)
return System.currentTimeMillis() - lastUploadTime < 10_000L
}
}

View File

@@ -1,255 +0,0 @@
package com.zhidao.roadcondition.service
import android.content.Intent
import android.util.Log
import com.mogo.commons.AbsMogoApplication
import com.zhidao.roadcondition.model.*
import com.zhidao.roadcondition.net.request
import com.zhidao.roadcondition.util.*
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyFrequency
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyInterval
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyMaxSpeed
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyMinSpeed
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyType
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyValidity
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class MainServiceController {
companion object {
const val TAG = "MainServiceController"
}
//逆地理编码是否重试
private var geoRetry = false
private var mFromType: String = ""
private var mPoiType: String = ""
private val strategyModel by lazy { StrategyServiceModel() }
fun initStrategies(initFinish: (() -> Unit)? = null) {
request<BaseResponse<Results>> {
loader {
strategyModel.getCityStrategy()
}
onSuccess {
it.result.let { strategy ->
trackNormalEvent(CarNet_Get_Strategy, null)
Log.d(TAG, "pic =" + strategy.cityStrategy.pic)
Log.d(TAG, "video =" + strategy.cityStrategy.video)
syncStrategiesData(strategy.cityStrategy)
initFinish?.invoke()
}
}
onError {
reInitStrategies()
Log.e(TAG, "initStrategies onError ${it.message}")
}
}
}
private fun reInitStrategies() = runBlocking {
launch {
// delay(30_000)
initStrategies()
}
}
//将数据同步到sharePreference中
private fun syncStrategiesData(strategy: CityStrategy) {
if (strategy.pic != null && strategy.video!=null) {
setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.pic!!.strategyType, "pic")
setStrategyType(AbsMogoApplication.getApp().applicationContext, strategy.video!!.strategyType, "video")
setStrategyFrequency(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.reportType
)
setStrategyFrequency(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.reportType
)
setStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.reportTimeInterval * 60 * 1000L
)
setStrategyInterval(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.reportTimeInterval * 60 * 1000L
)
setStrategyValidity(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.infoTimeout
)
setStrategyValidity(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.infoTimeout
)
setStrategyMaxSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.getMaxSpeed()
)
setStrategyMaxSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.getMaxSpeed()
)
setStrategyMinSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.pic!!.strategyType,
"pic",
strategy.pic!!.minSpeed
)
setStrategyMinSpeed(
AbsMogoApplication.getApp().applicationContext,
strategy.video!!.strategyType,
"video",
strategy.video!!.minSpeed
)
} else {
Log.d(TAG, "strategy Data is null")
}
}
//上传情报数据
fun sendInformationMessage(
fromType: String,
type: Int,
url: Map<String, String>,
isCustom: Boolean = false,
trafficInfoType:String = "",
isShare:Boolean = false,
poiType:String,
mainInfoId:Long,
speed: Float,
longitude: Double,
latitude: Double,
customSend: ((Boolean) -> Unit)? = null
) {
Log.d(TAG, " sendInformationMessage poiType = $poiType -- fromType = $fromType")
mFromType = fromType
mPoiType = poiType
val locationInfo = LocationUtil.getInstance().getLocationInfo()
if (locationInfo.address.isEmpty()) {
Log.d(TAG, " sendInformationMessage locationInfo.address = $locationInfo.address")
trackUploadGeo(1)
geoLocation(type, url, locationInfo, isCustom,trafficInfoType, isShare, customSend,poiType,mainInfoId,speed, longitude,latitude)
} else {
postInformationMessage(
getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare,poiType,mainInfoId,longitude,latitude, speed, mFromType),
customSend
)
}
}
//如果address为空则逆地理编码
private fun geoLocation(
type: Int,
url: Map<String, String>,
locationInfo: LocationInfo,
isCustom: Boolean,
trafficInfoType:String,
isShare: Boolean,
customSend: ((Boolean) -> Unit)? = null,
poiType: String,
mainInfoId: Long,
speed: Float,
longitude: Double,
latitude: Double
) {
Log.d(TAG, " geoLocation -- poiType = $poiType")
LocationUtil.getInstance()
.geoCodeLocation(locationInfo.toLatLngPoint(), {
Log.d(TAG, "geoLocation -------start -->")
postInformationMessage(
getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude, speed, mFromType),
customSend
)
}, {
//转换失败的情况下再重试一次
Log.d(TAG, "geoLocation -------true-->")
geoRetry = if (!geoRetry) {
geoLocation(type, url, locationInfo, isCustom, trafficInfoType, isShare, customSend, poiType,mainInfoId,speed, longitude,latitude)
true
} else {
//如果两次都失败,直接上报服务端
Log.d(TAG, "geoLocation ---- postInformationMessage ---false-->")
postInformationMessage(
getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude,speed, mFromType),
customSend
)
false
}
})
}
private fun postInformationMessage(
informationBody: InformationBody,
customSend: ((Boolean) -> Unit)? = null
) {
trackUploadServer(3)
request<BaseResponse<UploadResult>> {
loader {
strategyModel.uploadInformation(informationBody)
}
onSuccess {
Log.i(TAG, "upload success id = " + it.result.id)
if (mFromType == "6") {
sendUgcStatusReceiver(it.result.id, mPoiType, mFromType)
}
trackUploadServer(1)
customSend?.invoke(true)
}
onError {
Log.i(TAG, "$it upload message ${it.message}")
trackUploadServer(2)
if (mFromType == "6") {
sendUgcStatusReceiver(0, mPoiType, mFromType)
}
customSend?.invoke(false)
}
}
}
private fun sendUgcStatusReceiver(id: Long, type: String?, fromType: String?) {
Log.d(TAG, "sendUgcStatusReceiver id = $id ---type = $type --fromType = $fromType ")
val intent = Intent()
intent.action = "com.v2x.ugc.upload.status"
intent.putExtra("id", id)
intent.putExtra("type", type)
intent.putExtra("fromType", fromType)
AbsMogoApplication.getApp().applicationContext.sendBroadcast(intent)
}
//上传服务器
private fun trackUploadServer(type: Int) {
trackNormalEvent(
CarNet_Servers_Upload, mutableMapOf("type" to type)
)
}
//上传
private fun trackUploadGeo(type: Int) {
trackNormalEvent(
CarNet_Geo, mutableMapOf("type" to type)
)
}
}

View File

@@ -1,8 +0,0 @@
package com.zhidao.roadcondition.service
val AlarmTypePic: Int = 1 //定时任务类型 1照片
val AlarmTypeVideo: Int = 2 //定时任务类型 2视频
val alarmBroadAction: String = "com.zhidao.roadCondition.AlarmBroadCast" //定时广播
val sendInformationAction: String = "com.zhidao.roadCondition.SendInformation" //主动上报广播
val customResultAction: String = "com.zhidao.roadCondition.CustomResult" //主动上报结果广播

View File

@@ -1,14 +0,0 @@
package com.zhidao.roadcondition.service
import com.zhidao.auto.carcorder.callback.TakePhotoCallback
/**
* @author congtaowang
* @since 2019-11-19
*
* 拍照拦截器
*/
interface TakePhotoInterceptor : TakePhotoCallback {
fun intercept(): Boolean
}

View File

@@ -54,7 +54,6 @@ include ':libraries:map-autonavi'
include ':libraries:mogo-map'
// OLD业务模块
include ':modules:tanlulib'
include ':modules:mogo-module-monitor'
include ':modules:mogo-module-adas'
include ':modules:mogo-module-map'