Fix possible exception

This commit is contained in:
Chumva 2019-04-10 19:13:16 +03:00
parent a379fb900c
commit 849db89c5d
2 changed files with 8 additions and 4 deletions

View file

@ -35,7 +35,7 @@ class TelegramHelper private constructor() {
private const val IGNORED_ERROR_CODE = 406
private const val MESSAGE_CANNOT_BE_EDITED_ERROR_CODE = 5
private const val MAX_SEARCH_ITEMS = 100
private const val MAX_SEARCH_ITEMS = Int.MAX_VALUE
// min and max values for the Telegram API
const val MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 61

View file

@ -31,6 +31,7 @@ import net.osmand.telegram.utils.OsmandLocationUtils
import net.osmand.telegram.utils.UiUtils
import net.osmand.util.MapUtils
import org.drinkless.td.libcore.telegram.TdApi
import java.util.concurrent.ConcurrentLinkedQueue
class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearchListener,
TelegramLocationListener, TelegramCompassListener {
@ -46,9 +47,9 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
private lateinit var searchBox: EditText
private lateinit var buttonsBar: LinearLayout
private val searchedChatsIds = mutableSetOf<Long>()
private val searchedPublicChatsIds = mutableSetOf<Long>()
private val searchedContactsIds = mutableSetOf<Int>()
private val searchedChatsIds = ConcurrentLinkedQueue<Long>()
private val searchedPublicChatsIds = ConcurrentLinkedQueue<Long>()
private val searchedContactsIds = ConcurrentLinkedQueue<Int>()
private val selectedChats = HashSet<Long>()
private val selectedUsers = HashSet<Long>()
@ -269,6 +270,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
override fun onSearchContactsFinished(obj: TdApi.Users) {
log.debug("searchContactsFinished $obj")
val ids = obj.userIds
searchedContactsIds.clear()
if (ids.isNotEmpty()) {
searchedContactsIds.addAll(ids.toList())
app.runInUIThread { updateList() }
@ -278,6 +280,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
override fun onSearchChatsFinished(obj: TdApi.Chats) {
log.debug("searchChatsFinished $obj")
val ids = obj.chatIds
searchedChatsIds.clear()
if (ids.isNotEmpty()) {
searchedChatsIds.addAll(ids.toList())
app.runInUIThread { updateList() }
@ -287,6 +290,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
override fun onSearchPublicChatsFinished(obj: TdApi.Chats) {
log.debug("onSearchPublicChatsFinished $obj")
val ids = obj.chatIds
searchedPublicChatsIds.clear()
if (ids.isNotEmpty()) {
searchedPublicChatsIds.addAll(ids.toList())
app.runInUIThread { updateList() }