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) {
var chatLocLivePeriods = mutableMapOf<Long, Long>()
var chatLivePeriods = mutableMapOf<Long, Long>()
private var shareLocationChats: Set<Long> = emptySet()
private var showOnMapChats: Set<Long> = emptySet()
@ -58,7 +58,7 @@ class TelegramSettings(private val app: TelegramApplication) {
showOnMapChats.intersect(presentChatIds)
this.showOnMapChats = showOnMapChats.toHashSet()
chatLocLivePeriods = chatLocLivePeriods.filter { (key, _) ->
chatLivePeriods = chatLivePeriods.filter { (key, _) ->
presentChatIds.contains(key)
}.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()
else -> duration
}
chatLocLivePeriods[chatId] = lp
chatLivePeriods[chatId] = lp
shareLocationChats.add(chatId)
} else {
shareLocationChats.remove(chatId)
chatLocLivePeriods.remove(chatId)
chatLivePeriods.remove(chatId)
}
this.shareLocationChats = shareLocationChats.toHashSet()
}
fun getChatExpireTime(chatId: Long) = chatLocLivePeriods[chatId]
fun getChatExpireTime(chatId: Long) = chatLivePeriods[chatId]
fun stopSharingLocationToChats() {
this.shareLocationChats = emptySet()
this.chatLocLivePeriods.clear()
this.chatLivePeriods.clear()
}
fun showChatOnMap(chatId: Long, show: Boolean) {

View file

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