Show all chats on map by default
This commit is contained in:
parent
546679298e
commit
d6cd0df2ea
4 changed files with 39 additions and 40 deletions
|
@ -74,9 +74,6 @@ class TelegramApplication : Application(), OsmandHelperListener {
|
|||
if (settings.hasAnyChatToShareLocation() && AndroidUtils.isLocationPermissionAvailable(this)) {
|
||||
shareLocationHelper.startSharingLocation()
|
||||
}
|
||||
if (settings.hasAnyChatToShowOnMap()) {
|
||||
showLocationHelper.startShowingLocation()
|
||||
}
|
||||
}
|
||||
|
||||
fun cleanupResources() {
|
||||
|
|
|
@ -34,7 +34,7 @@ private const val LOC_HISTORY_DEFAULT_INDEX = 2
|
|||
private const val SETTINGS_NAME = "osmand_telegram_settings"
|
||||
|
||||
private const val SHARE_LOCATION_CHATS_KEY = "share_location_chats"
|
||||
private const val SHOW_ON_MAP_CHATS_KEY = "show_on_map_chats"
|
||||
private const val HIDDEN_ON_MAP_CHATS_KEY = "hidden_on_map_chats"
|
||||
|
||||
private const val METRICS_CONSTANTS_KEY = "metrics_constants"
|
||||
private const val SPEED_CONSTANTS_KEY = "speed_constants"
|
||||
|
@ -57,7 +57,7 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
private var chatShareLocStartSec = mutableMapOf<Long, Long>()
|
||||
|
||||
private var shareLocationChats: Set<Long> = emptySet()
|
||||
private var showOnMapChats: Set<Long> = emptySet()
|
||||
private var hiddenOnMapChats: Set<Long> = emptySet()
|
||||
|
||||
var metricsConstants = MetricsConstants.KILOMETERS_AND_METERS
|
||||
var speedConstants = SpeedConstants.KILOMETERS_PER_HOUR
|
||||
|
@ -82,18 +82,18 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
fun isSharingLocationToChat(chatId: Long) = shareLocationChats.contains(chatId)
|
||||
|
||||
fun hasAnyChatToShowOnMap() = showOnMapChats.isNotEmpty()
|
||||
fun hasAnyChatToShowOnMap() = !hiddenOnMapChats.containsAll(getLiveNowChats())
|
||||
|
||||
fun isShowingChatOnMap(chatId: Long) = showOnMapChats.contains(chatId)
|
||||
fun isShowingChatOnMap(chatId: Long) = !hiddenOnMapChats.contains(chatId)
|
||||
|
||||
fun removeNonexistingChats(presentChatIds: List<Long>) {
|
||||
val shareLocationChats = shareLocationChats.toMutableList()
|
||||
shareLocationChats.intersect(presentChatIds)
|
||||
this.shareLocationChats = shareLocationChats.toHashSet()
|
||||
|
||||
val showOnMapChats = showOnMapChats.toMutableList()
|
||||
showOnMapChats.intersect(presentChatIds)
|
||||
this.showOnMapChats = showOnMapChats.toHashSet()
|
||||
val hiddenChats = hiddenOnMapChats.toMutableList()
|
||||
hiddenChats.intersect(presentChatIds)
|
||||
hiddenOnMapChats = hiddenChats.toHashSet()
|
||||
|
||||
chatLivePeriods = chatLivePeriods.filter { (key, _) ->
|
||||
presentChatIds.contains(key)
|
||||
|
@ -157,25 +157,21 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
this.chatShareLocStartSec.clear()
|
||||
}
|
||||
|
||||
fun clearShowOnMapChats() {
|
||||
showOnMapChats = emptySet()
|
||||
}
|
||||
|
||||
fun showChatOnMap(chatId: Long, show: Boolean) {
|
||||
val showOnMapChats = showOnMapChats.toMutableList()
|
||||
val hiddenChats = hiddenOnMapChats.toMutableList()
|
||||
if (show) {
|
||||
showOnMapChats.add(chatId)
|
||||
hiddenChats.remove(chatId)
|
||||
} else {
|
||||
showOnMapChats.remove(chatId)
|
||||
hiddenChats.add(chatId)
|
||||
}
|
||||
this.showOnMapChats = showOnMapChats.toHashSet()
|
||||
hiddenOnMapChats = hiddenChats.toHashSet()
|
||||
}
|
||||
|
||||
fun getShareLocationChats() = ArrayList(shareLocationChats)
|
||||
|
||||
fun getShowOnMapChats() = ArrayList(showOnMapChats)
|
||||
fun getShowOnMapChats() = getLiveNowChats().minus(hiddenOnMapChats)
|
||||
|
||||
fun getShowOnMapChatsCount() = showOnMapChats.size
|
||||
fun getShowOnMapChatsCount() = getShowOnMapChats().size
|
||||
|
||||
fun clear() {
|
||||
stopSharingLocationToChats()
|
||||
|
@ -199,12 +195,12 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, shareLocationChatsSet)
|
||||
|
||||
val showOnMapChatsSet = mutableSetOf<String>()
|
||||
val showOnMapChats = ArrayList(showOnMapChats)
|
||||
for (chatId in showOnMapChats) {
|
||||
showOnMapChatsSet.add(chatId.toString())
|
||||
val hiddenChatsSet = mutableSetOf<String>()
|
||||
val hiddenChats = ArrayList(hiddenOnMapChats)
|
||||
for (chatId in hiddenChats) {
|
||||
hiddenChatsSet.add(chatId.toString())
|
||||
}
|
||||
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, showOnMapChatsSet)
|
||||
edit.putStringSet(HIDDEN_ON_MAP_CHATS_KEY, hiddenChatsSet)
|
||||
|
||||
edit.putString(METRICS_CONSTANTS_KEY, metricsConstants.name)
|
||||
edit.putString(SPEED_CONSTANTS_KEY, speedConstants.name)
|
||||
|
@ -230,12 +226,12 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
this.shareLocationChats = shareLocationChats
|
||||
|
||||
val showOnMapChats = mutableSetOf<Long>()
|
||||
val showOnMapChatsSet = prefs.getStringSet(SHOW_ON_MAP_CHATS_KEY, mutableSetOf())
|
||||
for (chatId in showOnMapChatsSet) {
|
||||
showOnMapChats.add(chatId.toLong())
|
||||
val hiddenChats = mutableSetOf<Long>()
|
||||
val hiddenChatsSet = prefs.getStringSet(HIDDEN_ON_MAP_CHATS_KEY, mutableSetOf())
|
||||
for (chatId in hiddenChatsSet) {
|
||||
hiddenChats.add(chatId.toLong())
|
||||
}
|
||||
this.showOnMapChats = showOnMapChats
|
||||
hiddenOnMapChats = hiddenChats
|
||||
|
||||
metricsConstants = MetricsConstants.valueOf(
|
||||
prefs.getString(METRICS_CONSTANTS_KEY, MetricsConstants.KILOMETERS_AND_METERS.name)
|
||||
|
@ -258,6 +254,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
)
|
||||
}
|
||||
|
||||
private fun getLiveNowChats() = app.telegramHelper.getMessagesByChatIds(locHistoryTime).keys
|
||||
|
||||
private fun updatePrefs() {
|
||||
val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)
|
||||
val idsInUse = prefs.getBoolean(TITLES_REPLACED_WITH_IDS, false)
|
||||
|
@ -265,7 +263,6 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
val edit = prefs.edit()
|
||||
|
||||
edit.putStringSet(SHARE_LOCATION_CHATS_KEY, emptySet())
|
||||
edit.putStringSet(SHOW_ON_MAP_CHATS_KEY, emptySet())
|
||||
edit.putBoolean(TITLES_REPLACED_WITH_IDS, true)
|
||||
|
||||
edit.apply()
|
||||
|
|
|
@ -2,18 +2,18 @@ package net.osmand.telegram.helpers
|
|||
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.AsyncTask
|
||||
import android.text.TextUtils
|
||||
import net.osmand.aidl.map.ALatLon
|
||||
import net.osmand.aidl.maplayer.point.AMapPoint
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.helpers.TelegramHelper.MessageOsmAndBotLocation
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper.ListItem
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import java.io.File
|
||||
import android.net.Uri
|
||||
import android.os.AsyncTask
|
||||
import net.osmand.telegram.R
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class ShowLocationHelper(private val app: TelegramApplication) {
|
||||
|
@ -31,6 +31,8 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
var showingLocation: Boolean = false
|
||||
private set
|
||||
|
||||
private var forcedStop: Boolean = false
|
||||
|
||||
fun setupMapLayer() {
|
||||
execOsmandApi {
|
||||
osmandAidlHelper.addMapLayer(MAP_LAYER_ID, "Telegram", 5.5f, null)
|
||||
|
@ -147,7 +149,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
|
||||
fun startShowingLocation() {
|
||||
if (!showingLocation) {
|
||||
if (!showingLocation && !forcedStop) {
|
||||
showingLocation = if (isUseOsmandCallback()) {
|
||||
osmandAidlHelper.registerForUpdates()
|
||||
} else {
|
||||
|
@ -157,7 +159,8 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
fun stopShowingLocation() {
|
||||
fun stopShowingLocation(force: Boolean = false) {
|
||||
forcedStop = force
|
||||
if (showingLocation) {
|
||||
showingLocation = false
|
||||
if (isUseOsmandCallback()) {
|
||||
|
|
|
@ -269,6 +269,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
|
||||
override fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) {
|
||||
addGrayPhoto(chatId)
|
||||
if (!app.showLocationHelper.showingLocation && settings.hasAnyChatToShowOnMap()) {
|
||||
app.showLocationHelper.startShowingLocation()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {}
|
||||
|
@ -294,15 +297,14 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
telegramHelper.stopSendingLiveLocationMessages()
|
||||
}
|
||||
|
||||
fun stopShowingChatsOnMap() {
|
||||
fun stopShowingChatsOnMap(forceStop: Boolean) {
|
||||
settings.getShowOnMapChats().forEach { app.showLocationHelper.hideChatMessages(it) }
|
||||
settings.clearShowOnMapChats()
|
||||
app.showLocationHelper.stopShowingLocation()
|
||||
app.showLocationHelper.stopShowingLocation(forceStop)
|
||||
}
|
||||
|
||||
private fun closeApp() {
|
||||
stopSharingLocation()
|
||||
stopShowingChatsOnMap()
|
||||
stopShowingChatsOnMap(true)
|
||||
finish()
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue