Telegram - working on show on map

This commit is contained in:
crimean 2018-06-10 15:20:11 +03:00
parent 9d37174113
commit 3892f944ac
2 changed files with 35 additions and 0 deletions

View file

@ -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

View file

@ -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<String>) {
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)