buffer time initial commit
This commit is contained in:
parent
22be792a53
commit
704d63ed1b
2 changed files with 25 additions and 5 deletions
|
@ -61,6 +61,9 @@ private const val MIN_LOCATION_DISTANCE_INDEX = 0
|
||||||
private const val MIN_LOCATION_ACCURACY_INDEX = 0
|
private const val MIN_LOCATION_ACCURACY_INDEX = 0
|
||||||
private const val MIN_LOCATION_SPEED_INDEX = 0
|
private const val MIN_LOCATION_SPEED_INDEX = 0
|
||||||
|
|
||||||
|
private const val MIN_BUFFER_TIME = 60 * 1L // 1 minute for test
|
||||||
|
private const val BUFFER_TIME_KEY = "buffer_time"
|
||||||
|
|
||||||
private const val SETTINGS_NAME = "osmand_telegram_settings"
|
private const val SETTINGS_NAME = "osmand_telegram_settings"
|
||||||
|
|
||||||
private const val SHARE_LOCATION_CHATS_KEY = "share_location_chats"
|
private const val SHARE_LOCATION_CHATS_KEY = "share_location_chats"
|
||||||
|
@ -152,6 +155,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
|
|
||||||
var proxyEnabled = false
|
var proxyEnabled = false
|
||||||
|
|
||||||
|
var bufferTime = MIN_BUFFER_TIME
|
||||||
|
|
||||||
init {
|
init {
|
||||||
updatePrefs()
|
updatePrefs()
|
||||||
read()
|
read()
|
||||||
|
|
|
@ -25,7 +25,7 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
dbHelper = SQLiteHelper(app)
|
dbHelper = SQLiteHelper(app)
|
||||||
readBufferedMessages()
|
readBufferedMessages(app.settings.bufferTime)
|
||||||
readLastMessages()
|
readLastMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +140,8 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
dbHelper.removeBufferedMessage(message)
|
dbHelper.removeBufferedMessage(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readBufferedMessages() {
|
private fun readBufferedMessages(bufferTime: Long) {
|
||||||
this.bufferedMessages = dbHelper.getBufferedMessages()
|
this.bufferedMessages = dbHelper.getBufferedMessages(bufferTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readLastMessages() {
|
private fun readLastMessages() {
|
||||||
|
@ -293,7 +293,7 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun getBufferedMessages(): List<BufferMessage> {
|
internal fun getBufferedMessages(bufferTime: Long): List<BufferMessage> {
|
||||||
val res = arrayListOf<BufferMessage>()
|
val res = arrayListOf<BufferMessage>()
|
||||||
readableDatabase?.rawQuery(BUFFER_TABLE_SELECT, null)?.apply {
|
readableDatabase?.rawQuery(BUFFER_TABLE_SELECT, null)?.apply {
|
||||||
if (moveToFirst()) {
|
if (moveToFirst()) {
|
||||||
|
@ -303,7 +303,22 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
return res
|
return removeOldBufferedMessages(res, bufferTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun removeOldBufferedMessages(list: List<BufferMessage>, bufferTime: Long): List<BufferMessage> {
|
||||||
|
log.info("removeOldBufferedMessages" )
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
val cleanedList = arrayListOf<BufferMessage>()
|
||||||
|
list.forEach { message ->
|
||||||
|
if (currentTime - message.time > bufferTime) {
|
||||||
|
removeBufferedMessage(message)
|
||||||
|
log.debug("remove old buffered message: $message" )
|
||||||
|
} else {
|
||||||
|
cleanedList.add(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cleanedList
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun getLastMessages(): MutableList<LocationMessage> {
|
internal fun getLastMessages(): MutableList<LocationMessage> {
|
||||||
|
|
Loading…
Reference in a new issue