diff --git a/OsmAnd-telegram/src/main/java/net/osmand/telegram/MainActivity.kt b/OsmAnd-telegram/src/main/java/net/osmand/telegram/MainActivity.kt index d5effc6a08..b1795fecd1 100644 --- a/OsmAnd-telegram/src/main/java/net/osmand/telegram/MainActivity.kt +++ b/OsmAnd-telegram/src/main/java/net/osmand/telegram/MainActivity.kt @@ -315,6 +315,7 @@ class MainActivity : AppCompatActivity(), TelegramListener { override fun onBindViewHolder(holder: ViewHolder, position: Int) { val chatTitle = chats[position].title holder.groupName?.text = chatTitle + holder.shareLocationSwitch?.setOnCheckedChangeListener(null) holder.shareLocationSwitch?.isChecked = settings.isSharingLocationToChat(chatTitle) holder.shareLocationSwitch?.setOnCheckedChangeListener { view, isChecked -> @@ -329,6 +330,17 @@ class MainActivity : AppCompatActivity(), TelegramListener { app.shareLocationHelper.stopSharingLocation() } } + + holder.showOnMapSwitch?.setOnCheckedChangeListener(null) + holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatTitle) + holder.showOnMapSwitch?.setOnCheckedChangeListener { view, isChecked -> + settings.showChatOnMap(chatTitle, isChecked) + if (settings.hasAnyChatToShowOnMap()) { + //app.shareLocationHelper.startSharingLocation() + } else { + //app.shareLocationHelper.stopSharingLocation() + } + } } override fun getItemCount() = chats.size diff --git a/OsmAnd-telegram/src/main/java/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/main/java/net/osmand/telegram/TelegramSettings.kt index aed758416f..1ad4824403 100644 --- a/OsmAnd-telegram/src/main/java/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/main/java/net/osmand/telegram/TelegramSettings.kt @@ -39,10 +39,22 @@ class TelegramSettings(private val app: TelegramApplication) { return shareLocationChats.contains(chatTitle) } + fun hasAnyChatToShowOnMap(): Boolean { + return showOnMapChats.isNotEmpty() + } + + fun isShowingChatOnMap(chatTitle: String): Boolean { + return showOnMapChats.contains(chatTitle) + } + fun removeNonexistingChats(presentChatTitles: List) { val shareLocationChats = shareLocationChats.toMutableList() shareLocationChats.intersect(presentChatTitles) this.shareLocationChats = shareLocationChats.toHashSet() + + val showOnMapChats = showOnMapChats.toMutableList() + showOnMapChats.intersect(presentChatTitles) + this.showOnMapChats = showOnMapChats.toHashSet() } fun shareLocationToChat(chatTitle: String, share: Boolean) { @@ -55,7 +67,18 @@ class TelegramSettings(private val app: TelegramApplication) { this.shareLocationChats = shareLocationChats.toHashSet() } + fun showChatOnMap(chatTitle: String, show: Boolean) { + val showOnMapChats = showOnMapChats.toMutableList() + if (show) { + showOnMapChats.add(chatTitle) + } else { + showOnMapChats.remove(chatTitle) + } + this.showOnMapChats = showOnMapChats.toHashSet() + } + fun getShareLocationChats() = ArrayList(shareLocationChats) + fun getShowOnMapChats() = ArrayList(showOnMapChats) fun save() { val prefs = app.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE)