remove unnecessary methods

This commit is contained in:
Chumva 2019-01-30 10:37:28 +02:00
parent d771c47fb8
commit dcdd62abcc
4 changed files with 21 additions and 51 deletions

View file

@ -278,7 +278,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
messages.forEach { messages.forEach {
val locationMessage = OsmandLocationUtils.parseMessage(it, app().telegramHelper) val locationMessage = OsmandLocationUtils.parseMessage(it, app().telegramHelper)
if (locationMessage != null) { if (locationMessage != null) {
app().locationMessages.addIngoingMessage(locationMessage) app().locationMessages.addLocationMessage(locationMessage)
} }
} }
} }
@ -298,7 +298,7 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
if (it.sendingState == null && (it.content is TdApi.MessageLocation || it.content is TdApi.MessageText)) { if (it.sendingState == null && (it.content is TdApi.MessageLocation || it.content is TdApi.MessageText)) {
val locationMessage = OsmandLocationUtils.parseMessage(it, app().telegramHelper) val locationMessage = OsmandLocationUtils.parseMessage(it, app().telegramHelper)
if (locationMessage != null) { if (locationMessage != null) {
app().locationMessages.addOutgoingMessage(locationMessage) app().locationMessages.addLocationMessage(locationMessage)
} }
} }
} }

View file

@ -30,12 +30,6 @@ class LocationMessages(val app: TelegramApplication) {
return bufferedMessages.filter { it.chatId==chatId }.sortedBy { it.time } return bufferedMessages.filter { it.chatId==chatId }.sortedBy { it.time }
} }
// // todo - drop method. add collected / sent messages count to ShareChatInfo
// fun getOutgoingMessages(chatId: Long): List<LocationMessage> {
// val currentUserId = app.telegramHelper.getCurrentUserId()
// return bufferedMessages.filter { it.userId == currentUserId && it.chatId == chatId }.sortedBy { it.date }
// }
// todo - read from db by date (Victor's suggestion - filter by one day only. Need to be changed in UI also. // todo - read from db by date (Victor's suggestion - filter by one day only. Need to be changed in UI also.
fun getIngoingMessages(currentUserId: Int, start: Long, end: Long): List<LocationMessage> { fun getIngoingMessages(currentUserId: Int, start: Long, end: Long): List<LocationMessage> {
return dbHelper.getIngoingMessages(currentUserId, start, end) return dbHelper.getIngoingMessages(currentUserId, start, end)
@ -45,8 +39,8 @@ class LocationMessages(val app: TelegramApplication) {
return dbHelper.getIngoingMessagesForUser(userId, chatId, start, end) return dbHelper.getIngoingMessagesForUser(userId, chatId, start, end)
} }
fun getOutgoingMessages(userId: Int, start: Long, end: Long): List<LocationMessage> { fun getMessagesForUser(userId: Int, start: Long, end: Long): List<LocationMessage> {
return dbHelper.getOutgoingMessagesForUser(userId, start, end) return dbHelper.getMessagesForUser(userId, start, end)
} }
fun addBufferedMessage(message: BufferMessage) { fun addBufferedMessage(message: BufferMessage) {
@ -57,14 +51,9 @@ class LocationMessages(val app: TelegramApplication) {
dbHelper.addBufferedMessage(message) dbHelper.addBufferedMessage(message)
} }
fun addIngoingMessage(message: LocationMessage) { fun addLocationMessage(message: LocationMessage) {
log.debug("addIngoingMessage $message") log.debug("addIngoingMessage $message")
dbHelper.addIngoingMessage(message) dbHelper.addLocationMessage(message)
}
fun addOutgoingMessage(message: LocationMessage) {
log.debug("addOutgoingMessage $message")
dbHelper.addOutgoingMessage(message)
} }
fun clearBufferedMessages() { fun clearBufferedMessages() {
@ -100,7 +89,19 @@ class LocationMessages(val app: TelegramApplication) {
onCreate(db) onCreate(db)
} }
internal fun getOutgoingMessagesForUser(userId: Int, start: Long, end: Long): List<LocationMessage> { internal fun addBufferedMessage(message: BufferMessage) {
writableDatabase?.execSQL(BUFFER_TABLE_INSERT,
arrayOf(message.chatId, message.lat, message.lon, message.altitude, message.speed,
message.hdop, message.bearing, message.time, message.type))
}
internal fun addLocationMessage(message: LocationMessage) {
writableDatabase?.execSQL(TIMELINE_TABLE_INSERT,
arrayOf(message.userId, message.chatId, message.lat, message.lon, message.altitude, message.speed,
message.hdop, message.bearing, message.time, message.type))
}
internal fun getMessagesForUser(userId: Int, start: Long, end: Long): List<LocationMessage> {
val res = arrayListOf<LocationMessage>() val res = arrayListOf<LocationMessage>()
readableDatabase?.rawQuery( readableDatabase?.rawQuery(
"$TIMELINE_TABLE_SELECT WHERE $COL_USER_ID = ? AND $COL_TIME BETWEEN $start AND $end ORDER BY $COL_TIME ASC ", "$TIMELINE_TABLE_SELECT WHERE $COL_USER_ID = ? AND $COL_TIME BETWEEN $start AND $end ORDER BY $COL_TIME ASC ",
@ -145,37 +146,6 @@ class LocationMessages(val app: TelegramApplication) {
return res return res
} }
internal fun addBufferedMessage(message: BufferMessage) {
writableDatabase?.execSQL(BUFFER_TABLE_INSERT,
arrayOf(message.chatId, message.lat, message.lon, message.altitude, message.speed,
message.hdop, message.bearing, message.time, message.type))
}
internal fun addIngoingMessage(message: LocationMessage) {
writableDatabase?.execSQL(TIMELINE_TABLE_INSERT,
arrayOf(message.userId, message.chatId, message.lat, message.lon, message.altitude, message.speed,
message.hdop, message.bearing, message.time, message.type))
}
internal fun addOutgoingMessage(message: LocationMessage) {
writableDatabase?.execSQL(TIMELINE_TABLE_INSERT,
arrayOf(message.userId, message.chatId, message.lat, message.lon, message.altitude, message.speed,
message.hdop, message.bearing, message.time, message.type))
}
internal fun getOutgoingMessages(): List<LocationMessage> {
val res = arrayListOf<LocationMessage>()
readableDatabase?.rawQuery(TIMELINE_TABLE_SELECT, null)?.apply {
if (moveToFirst()) {
do {
res.add(readLocationMessage(this@apply))
} while (moveToNext())
}
close()
}
return res
}
internal fun getBufferedMessages(): List<BufferMessage> { internal fun getBufferedMessages(): List<BufferMessage> {
val res = arrayListOf<BufferMessage>() val res = arrayListOf<BufferMessage>()
readableDatabase?.rawQuery(BUFFER_TABLE_SELECT, null)?.apply { readableDatabase?.rawQuery(BUFFER_TABLE_SELECT, null)?.apply {

View file

@ -296,7 +296,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
messages.forEach { messages.forEach {
val locationMessage = OsmandLocationUtils.parseMessage(it, telegramHelper) val locationMessage = OsmandLocationUtils.parseMessage(it, telegramHelper)
if (locationMessage != null) { if (locationMessage != null) {
app.locationMessages.addIngoingMessage(locationMessage) app.locationMessages.addLocationMessage(locationMessage)
} }
} }
} }

View file

@ -191,7 +191,7 @@ class TimelineTabFragment : Fragment() {
val ignoredUsersIds = ArrayList<Int>() val ignoredUsersIds = ArrayList<Int>()
val currentUserId = telegramHelper.getCurrentUser()?.id val currentUserId = telegramHelper.getCurrentUser()?.id
if (currentUserId != null) { if (currentUserId != null) {
val outgoingMessages = app.locationMessages.getOutgoingMessages(currentUserId, start, end) val outgoingMessages = app.locationMessages.getMessagesForUser(currentUserId, start, end)
// todo - why do we need convert to gpx on update? Is locationMessages not enough to display info? // todo - why do we need convert to gpx on update? Is locationMessages not enough to display info?
OsmandLocationUtils.convertLocationMessagesToGpxFiles(outgoingMessages, false).forEach { OsmandLocationUtils.convertLocationMessagesToGpxFiles(outgoingMessages, false).forEach {
TelegramUiHelper.gpxToChatItem(telegramHelper, it, true)?.also { chatItem -> TelegramUiHelper.gpxToChatItem(telegramHelper, it, true)?.also { chatItem ->