rename chatLivePeriods

This commit is contained in:
Chumva 2018-07-13 17:02:49 +03:00
parent c2aca3c9fb
commit e37e78cb33
3 changed files with 19 additions and 19 deletions

View file

@ -25,7 +25,7 @@ private const val TITLES_REPLACED_WITH_IDS = "changed_to_chat_id"
class TelegramSettings(private val app: TelegramApplication) { class TelegramSettings(private val app: TelegramApplication) {
var chatLocLivePeriods = mutableMapOf<Long, Long>() var chatLivePeriods = mutableMapOf<Long, Long>()
private var shareLocationChats: Set<Long> = emptySet() private var shareLocationChats: Set<Long> = emptySet()
private var showOnMapChats: Set<Long> = emptySet() private var showOnMapChats: Set<Long> = emptySet()
@ -58,7 +58,7 @@ class TelegramSettings(private val app: TelegramApplication) {
showOnMapChats.intersect(presentChatIds) showOnMapChats.intersect(presentChatIds)
this.showOnMapChats = showOnMapChats.toHashSet() this.showOnMapChats = showOnMapChats.toHashSet()
chatLocLivePeriods = chatLocLivePeriods.filter { (key, _) -> chatLivePeriods = chatLivePeriods.filter { (key, _) ->
presentChatIds.contains(key) presentChatIds.contains(key)
}.toMutableMap() }.toMutableMap()
} }
@ -71,20 +71,20 @@ class TelegramSettings(private val app: TelegramApplication) {
duration > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong() duration > TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC -> TelegramHelper.MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC.toLong()
else -> duration else -> duration
} }
chatLocLivePeriods[chatId] = lp chatLivePeriods[chatId] = lp
shareLocationChats.add(chatId) shareLocationChats.add(chatId)
} else { } else {
shareLocationChats.remove(chatId) shareLocationChats.remove(chatId)
chatLocLivePeriods.remove(chatId) chatLivePeriods.remove(chatId)
} }
this.shareLocationChats = shareLocationChats.toHashSet() this.shareLocationChats = shareLocationChats.toHashSet()
} }
fun getChatExpireTime(chatId: Long) = chatLocLivePeriods[chatId] fun getChatExpireTime(chatId: Long) = chatLivePeriods[chatId]
fun stopSharingLocationToChats() { fun stopSharingLocationToChats() {
this.shareLocationChats = emptySet() this.shareLocationChats = emptySet()
this.chatLocLivePeriods.clear() this.chatLivePeriods.clear()
} }
fun showChatOnMap(chatId: Long, show: Boolean) { fun showChatOnMap(chatId: Long, show: Boolean) {

View file

@ -38,7 +38,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
lastLocation = location lastLocation = location
if (location != null && app.isInternetConnectionAvailable) { if (location != null && app.isInternetConnectionAvailable) {
val chatIdsToDuration = app.settings.chatLocLivePeriods val chatIdsToDuration = app.settings.chatLivePeriods
if (chatIdsToDuration.isNotEmpty()) { if (chatIdsToDuration.isNotEmpty()) {
app.telegramHelper.sendLiveLocationMessage(chatIdsToDuration, location.latitude, location.longitude) app.telegramHelper.sendLiveLocationMessage(chatIdsToDuration, location.latitude, location.longitude)
} }

View file

@ -33,7 +33,7 @@ class SetTimeDialogFragment : DialogFragment() {
private lateinit var timeForAllTitle: TextView private lateinit var timeForAllTitle: TextView
private lateinit var timeForAllValue: TextView private lateinit var timeForAllValue: TextView
private val chatIdsToDuration = HashMap<Long, Long>() private val chatLivePeriods = HashMap<Long, Long>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -80,7 +80,7 @@ class SetTimeDialogFragment : DialogFragment() {
if (!AndroidUtils.isLocationPermissionAvailable(view.context)) { if (!AndroidUtils.isLocationPermissionAvailable(view.context)) {
AndroidUtils.requestLocationPermission(activity!!) AndroidUtils.requestLocationPermission(activity!!)
} else { } else {
chatIdsToDuration.forEach { chatId, expireTime -> chatLivePeriods.forEach { chatId, expireTime ->
settings.shareLocationToChat(chatId, true, expireTime) settings.shareLocationToChat(chatId, true, expireTime)
} }
app.shareLocationHelper.startSharingLocation() app.shareLocationHelper.startSharingLocation()
@ -100,7 +100,7 @@ class SetTimeDialogFragment : DialogFragment() {
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
val chats = mutableListOf<Long>() val chats = mutableListOf<Long>()
for ((id, duration) in chatIdsToDuration) { for ((id, duration) in chatLivePeriods) {
chats.add(id) chats.add(id)
chats.add(duration) chats.add(duration)
} }
@ -108,18 +108,18 @@ class SetTimeDialogFragment : DialogFragment() {
} }
private fun readFromBundle(bundle: Bundle?) { private fun readFromBundle(bundle: Bundle?) {
chatIdsToDuration.clear() chatLivePeriods.clear()
bundle?.getLongArray(CHATS_KEY)?.also { bundle?.getLongArray(CHATS_KEY)?.also {
for (i in 0 until it.size step 2) { for (i in 0 until it.size step 2) {
val expireTime = settings.getChatExpireTime(it[i]) val expireTime = settings.getChatExpireTime(it[i])
chatIdsToDuration[it[i]] = expireTime ?: it[i + 1] chatLivePeriods[it[i]] = expireTime ?: it[i + 1]
} }
} }
} }
private fun getTimeForAll(useDefValue: Boolean = false): Long { private fun getTimeForAll(useDefValue: Boolean = false): Long {
val returnVal = if (useDefValue) DEFAULT_VISIBLE_TIME_SECONDS else NO_VALUE val returnVal = if (useDefValue) DEFAULT_VISIBLE_TIME_SECONDS else NO_VALUE
val iterator = chatIdsToDuration.values.iterator() val iterator = chatLivePeriods.values.iterator()
if (!iterator.hasNext()) { if (!iterator.hasNext()) {
return returnVal return returnVal
} }
@ -146,7 +146,7 @@ class SetTimeDialogFragment : DialogFragment() {
private fun selectDuration(id: Long? = null) { private fun selectDuration(id: Long? = null) {
val timeForAll = getTimeForAll(true) val timeForAll = getTimeForAll(true)
val defSeconds = if (id == null) timeForAll else chatIdsToDuration[id] ?: timeForAll val defSeconds = if (id == null) timeForAll else chatLivePeriods[id] ?: timeForAll
val (defHours, defMinutes) = secondsToHoursAndMinutes(defSeconds) val (defHours, defMinutes) = secondsToHoursAndMinutes(defSeconds)
TimePickerDialog( TimePickerDialog(
context, context,
@ -155,10 +155,10 @@ class SetTimeDialogFragment : DialogFragment() {
TimeUnit.MINUTES.toSeconds(minutes.toLong()) TimeUnit.MINUTES.toSeconds(minutes.toLong())
if (seconds >= ShareLocationHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC) { if (seconds >= ShareLocationHelper.MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC) {
if (id != null) { if (id != null) {
chatIdsToDuration[id] = seconds chatLivePeriods[id] = seconds
} else { } else {
chatIdsToDuration.keys.forEach { chatLivePeriods.keys.forEach {
chatIdsToDuration[it] = seconds chatLivePeriods[it] = seconds
} }
} }
updateTimeForAllRow() updateTimeForAllRow()
@ -185,7 +185,7 @@ class SetTimeDialogFragment : DialogFragment() {
private fun updateList() { private fun updateList() {
val chats: MutableList<TdApi.Chat> = mutableListOf() val chats: MutableList<TdApi.Chat> = mutableListOf()
telegramHelper.getChatList().filter { chatIdsToDuration.keys.contains(it.chatId) } telegramHelper.getChatList().filter { chatLivePeriods.keys.contains(it.chatId) }
.forEach { orderedChat -> .forEach { orderedChat ->
telegramHelper.getChat(orderedChat.chatId)?.also { chats.add(it) } telegramHelper.getChat(orderedChat.chatId)?.also { chats.add(it) }
} }
@ -214,7 +214,7 @@ class SetTimeDialogFragment : DialogFragment() {
holder.description?.text = "Some description" // FIXME holder.description?.text = "Some description" // FIXME
holder.textInArea?.apply { holder.textInArea?.apply {
visibility = View.VISIBLE visibility = View.VISIBLE
chatIdsToDuration[chat.id]?.also { text = formatDuration(it) } chatLivePeriods[chat.id]?.also { text = formatDuration(it) }
} }
holder.bottomShadow?.visibility = View.GONE holder.bottomShadow?.visibility = View.GONE
holder.itemView.setOnClickListener { holder.itemView.setOnClickListener {