修复gps轨迹数据不对问题

This commit is contained in:
刘金华 2023-09-11 17:54:27 +08:00
parent d5b1814ae2
commit 029f148bd8
28 changed files with 204 additions and 79 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,2 @@
#Mon Aug 28 09:56:58 GMT+08:00 2023
gradle.version=5.6.4

Binary file not shown.

View File

View File

@ -21,8 +21,8 @@ android {
applicationId "net.sysolution.taxiapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 229
versionName "3.3.3-beta26.3.9.3.5-release"
versionCode 235
versionName "3.3.3-beta26.3.9.3.92-release"
//alphaxx - ,bug
//Betaxx -
@ -55,7 +55,7 @@ android {
26.3.8.3 taxiApp刷新列表时广,广regions也加入缓存机制
26.3.8.6.9 38s
26.3.9 webSocket的连接保活代码gps坐标记录两个点的距离由原来的50米记录一次改为20米记录一次
26.3.9.3.5
26.3.9.3.6
**/
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -22,6 +22,7 @@ import cn.trans88.taxiappkotlin.net.BizInterceptor
import cn.trans88.taxiappkotlin.ui.custom.JVideoView
import cn.trans88.taxiappkotlin.ui.play.PlayActivity
import cn.trans88.taxiappkotlin.util.DateUtil
import cn.trans88.taxiappkotlin.util.KuroTimer
import cn.trans88.taxiappkotlin.util.YoungUtil
import com.facebook.stetho.Stetho
import com.google.gson.Gson
@ -44,6 +45,7 @@ class TaxiApp:Application() {
//缓存数据库所有广告
var daoAds:CopyOnWriteArrayList<Advertise> = CopyOnWriteArrayList()
var cacheDaoAds: ArrayList<Advertise> = ArrayList()
//缓存数据库regions
var regionsList:CopyOnWriteArrayList<Regions> = CopyOnWriteArrayList()
@ -62,6 +64,9 @@ class TaxiApp:Application() {
var timedAds:ArrayList<Advertise> = ArrayList()
var activity:PlayActivity? = null
//日志定时器
var gpsTimer: KuroTimer? = null
var testCount = 0
val TAG = "TaxiApp"
val poolSize = Runtime.getRuntime().availableProcessors()*2+1

View File

@ -338,10 +338,18 @@ object Repository {
//#edit by ljh @2023/8/7
val daoAdvertises:List<Advertise> = if (taxiApp.daoAds.isNotEmpty()){
"从缓存获取广告列表.数量:${taxiApp.daoAds.size}".logd()
taxiApp.daoAds.sortByDescending {
// taxiApp.daoAds.sortByDescending {
// it.createAt
// }
// taxiApp.daoAds
taxiApp.cacheDaoAds.clear()
for (daoAd in taxiApp.daoAds) {
taxiApp.cacheDaoAds.add(daoAd)
}
taxiApp.cacheDaoAds.sortByDescending {
it.createAt
}
taxiApp.daoAds
taxiApp.cacheDaoAds
} else {
// val currentAds = DaoUtil.getAdvertise().queryBuilder().orderDesc(AdvertiseDao.Properties.CreateAt).list()
lazyList = DaoUtil.getAdvertise().queryBuilder().orderDesc(AdvertiseDao.Properties.CreateAt).listLazyUncached()
@ -352,10 +360,10 @@ object Repository {
}
"存储的广告数量:${daoAdvertises.size}".loge()
//edit by ljh @2023/9/1
if (daoAdvertises.size == 0){
"卡里没广告了,清除排序".logd()
Configurations.config(TaxiApp.instance()).advertiseOrderSave("")
}
// if (daoAdvertises.size == 0){
// "卡里没广告了,清除排序".logd()
// Configurations.config(TaxiApp.instance()).advertiseOrderSave("")
// }
val advertises = mutableListOf<Advertise>()
//定点广告list
//#edit by ljh @2023/8/11

View File

@ -173,6 +173,8 @@ object ConnManger {
if (!registerToken.equals(defaultToken)){
"is not defaultToken,save message to conn.".loge()
initConnectMessage()
//测试平台要加
// setServerToConn()
} else {
//是默认账号看看conn有没保存信息如果有则重新注册一遍
if (connService != null){
@ -214,6 +216,54 @@ object ConnManger {
// }
}
/**
* 给conn设置凭证信息和服务地址
*/
fun setServerToConn(){
val serverWebSocketUrl = Configurations.config(TaxiApp.instance()).taxiServiceUrl()
val serverUrl = Configurations.config(TaxiApp.instance()).taxiBaseUrl()
connService?.let {
try {
if (serverWebSocketUrl.isNotEmpty()){
"setConnWebSocketUrl:${serverWebSocketUrl}".loge()
setConnWebSocketUrl(serverWebSocketUrl)
} else {
"setConnServiceUrl:${serverUrl}".loge()
setConnServiceUrl(serverUrl)
}
} catch (e:Exception) {
"给conn设置服务地址失败,failed set conn server,e.message:${e.message}".loge()
}
}
}
/**
* 给conn设置地址
* @param url String
*/
private fun setConnWebSocketUrl(url: String){
val sb = StringBuilder()
val split = url.split(":")
sb.apply {
if (url.contains("ws") || url.contains("wss")){
append("http:")
if (split[2].isNotEmpty() && split[2].length > 5){
append(split[2])
} else {
append(split[1])
sb.append(":2340")
}
} else {
append(url)
}
}
"conn webSocketUrl:${sb.toString()}".loge()
connService?.let {
val str = it.setServerURL(sb.toString())
"设置conn服务器成功conn response:$str".loge()
}
}
/**
* 初始化connectMessage并传给conn
*/
@ -374,21 +424,26 @@ object ConnManger {
}
/**
* 发送坐标
* 提交gps坐标
*/
fun sendLocation() {
fun sendLocationToWeb(){
YoungUtil.YoungLog("sendLocation in MainThread is ${Looper.getMainLooper().thread === Thread.currentThread()}")
//todo 如果这里突然有大量的信息序列化是不是同样会内存溢出
// val locations = DaoUtil.getLocations()
//如果这里突然有大量的信息序列化是不是同样会内存溢出
val locations = DaoUtil.getLocations()
//edit by ljh @2023/8/8 每次只查20条定点数据防止数据量大导致内存爆满
val locations = DaoUtil.getLocationDao().queryBuilder().limit(20).list()
// val locations = DaoUtil.getLocationDao().queryBuilder().limit(20).list()
if (locations.isNotEmpty()) {
val requestJson: String = if (locations.size < 20) {
ProcessingCommands.gson.toJson(locations)
} else {
ProcessingCommands.gson.toJson(locations.subList(0, 19))
}
// val requestJson: String = if (locations.size < 20) {
// ProcessingCommands.gson.toJson(locations)
// } else {
// ProcessingCommands.gson.toJson(locations.subList(0, 19))
// }
val requestJson: String = ProcessingCommands.gson.toJson(locations)
//日志存卡里
// taxiApp.saveLog("上传的坐标信息:$requestJson")
val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
val body = RequestBody.create(parse, requestJson)
@ -406,15 +461,17 @@ object ConnManger {
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
YoungUtil.YoungLog("上传坐标失败:${e.message}")
//日志存卡里
// taxiApp.saveLog("上传坐标失败,不删除失败的数据")
// DaoUtil.getLocationDao().deleteAll()
}
override fun onResponse(call: Call, response: Response) {
YoungUtil.YoungLog("上传坐标成功:${response.message},response is Sussceful ${response.isSuccessful}${response.code}")
if (response.code == 200) {
for (location in locations) {
DaoUtil.getLocationDao().delete(location)
}
// for (location in locations) {
// DaoUtil.getLocationDao().delete(location)
// }
// if (locations.size < 20) {
// DaoUtil.getLocationDao().deleteAll()
// } else {
@ -422,32 +479,49 @@ object ConnManger {
// DaoUtil.getLocationDao().delete(locations[index])
// }
// }
DaoUtil.getLocationDao().deleteAll()
//日志存卡里
// taxiApp.saveLog("上传坐标成功,删除上传成功的坐标:${locations.toString()}")
}
}
})
}
}
/**
* 发送坐标
*/
fun sendLocation() {
synchronized(ConnManger::class.java){
taxiApp.gpsTimer?.let {
it.cancel()
it.purge()
}
//edit by yzd @20211201
//if (Settings.gpsSwitch) {
if (Configurations.config(TaxiApp.instance()).gpsSwitch()) {
// "gpsSwitch on".loge()
val timer = KuroTimer()
timer.schedule(object : KuroTimerTask() {
"gpsSwitch on".loge()
taxiApp.gpsTimer = KuroTimer()
taxiApp.gpsTimer?.schedule(object : KuroTimerTask() {
override fun run() {
sendLocation()
sendLocationToWeb()
// sendLocation()
}
}, 10000)
}, 0,10000)
} else {
"gpsSwitch off".loge()
val timer = KuroTimer()
timer.schedule(object : KuroTimerTask() {
taxiApp.gpsTimer = KuroTimer()
taxiApp.gpsTimer?.schedule(object : KuroTimerTask() {
override fun run() {
sendLocation()
sendLocationToWeb()
// sendLocation()
}
}, 0,60 * 60 * 1000)
}
}
}
}, 60 * 60 * 1000)
}
}
/**
* 播放次数到了发送终止广告指令
@ -567,6 +641,7 @@ object ConnManger {
})
}
var loggerTimer:KuroTimer? = null
/**
* 发送播放日志
*/
@ -629,9 +704,10 @@ object ConnManger {
})
}
val timer = KuroTimer()
timer.schedule(object : KuroTimerTask() {
loggerTimer = KuroTimer()
loggerTimer?.schedule(object : KuroTimerTask() {
override fun run() {
"loggerTimer task started".logd()
sendLogger()
}
}, 30000)

View File

@ -36,7 +36,6 @@ object ProcessingCommands {
var areaIndex = 0
/**
* 三乐平台的命令
*/
@ -48,6 +47,12 @@ object ProcessingCommands {
YoungUtil.YoungLog("baskTask :${baseTask.toString()}")
if (baseTask.type != null) {
//日志存卡里
// if (!("beat_reply".equals(baseTask.type))){
// taxiApp.saveLog(baseTask.toString())
// }
val task = baseTask.task.toString()
when (baseTask.type) {
//添加普通广告
@ -108,6 +113,9 @@ object ProcessingCommands {
//Settings.gpsSwitch =gpsSwitch.isTurn_on
Configurations.config(TaxiApp.instance()).gpsSwitchSave(gpsSwitch.isTurn_on)
if (gpsSwitch.isTurn_on){
//edit by ljh @2023/9/7
// ConnManger.gpsTimer?.cancel()
// ConnManger.gpsTimer?.purge()
ConnManger.sendLocation()
}
@ -168,6 +176,8 @@ object ProcessingCommands {
//Settings.loggerSwitch =loggerSwitch.isTurn_on
Configurations.config(TaxiApp.instance()).loggerSwitchSave(loggerSwitch.isTurn_on)
if (loggerSwitch.isTurn_on){
ConnManger.loggerTimer?.cancel()
ConnManger.loggerTimer?.purge()
ConnManger.sendLogger()
}
@ -303,36 +313,39 @@ object ProcessingCommands {
private fun clearAdvertiseOrder(task: String, type: String?) {
val advertiseOrder = gson.fromJson<AdvertiseOrder>(task)
"clearAdvertiseOrder".logd()
//日志存卡里
// taxiApp.saveLog("收到了清空排序指令...")
//Settings.advertiseOrder = ""
//edit by ljh @2023/8/9/1
//三分钟内收到两次清除排序才会清除排序,防止排序被清除
taxiApp.isDoubleClearOrder += 1
if(taxiApp.isDoubleClearOrder < 2){
"没有点击两次清空排序,开始计时三分钟".logd()
taxiApp.clearOrderTimer.schedule(object :TimerTask(){
override fun run() {
try {
taxiApp.isDoubleClearOrder = 0
"三分钟时间到isDoubleClearOrder重置".logd()
} catch (e:java.lang.Exception){
e.printStackTrace()
}
}
},3*60*1000L)
} else {
"点击了两次清空排序,取消三分钟计时并清空排序".logd()
taxiApp.clearOrderTimer.cancel()
taxiApp.clearOrderTimer.purge()
taxiApp.clearOrderTimer = Timer()
Configurations.config(TaxiApp.instance()).advertiseOrderSave("")
taxiApp.isDoubleClearOrder = 0
}
// taxiApp.isDoubleClearOrder += 1
// if(taxiApp.isDoubleClearOrder < 2){
// "没有点击两次清空排序,开始计时三分钟".logd()
// taxiApp.clearOrderTimer.schedule(object :TimerTask(){
// override fun run() {
// try {
// taxiApp.isDoubleClearOrder = 0
// "三分钟时间到isDoubleClearOrder重置".logd()
// } catch (e:java.lang.Exception){
// e.printStackTrace()
// }
// }
// },3*60*1000L)
// } else {
// "点击了两次清空排序,取消三分钟计时并清空排序".logd()
// taxiApp.clearOrderTimer.cancel()
// taxiApp.clearOrderTimer.purge()
// taxiApp.clearOrderTimer = Timer()
// Configurations.config(TaxiApp.instance()).advertiseOrderSave("")
// taxiApp.isDoubleClearOrder = 0
// RefreshPlayer.refresh()
// }
//edit by ljh @2023/8/22
// taxiApp.saveLog("clearAdvertiseOrder清除了广告排序")
RefreshPlayer.refresh()
Configurations.config(TaxiApp.instance()).advertiseOrderSave("")
val sanleResponse = SanleResponse()
sanleResponse.task_id = advertiseOrder.task_id
@ -340,6 +353,10 @@ object ProcessingCommands {
sanleResponse.type = type
val response = gson.toJson(sanleResponse)
send(response)
RefreshPlayer.refresh()
}
/**

View File

@ -78,6 +78,8 @@ object WsManager {
} else {
this.removeMessages(10)
"没收到心跳回复主动断线重连".logd()
//日志存卡里
// Repository.taxiApp.saveLog("30s过去了发了心跳信息没收到心跳回复主动断线重连...")
ProcessingCommands.beatTimer?.cancel()
ProcessingCommands.beatTimer?.purge()
// ProcessingCommands.beatTimer = null
@ -101,6 +103,7 @@ object WsManager {
.url("${Configurations.config(TaxiApp.instance()).taxiServiceUrl()}?auth_token=${Configurations.config(TaxiApp.instance()).appToken()}")
// .url("http://192.168.1.141:2347/?auth_token=${Configurations.config(TaxiApp.instance()).appToken()}")
// .url("http://1vf5fnic.beesnat.com/?auth_token=${Configurations.config(TaxiApp.instance()).appToken()}")
// .url("http://twan718b.beesnat.com/?auth_token=${Configurations.config(TaxiApp.instance()).appToken()}")
// .url("http://192.168.43.191:2347/?auth_token=${Configurations.config(TaxiApp.instance()).appToken()}")
.build()
@ -254,6 +257,8 @@ object WsManager {
override fun onOpen(webSocket: WebSocket, response: Response) {
super.onOpen(webSocket, response)
YoungUtil.YoungLog("onOpen: connecting is open Ws连接成功!")
//日志存卡里
// Repository.taxiApp.saveLog("onOpen: connecting is open Ws连接成功!")
mWebSocket = webSocket
//edit by ljh @2023/8/16
@ -263,6 +268,8 @@ object WsManager {
heartHandler.removeMessages(10)
heartHandler.sendEmptyMessage(10)
// sendCurrentAdvertise()
}
}
}
@ -292,6 +299,8 @@ object WsManager {
* 重连
*/
private fun tryReconnect() {
//日志存卡里
// Repository.taxiApp.saveLog("webSocket开始重连...")
isRegister = false
@ -342,6 +351,11 @@ object WsManager {
fun send(msg: String) {
YoungUtil.YoungLog("回复服务器 $msg")
//日志存卡里
// if(!(heartbeatContext.equals(msg))){
// Repository.taxiApp.saveLog("回复服务器 $msg")
// }
mWebSocket?.send(msg)
// mWebSocket?.send(msg) ?: throw IllegalArgumentException("mWebSocket is null not send!")
}
@ -419,7 +433,9 @@ object WsManager {
val currentAdvertises = Gson().toJson(currentPlayAdvertise)
YoungUtil.YoungLog("当前在播放的广告: $currentAdvertises")
if(isConnected){
mWebSocket?.send(currentAdvertises) ?: throw IllegalArgumentException("mWebSocket is null not send!")
}
sendCurrentAdvertiseTimer?.let {
it.cancel()

View File

@ -473,7 +473,7 @@ class PlayActivity : AppCompatActivity(), NetworkCallback, BusCallback, OnScreen
RefreshPlayer.refresh()
}
MainHandler.postDelay(10 * 60 * 1000, Runnable {
MainHandler.postDelay(20 * 60 * 1000, Runnable {
timeRefreshAdvertise()
})
}

View File

@ -873,7 +873,7 @@ class PlayViewModel(val lifecycle: Lifecycle, private val fl_play: FrameLayout,
} else {
//YoungUtil.YoungLog("当前坐标 latitude:$latitude,longitude: $longitude , 速度 :$speed")
//保存坐标地址
YoungUtil.YoungLog("保存坐标")
YoungUtil.YoungLog("开始保存坐标")
curLongitude = longitude
curlatitude = latitude
@ -1030,7 +1030,8 @@ class PlayViewModel(val lifecycle: Lifecycle, private val fl_play: FrameLayout,
distance = 0.0f
elapse = 0
}
DaoUtil.getLocationDao().insert(location)
//不保存距离为0的点 edit by ljh @2023/9/9
// DaoUtil.getLocationDao().insert(location)
curLocation = location
} else {
if (curLocation?.longitude?.toDouble() != longitude || curLocation?.latitude?.toDouble() != latitude) {

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":229,"versionName":"3.3.3-beta26.3.9.3.5-debug","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.5-debug{229}.apk","fullName":"debug","baseName":"debug","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.5-debug{229}.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":235,"versionName":"3.3.3-beta26.3.9.3.92Local-debug","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.92Local-debug{235}.apk","fullName":"debug","baseName":"debug","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.92Local-debug{235}.apk","properties":{}}]

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Aug 28 09:57:51 GMT+08:00 2023
#Thu Sep 07 10:09:52 GMT+08:00 2023
sdk.dir=D\:\\Android\\sdk

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":229,"versionName":"3.3.3-beta26.3.9.3.5-release","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.5-release{229}.apk","fullName":"release","baseName":"release","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.5-release{229}.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":235,"versionName":"3.3.3-beta26.3.9.3.92-release","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.92-release{235}.apk","fullName":"release","baseName":"release","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.92-release{235}.apk","properties":{}}]