LocationMessages fixes. Added todos.
This commit is contained in:
parent
f652e2f256
commit
430ceb10ae
9 changed files with 133 additions and 106 deletions
|
@ -13,7 +13,7 @@ import android.os.*
|
|||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import net.osmand.PlatformUtil
|
||||
import net.osmand.telegram.helpers.LocationMessages
|
||||
import net.osmand.telegram.helpers.LocationMessages.LocationMessage
|
||||
import net.osmand.telegram.helpers.TelegramHelper.TelegramIncomingMessagesListener
|
||||
import net.osmand.telegram.helpers.TelegramHelper.TelegramOutgoingMessagesListener
|
||||
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
|
||||
|
@ -277,9 +277,9 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
|||
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
|
||||
app().showLocationHelper.startShowMessagesTask(chatId, *messages)
|
||||
messages.forEach {
|
||||
val locationMessage = OsmandLocationUtils.parseMessage(it, app().telegramHelper, LocationMessages.LocationMessage.STATUS_INCOMING)
|
||||
val locationMessage = OsmandLocationUtils.parseMessage(it, app().telegramHelper, LocationMessage.STATUS_PREPARED)
|
||||
if (locationMessage != null) {
|
||||
app().locationMessages.addLocationMessage(locationMessage)
|
||||
app().locationMessages.addIngoingMessage(locationMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,105 +5,116 @@ import android.database.Cursor
|
|||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class LocationMessages(val app: TelegramApplication) {
|
||||
|
||||
private val locationMessages = ArrayList<LocationMessage>()
|
||||
// todo - bufferedMessages is for prepared/pending messages only. On app start we read prepared/pending messages to bufferedMessages. After status changed to sent/error - remove message from buffered.
|
||||
private var bufferedMessages = emptyList<LocationMessage>()
|
||||
|
||||
private val sqliteHelper: SQLiteHelper
|
||||
private val dbHelper: SQLiteHelper
|
||||
|
||||
init {
|
||||
sqliteHelper = SQLiteHelper(app)
|
||||
readMessages()
|
||||
dbHelper = SQLiteHelper(app)
|
||||
readBufferedMessages()
|
||||
}
|
||||
|
||||
fun getLocationMessages(): List<LocationMessage> {
|
||||
return this.locationMessages
|
||||
}
|
||||
|
||||
fun getPreparedToShareMessages(): List<LocationMessage> {
|
||||
fun getPreparedMessages(): List<LocationMessage> {
|
||||
val currentUserId = app.telegramHelper.getCurrentUserId()
|
||||
return locationMessages.filter { it.userId == currentUserId && it.status == LocationMessage.STATUS_PREPARED }.sortedBy { it.date }
|
||||
return bufferedMessages.filter { it.userId == currentUserId && it.status == LocationMessage.STATUS_PREPARED }.sortedBy { it.date }
|
||||
}
|
||||
|
||||
fun getOutgoingMessagesToChat(chatId: Long): List<LocationMessage> {
|
||||
// todo - drop method. add collected / sent messages count to ShareChatInfo
|
||||
fun getOutgoingMessages(chatId: Long): List<LocationMessage> {
|
||||
val currentUserId = app.telegramHelper.getCurrentUserId()
|
||||
return locationMessages.filter { it.userId == currentUserId && it.chatId == chatId }.sortedBy { it.date }
|
||||
return bufferedMessages.filter { it.userId == currentUserId && it.chatId == chatId }.sortedBy { it.date }
|
||||
}
|
||||
|
||||
fun getOutgoingMessagesToChatFromDate(chatId: Long, date:Long): List<LocationMessage> {
|
||||
// todo - drop it or read from db
|
||||
fun getSentMessages(chatId: Long, date:Long): List<LocationMessage> {
|
||||
val currentUserId = app.telegramHelper.getCurrentUserId()
|
||||
return locationMessages.filter { it.userId == currentUserId && it.chatId == chatId && it.date > date }.sortedBy { it.date }
|
||||
return bufferedMessages.filter { it.userId == currentUserId && it.chatId == chatId && it.date > date }.sortedBy { it.date }
|
||||
}
|
||||
|
||||
fun getSentOutgoingMessagesToChat(chatId: Long): List<LocationMessage> {
|
||||
// todo - drop it or read from db
|
||||
fun getSentMessages(chatId: Long): List<LocationMessage> {
|
||||
val currentUserId = app.telegramHelper.getCurrentUserId()
|
||||
return locationMessages.filter { it.userId == currentUserId && it.chatId == chatId && it.status == LocationMessages.LocationMessage.STATUS_SENT }.sortedBy { it.date }
|
||||
return bufferedMessages.filter { it.userId == currentUserId && it.chatId == chatId && it.status == LocationMessage.STATUS_SENT }.sortedBy { it.date }
|
||||
}
|
||||
|
||||
fun getIncomingMessages(): List<LocationMessage> {
|
||||
return locationMessages.filter { it.status != LocationMessage.STATUS_INCOMING }.sortedBy { it.date }
|
||||
// todo - read from db by date (Victor's suggestion - filter by one day only. Need to be changed in UI also.
|
||||
fun getIngoingMessages(userId: Int, date: Date): List<LocationMessage> {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
fun addLocationMessage(locationMessage: LocationMessage) {
|
||||
locationMessages.add(locationMessage)
|
||||
sqliteHelper.addLocationMessage(locationMessage)
|
||||
fun addOutgoingMessage(message: LocationMessage) {
|
||||
val messages = mutableListOf(*this.bufferedMessages.toTypedArray())
|
||||
messages.add(message)
|
||||
this.bufferedMessages = messages
|
||||
dbHelper.addOutgoingMessage(message)
|
||||
}
|
||||
|
||||
fun clearMessages() {
|
||||
sqliteHelper.clearLocationMessages()
|
||||
fun addIngoingMessage(message: LocationMessage) {
|
||||
dbHelper.addIngoingMessage(message)
|
||||
}
|
||||
|
||||
fun collectRecordedDataForUser(userId: Int, chatId: Long, start: Long, end: Long): List<LocationMessages.LocationMessage> {
|
||||
fun clearOutgoingMessages() {
|
||||
dbHelper.clearOutgoingMessages()
|
||||
bufferedMessages = emptyList()
|
||||
}
|
||||
|
||||
// todo - both methods should be refactored since we have two tables now for outgoing/ingoing messages. Data should be read from db.
|
||||
fun collectRecordedDataForUser(userId: Int, chatId: Long, start: Long, end: Long): List<LocationMessage> {
|
||||
return if (chatId == 0L) {
|
||||
locationMessages.sortedWith(compareBy({ it.userId }, { it.chatId })).filter { it.userId == userId&&it.date in (start + 1)..(end - 1) }
|
||||
bufferedMessages.sortedWith(compareBy({ it.userId }, { it.chatId })).filter { it.userId == userId && it.date in (start + 1)..(end - 1) }
|
||||
} else {
|
||||
locationMessages.sortedWith(compareBy({ it.userId }, { it.chatId })).filter {
|
||||
bufferedMessages.sortedWith(compareBy({ it.userId }, { it.chatId })).filter {
|
||||
it.chatId == chatId && it.userId == userId && it.status == LocationMessage.STATUS_SENT && it.date in (start + 1)..(end - 1) }
|
||||
}
|
||||
}
|
||||
|
||||
fun collectRecordedDataForUsers(start: Long, end: Long, ignoredUsersIds: ArrayList<Int>): List<LocationMessages.LocationMessage> {
|
||||
return locationMessages.sortedWith(compareBy({ it.userId }, { it.chatId })).filter {
|
||||
fun collectRecordedDataForUsers(start: Long, end: Long, ignoredUsersIds: ArrayList<Int>): List<LocationMessage> {
|
||||
return bufferedMessages.sortedWith(compareBy({ it.userId }, { it.chatId })).filter {
|
||||
it.date in (start + 1)..(end - 1) && !ignoredUsersIds.contains(it.userId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun readMessages() {
|
||||
val messages = sqliteHelper.getLocationMessages()
|
||||
locationMessages.addAll(messages)
|
||||
private fun readBufferedMessages() {
|
||||
this.bufferedMessages = dbHelper.getOutgoingMessages();
|
||||
}
|
||||
|
||||
private class SQLiteHelper(context: Context) :
|
||||
SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
db.execSQL(TRACKS_TABLE_CREATE)
|
||||
db.execSQL("CREATE INDEX $TRACK_DATE_INDEX ON $TRACK_TABLE_NAME (\"$TRACK_COL_DATE\" DESC);")
|
||||
db.execSQL(OUTGOING_TABLE_CREATE)
|
||||
db.execSQL("CREATE INDEX $DATE_INDEX ON $OUTGOING_TABLE_NAME (\"$COL_DATE\" DESC);")
|
||||
db.execSQL(INGOING_TABLE_CREATE)
|
||||
db.execSQL("CREATE INDEX $DATE_INDEX ON $INGOING_TABLE_NAME (\"$COL_DATE\" DESC);")
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL(TRACKS_TABLE_DELETE)
|
||||
db.execSQL(OUTGOING_TABLE_DELETE)
|
||||
db.execSQL(INGOING_TABLE_DELETE)
|
||||
onCreate(db)
|
||||
}
|
||||
|
||||
internal fun addLocationMessages(locationMessages: List<LocationMessage>) {
|
||||
locationMessages.forEach {
|
||||
writableDatabase?.execSQL(TRACKS_TABLE_INSERT,
|
||||
arrayOf(it.userId, it.chatId, it.lat, it.lon, it.altitude, it.speed, it.hdop, it.bearing, it.date, it.type, it.status, it.messageId))
|
||||
}
|
||||
internal fun addOutgoingMessage(message: LocationMessage) {
|
||||
writableDatabase?.execSQL(OUTGOING_TABLE_INSERT,
|
||||
arrayOf(message.userId, message.chatId, message.lat, message.lon, message.altitude, message.speed,
|
||||
message.hdop, message.bearing, message.date, message.type, message.status, message.messageId))
|
||||
}
|
||||
|
||||
internal fun addLocationMessage(locationMessage: LocationMessage) {
|
||||
writableDatabase?.execSQL(TRACKS_TABLE_INSERT,
|
||||
arrayOf(locationMessage.userId, locationMessage.chatId, locationMessage.lat, locationMessage.lon, locationMessage.altitude, locationMessage.speed,
|
||||
locationMessage.hdop, locationMessage.bearing, locationMessage.date, locationMessage.type, locationMessage.status, locationMessage.messageId))
|
||||
internal fun addIngoingMessage(message: LocationMessage) {
|
||||
writableDatabase?.execSQL(INGOING_TABLE_INSERT,
|
||||
arrayOf(message.userId, message.chatId, message.lat, message.lon, message.altitude, message.speed,
|
||||
message.hdop, message.bearing, message.date, message.type, message.status, message.messageId))
|
||||
}
|
||||
|
||||
internal fun getLocationMessages(): List<LocationMessage> {
|
||||
val res = ArrayList<LocationMessage>()
|
||||
readableDatabase?.rawQuery(TRACKS_TABLE_SELECT, null)?.apply {
|
||||
internal fun getOutgoingMessages(): List<LocationMessage> {
|
||||
val res = arrayListOf<LocationMessage>()
|
||||
readableDatabase?.rawQuery(OUTGOING_TABLE_SELECT, null)?.apply {
|
||||
if (moveToFirst()) {
|
||||
do {
|
||||
res.add(readLocationMessage(this@apply))
|
||||
|
@ -122,52 +133,69 @@ class LocationMessages(val app: TelegramApplication) {
|
|||
val altitude = cursor.getDouble(4)
|
||||
val speed = cursor.getDouble(5)
|
||||
val hdop = cursor.getDouble(6)
|
||||
val date = cursor.getLong(7)
|
||||
val bearing = cursor.getDouble(8)
|
||||
val textInfo = cursor.getInt(9)
|
||||
val bearing = cursor.getDouble(7)
|
||||
val date = cursor.getLong(8)
|
||||
val type = cursor.getInt(9)
|
||||
val status = cursor.getInt(10)
|
||||
val messageId = cursor.getLong(11)
|
||||
|
||||
return LocationMessage(userId, chatId, lat, lon, altitude, speed, hdop, bearing, date, textInfo, status, messageId)
|
||||
return LocationMessage(userId, chatId, lat, lon, altitude, speed, hdop, bearing, date, type, status, messageId)
|
||||
}
|
||||
|
||||
internal fun clearLocationMessages() {
|
||||
writableDatabase?.execSQL(TRACKS_TABLE_CLEAR)
|
||||
internal fun clearOutgoingMessages() {
|
||||
writableDatabase?.execSQL(OUTGOING_TABLE_CLEAR)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val DATABASE_NAME = "location_messages"
|
||||
private const val DATABASE_VERSION = 2
|
||||
private const val DATABASE_VERSION = 3
|
||||
|
||||
private const val TRACK_TABLE_NAME = "track"
|
||||
private const val TRACK_COL_USER_ID = "user_id"
|
||||
private const val TRACK_COL_CHAT_ID = "chat_id"
|
||||
private const val TRACK_COL_DATE = "date"
|
||||
private const val TRACK_COL_LAT = "lat"
|
||||
private const val TRACK_COL_LON = "lon"
|
||||
private const val TRACK_COL_ALTITUDE = "altitude"
|
||||
private const val TRACK_COL_SPEED = "speed"
|
||||
private const val TRACK_COL_HDOP = "hdop"
|
||||
private const val TRACK_COL_BEARING = "bearing"
|
||||
private const val TRACK_COL_TYPE = "type" // 0 = user map message, 1 = user text message, 2 = bot map message, 3 = bot text message
|
||||
private const val TRACK_COL_MESSAGE_STATUS = "status" // 0 = preparing , 1 = pending, 2 = sent, 3 = error
|
||||
private const val TRACK_COL_MESSAGE_ID = "message_id"
|
||||
private const val OUTGOING_TABLE_NAME = "outgoing"
|
||||
private const val INGOING_TABLE_NAME = "ingoing"
|
||||
|
||||
private const val TRACK_DATE_INDEX = "date_index"
|
||||
private const val COL_USER_ID = "user_id"
|
||||
private const val COL_CHAT_ID = "chat_id"
|
||||
private const val COL_DATE = "date"
|
||||
private const val COL_LAT = "lat"
|
||||
private const val COL_LON = "lon"
|
||||
private const val COL_ALTITUDE = "altitude"
|
||||
private const val COL_SPEED = "speed"
|
||||
private const val COL_HDOP = "hdop"
|
||||
private const val COL_BEARING = "bearing"
|
||||
private const val COL_TYPE = "type" // 0 = user map message, 1 = user text message, 2 = bot map message, 3 = bot text message
|
||||
private const val COL_MESSAGE_STATUS = "status" // 0 = preparing , 1 = pending, 2 = sent, 3 = error
|
||||
private const val COL_MESSAGE_ID = "message_id"
|
||||
|
||||
private const val TRACKS_TABLE_INSERT =
|
||||
("INSERT INTO $TRACK_TABLE_NAME ($TRACK_COL_USER_ID, $TRACK_COL_CHAT_ID, $TRACK_COL_LAT, $TRACK_COL_LON, $TRACK_COL_ALTITUDE, $TRACK_COL_SPEED, $TRACK_COL_HDOP, $TRACK_COL_BEARING, $TRACK_COL_DATE, $TRACK_COL_TYPE, $TRACK_COL_MESSAGE_STATUS, $TRACK_COL_MESSAGE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
private const val DATE_INDEX = "date_index"
|
||||
|
||||
private const val TRACKS_TABLE_CREATE =
|
||||
("CREATE TABLE IF NOT EXISTS $TRACK_TABLE_NAME ($TRACK_COL_USER_ID long, $TRACK_COL_CHAT_ID long,$TRACK_COL_LAT double, $TRACK_COL_LON double, $TRACK_COL_ALTITUDE double, $TRACK_COL_SPEED float, $TRACK_COL_HDOP double, $TRACK_COL_BEARING double, $TRACK_COL_DATE long, $TRACK_COL_TYPE int, $TRACK_COL_MESSAGE_STATUS int, $TRACK_COL_MESSAGE_ID long )")
|
||||
// Outgoing messages table
|
||||
private const val OUTGOING_TABLE_INSERT =
|
||||
("INSERT INTO $OUTGOING_TABLE_NAME ($COL_USER_ID, $COL_CHAT_ID, $COL_LAT, $COL_LON, $COL_ALTITUDE, $COL_SPEED, $COL_HDOP, $COL_BEARING, $COL_DATE, $COL_TYPE, $COL_MESSAGE_STATUS, $COL_MESSAGE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
|
||||
private const val TRACKS_TABLE_SELECT =
|
||||
"SELECT $TRACK_COL_USER_ID, $TRACK_COL_CHAT_ID, $TRACK_COL_LAT, $TRACK_COL_LON, $TRACK_COL_ALTITUDE, $TRACK_COL_SPEED, $TRACK_COL_HDOP, $TRACK_COL_BEARING, $TRACK_COL_DATE, $TRACK_COL_TYPE, $TRACK_COL_MESSAGE_STATUS, $TRACK_COL_MESSAGE_ID FROM $TRACK_TABLE_NAME"
|
||||
private const val OUTGOING_TABLE_CREATE =
|
||||
("CREATE TABLE IF NOT EXISTS $OUTGOING_TABLE_NAME ($COL_USER_ID long, $COL_CHAT_ID long,$COL_LAT double, $COL_LON double, $COL_ALTITUDE double, $COL_SPEED float, $COL_HDOP double, $COL_BEARING double, $COL_DATE long, $COL_TYPE int, $COL_MESSAGE_STATUS int, $COL_MESSAGE_ID long )")
|
||||
|
||||
private const val TRACKS_TABLE_CLEAR = "DELETE FROM $TRACK_TABLE_NAME"
|
||||
private const val OUTGOING_TABLE_SELECT =
|
||||
"SELECT $COL_USER_ID, $COL_CHAT_ID, $COL_LAT, $COL_LON, $COL_ALTITUDE, $COL_SPEED, $COL_HDOP, $COL_BEARING, $COL_DATE, $COL_TYPE, $COL_MESSAGE_STATUS, $COL_MESSAGE_ID FROM $OUTGOING_TABLE_NAME"
|
||||
|
||||
private const val TRACKS_TABLE_DELETE = "DROP TABLE IF EXISTS $TRACK_TABLE_NAME"
|
||||
private const val OUTGOING_TABLE_CLEAR = "DELETE FROM $OUTGOING_TABLE_NAME"
|
||||
|
||||
private const val OUTGOING_TABLE_DELETE = "DROP TABLE IF EXISTS $OUTGOING_TABLE_NAME"
|
||||
|
||||
// Ingoing messages table
|
||||
private const val INGOING_TABLE_INSERT =
|
||||
("INSERT INTO $INGOING_TABLE_NAME ($COL_USER_ID, $COL_CHAT_ID, $COL_LAT, $COL_LON, $COL_ALTITUDE, $COL_SPEED, $COL_HDOP, $COL_BEARING, $COL_DATE, $COL_TYPE, $COL_MESSAGE_STATUS, $COL_MESSAGE_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
|
||||
private const val INGOING_TABLE_CREATE =
|
||||
("CREATE TABLE IF NOT EXISTS $INGOING_TABLE_NAME ($COL_USER_ID long, $COL_CHAT_ID long,$COL_LAT double, $COL_LON double, $COL_ALTITUDE double, $COL_SPEED float, $COL_HDOP double, $COL_BEARING double, $COL_DATE long, $COL_TYPE int, $COL_MESSAGE_STATUS int, $COL_MESSAGE_ID long )")
|
||||
|
||||
private const val INGOING_TABLE_SELECT =
|
||||
"SELECT $COL_USER_ID, $COL_CHAT_ID, $COL_LAT, $COL_LON, $COL_ALTITUDE, $COL_SPEED, $COL_HDOP, $COL_BEARING, $COL_DATE, $COL_TYPE, $COL_MESSAGE_STATUS, $COL_MESSAGE_ID FROM $INGOING_TABLE_NAME"
|
||||
|
||||
private const val INGOING_TABLE_CLEAR = "DELETE FROM $INGOING_TABLE_NAME"
|
||||
|
||||
private const val INGOING_TABLE_DELETE = "DROP TABLE IF EXISTS $INGOING_TABLE_NAME"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,9 +210,9 @@ class LocationMessages(val app: TelegramApplication) {
|
|||
val bearing: Double,
|
||||
val date: Long,
|
||||
val type: Int,
|
||||
// todo - status and messageId should be updated in db right away. Make them val instead of var.
|
||||
var status: Int,
|
||||
var messageId: Long
|
||||
) {
|
||||
var messageId: Long) {
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -192,7 +220,6 @@ class LocationMessages(val app: TelegramApplication) {
|
|||
const val STATUS_PENDING = 1
|
||||
const val STATUS_SENT = 2
|
||||
const val STATUS_ERROR = 3
|
||||
const val STATUS_INCOMING = 4
|
||||
|
||||
const val TYPE_USER_MAP = 0
|
||||
const val TYPE_USER_TEXT = 1
|
||||
|
|
|
@ -155,14 +155,14 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
types.forEach {
|
||||
val message = LocationMessage(userId, shareInfo.chatId, latitude, longitude, location.altitude, location.speed.toDouble(),
|
||||
location.accuracy.toDouble(), location.bearing.toDouble(), location.time, it, LocationMessage.STATUS_PREPARED, shareInfo.currentMapMessageId)
|
||||
app.locationMessages.addLocationMessage(message)
|
||||
app.locationMessages.addOutgoingMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shareMessages() {
|
||||
var bufferedMessagesFull = false
|
||||
app.locationMessages.getPreparedToShareMessages().forEach {
|
||||
app.locationMessages.getPreparedMessages().forEach {
|
||||
val shareChatInfo = app.settings.getChatsShareInfo()[it.chatId]
|
||||
if (shareChatInfo != null) {
|
||||
bufferedMessagesFull = shareChatInfo.bufferedMessages < 10
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package net.osmand.telegram.helpers
|
||||
|
||||
import android.text.TextUtils
|
||||
import net.osmand.Location
|
||||
import net.osmand.PlatformUtil
|
||||
import net.osmand.telegram.*
|
||||
import net.osmand.telegram.helpers.TelegramHelper.TelegramAuthenticationParameterType.*
|
||||
import net.osmand.telegram.utils.BASE_SHARING_URL
|
||||
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_DIR
|
||||
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_EXT
|
||||
import net.osmand.telegram.utils.OsmandLocationUtils
|
||||
|
@ -22,7 +20,6 @@ import org.drinkless.td.libcore.telegram.Client.ResultHandler
|
|||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import org.drinkless.td.libcore.telegram.TdApi.AuthorizationState
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.osmand.telegram.utils.OsmandLocationUtils
|
|||
import net.osmand.telegram.utils.OsmandLocationUtils.MessageUserTextLocation
|
||||
import net.osmand.telegram.utils.OsmandLocationUtils.MessageOsmAndBotLocation
|
||||
import net.osmand.telegram.utils.GPXUtilities
|
||||
import net.osmand.telegram.utils.GPXUtilities.GPXFile
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
|
||||
object TelegramUiHelper {
|
||||
|
@ -131,7 +132,7 @@ object TelegramUiHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun gpxToChatItem(helper: TelegramHelper, gpx: GPXUtilities.GPXFile, simpleUserItem: Boolean): GpxChatItem? {
|
||||
fun gpxToChatItem(helper: TelegramHelper, gpx: GPXFile, simpleUserItem: Boolean): GpxChatItem? {
|
||||
return if (simpleUserItem) gpxToUserGpxChatItem(helper, gpx) else gpxToGpxChatItem(helper, gpx)
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,7 @@ object TelegramUiHelper {
|
|||
|
||||
private fun gpxToGpxChatItem(
|
||||
helper: TelegramHelper,
|
||||
gpx: GPXUtilities.GPXFile
|
||||
gpx: GPXFile
|
||||
): GpxChatItem? {
|
||||
val user = helper.getUser(gpx.userId) ?: return null
|
||||
val chat = helper.getChat(gpx.chatId) ?: return null
|
||||
|
@ -258,7 +259,7 @@ object TelegramUiHelper {
|
|||
|
||||
private fun gpxToUserGpxChatItem(
|
||||
helper: TelegramHelper,
|
||||
gpx: GPXUtilities.GPXFile
|
||||
gpx: GPXFile
|
||||
): GpxChatItem? {
|
||||
val user = helper.getUser(gpx.userId) ?: return null
|
||||
return GpxChatItem().apply {
|
||||
|
@ -323,7 +324,7 @@ object TelegramUiHelper {
|
|||
|
||||
class GpxChatItem : ListItem() {
|
||||
|
||||
var gpxFile: GPXUtilities.GPXFile? = null
|
||||
var gpxFile: GPXFile? = null
|
||||
internal set
|
||||
var groupPhotoPath: String? = null
|
||||
internal set
|
||||
|
|
|
@ -19,7 +19,7 @@ import android.widget.*
|
|||
import net.osmand.PlatformUtil
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.helpers.LocationMessages
|
||||
import net.osmand.telegram.helpers.LocationMessages.LocationMessage
|
||||
import net.osmand.telegram.helpers.OsmandAidlHelper
|
||||
import net.osmand.telegram.helpers.TelegramHelper
|
||||
import net.osmand.telegram.helpers.TelegramHelper.*
|
||||
|
@ -293,9 +293,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
}
|
||||
if (app.telegramService == null) {
|
||||
messages.forEach {
|
||||
val locationMessage = OsmandLocationUtils.parseMessage(it, telegramHelper, LocationMessages.LocationMessage.STATUS_INCOMING)
|
||||
val locationMessage = OsmandLocationUtils.parseMessage(it, telegramHelper, LocationMessage.STATUS_PREPARED)
|
||||
if (locationMessage != null) {
|
||||
app.locationMessages.addLocationMessage(locationMessage)
|
||||
app.locationMessages.addIngoingMessage(locationMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +349,8 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
fun logoutTelegram(silent: Boolean = false) {
|
||||
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
|
||||
if (app.isInternetConnectionAvailable) {
|
||||
app.locationMessages.clearMessages()
|
||||
// todo - why delete messages on logout?
|
||||
app.locationMessages.clearOutgoingMessages()
|
||||
settings.clear()
|
||||
telegramHelper.logout()
|
||||
} else {
|
||||
|
|
|
@ -716,13 +716,13 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
holder.gpsPointsCollected?.apply {
|
||||
if (shareInfo != null) {
|
||||
val all = app.locationMessages.getOutgoingMessagesToChat(shareInfo.chatId)
|
||||
val all = app.locationMessages.getOutgoingMessages(shareInfo.chatId)
|
||||
text = "${all.size}"
|
||||
}
|
||||
}
|
||||
holder.gpsPointsSent?.apply {
|
||||
if (shareInfo != null) {
|
||||
val sent = app.locationMessages.getOutgoingMessagesToChatFromDate(shareInfo.chatId, shareInfo.start * 1000)
|
||||
val sent = app.locationMessages.getSentMessages(shareInfo.chatId, shareInfo.start * 1000)
|
||||
text = "${sent.size}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,6 +192,7 @@ class TimelineTabFragment : Fragment() {
|
|||
val currentUserId = telegramHelper.getCurrentUser()?.id
|
||||
if (currentUserId != null) {
|
||||
val locationMessages = app.locationMessages.collectRecordedDataForUser(currentUserId, 0, start, end)
|
||||
// todo - why do we need convert to gpx on update? Is locationMessages not enough to display info?
|
||||
OsmandLocationUtils.convertLocationMessagesToGpxFiles(locationMessages, false).forEach {
|
||||
TelegramUiHelper.gpxToChatItem(telegramHelper, it, true)?.also { chatItem ->
|
||||
res.add(chatItem)
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.osmand.telegram.utils
|
|||
import android.os.AsyncTask
|
||||
import net.osmand.Location
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.helpers.LocationMessages
|
||||
import net.osmand.telegram.helpers.LocationMessages.LocationMessage
|
||||
import net.osmand.telegram.helpers.TelegramHelper
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||
import net.osmand.util.GeoPointParserUtil
|
||||
|
@ -74,8 +74,8 @@ object OsmandLocationUtils {
|
|||
}
|
||||
}
|
||||
|
||||
fun parseMessage(message: TdApi.Message, helper: TelegramHelper, status: Int): LocationMessages.LocationMessage? {
|
||||
var locationMessage: LocationMessages.LocationMessage? = null
|
||||
fun parseMessage(message: TdApi.Message, helper: TelegramHelper, status: Int): LocationMessage? {
|
||||
var locationMessage: LocationMessage? = null
|
||||
val oldContent = message.content
|
||||
|
||||
val fromBot = helper.isOsmAndBot(message.senderUserId)
|
||||
|
@ -106,7 +106,7 @@ object OsmandLocationUtils {
|
|||
}
|
||||
|
||||
if (parsedMessageContent != null) {
|
||||
locationMessage = LocationMessages.LocationMessage(helper.getSenderMessageId(message), message.chatId, parsedMessageContent.lat,
|
||||
locationMessage = LocationMessage(helper.getSenderMessageId(message), message.chatId, parsedMessageContent.lat,
|
||||
parsedMessageContent.lon, parsedMessageContent.altitude, parsedMessageContent.speed, parsedMessageContent.hdop,
|
||||
parsedMessageContent.bearing, parsedMessageContent.lastUpdated * 1000L, messageType, status, message.id)
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ object OsmandLocationUtils {
|
|||
return String.format(Locale.US, "%.5f, %.5f", sig.latitude, sig.longitude)
|
||||
}
|
||||
|
||||
fun formatLocation(sig: LocationMessages.LocationMessage): String {
|
||||
fun formatLocation(sig: LocationMessage): String {
|
||||
return String.format(Locale.US, "%.5f, %.5f", sig.lat, sig.lon)
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ object OsmandLocationUtils {
|
|||
return 0
|
||||
}
|
||||
|
||||
fun getTextMessageContent(updateId: Int, location: LocationMessages.LocationMessage): TdApi.InputMessageText {
|
||||
fun getTextMessageContent(updateId: Int, location: LocationMessage): TdApi.InputMessageText {
|
||||
val entities = mutableListOf<TdApi.TextEntity>()
|
||||
val builder = StringBuilder()
|
||||
val locationMessage = formatLocation(location)
|
||||
|
@ -313,7 +313,7 @@ object OsmandLocationUtils {
|
|||
return TdApi.InputMessageText(TdApi.FormattedText(textMessage, entities.toTypedArray()), true, true)
|
||||
}
|
||||
|
||||
fun convertLocationMessagesToGpxFiles(items: List<LocationMessages.LocationMessage>, newGpxPerChat: Boolean = true): List<GPXUtilities.GPXFile> {
|
||||
fun convertLocationMessagesToGpxFiles(items: List<LocationMessage>, newGpxPerChat: Boolean = true): List<GPXUtilities.GPXFile> {
|
||||
val dataTracks = ArrayList<GPXUtilities.GPXFile>()
|
||||
|
||||
var previousTime: Long = -1
|
||||
|
|
Loading…
Reference in a new issue