From b05d510c446525f2ea0b3ff8c271a313565ec631 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 5 Sep 2018 11:28:39 +0300 Subject: [PATCH] Rename request code and fix OsmAnd Bot icon on map --- .../telegram/helpers/ShowLocationHelper.kt | 8 ++++---- .../osmand/telegram/ui/LiveNowTabFragment.kt | 18 ++++++++---------- .../osmand/telegram/ui/SortByBottomSheet.kt | 6 +++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index 1776270e9e..1e5ebe5ab6 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -76,11 +76,11 @@ class ShowLocationHelper(private val app: TelegramApplication) { val chatId = message.chatId val chatTitle = telegramHelper.getChat(message.chatId)?.title val content = message.content + val date = telegramHelper.getLastUpdatedTime(message) + val stale = System.currentTimeMillis() / 1000 - date > app.settings.staleLocTime if (chatTitle != null && content is TdApi.MessageLocation) { var userName = "" var photoPath: String? = null - val date = telegramHelper.getLastUpdatedTime(message) - val stale = System.currentTimeMillis() / 1000 - date > app.settings.staleLocTime val user = telegramHelper.getUser(message.senderUserId) if (user != null) { userName = "${user.firstName} ${user.lastName}".trim() @@ -113,10 +113,10 @@ class ShowLocationHelper(private val app: TelegramApplication) { setupMapLayer() if (update) { osmandAidlHelper.updateMapPoint(MAP_LAYER_ID, "${chatId}_$name", name, name, - chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, null) + chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, generatePhotoParams(null, stale)) } else { osmandAidlHelper.addMapPoint(MAP_LAYER_ID, "${chatId}_$name", name, name, - chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, null) + chatTitle, Color.WHITE, ALatLon(content.lat, content.lon), null, generatePhotoParams(null, stale)) } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index ebbbc8ec7e..dbfb0e9df1 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -128,7 +128,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage super.onActivityResult(requestCode, resultCode, data) when (requestCode) { ChooseOsmAndBottomSheet.OSMAND_CHOSEN_REQUEST_CODE -> updateOpenOsmAndIcon() - SortByBottomSheet.SORT_BY_REQUEST_CODE -> { + SortByBottomSheet.SORTING_CHANGED_REQUEST_CODE -> { updateSortBtn() updateList() } @@ -279,9 +279,8 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage } } } - sortAdapterItems(res) - adapter.items = res + adapter.items = sortAdapterItems(res) } private fun sortAdapterItems(list: MutableList): MutableList { @@ -413,14 +412,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage override fun onBindViewHolder(holder: BaseViewHolder, position: Int) { val lastItem = position == itemCount - 1 val item = items[position] + val sortByGroup = settings.liveNowSortType.isSortByGroup() val canBeOpenedOnMap = item.canBeOpenedOnMap() - && (settings.liveNowSortType.isSortByGroup() && !telegramHelper.isBot(item.userId) - || !settings.liveNowSortType.isSortByGroup()) val openOnMapView = holder.getOpenOnMapClickView() val staleLocation = System.currentTimeMillis() / 1000 - item.lastUpdated > settings.staleLocTime if (staleLocation) { - val photoPath = if (settings.liveNowSortType.isSortByGroup() && item is ChatItem && !item.privateChat) { + val photoPath = if (sortByGroup && item is ChatItem && !item.privateChat) { item.photoPath } else { item.grayscalePhotoPath @@ -430,7 +428,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, R.drawable.img_user_picture_active, false) } - holder.title?.text = if (settings.liveNowSortType.isSortByGroup()) item.getVisibleName() else item.name + holder.title?.text = if (sortByGroup) item.getVisibleName() else item.name openOnMapView?.isEnabled = canBeOpenedOnMap if (canBeOpenedOnMap) { openOnMapView?.setOnClickListener { @@ -458,10 +456,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE if (item is ChatItem && holder is ChatViewHolder) { - val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !settings.liveNowSortType.isSortByGroup()) + val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !sortByGroup) val chatId = item.chatId val stateTextInd = if (settings.isShowingChatOnMap(chatId)) 1 else 0 - val groupDescrRowVisible = !settings.liveNowSortType.isSortByGroup() + val groupDescrRowVisible = !sortByGroup && (!item.privateChat || item.chatWithBot) if (groupDescrRowVisible) { @@ -477,7 +475,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) } holder.showOnMapState?.text = menuList[stateTextInd] holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE - holder.topDivider?.visibility = if (!settings.liveNowSortType.isSortByGroup() && position != 0) View.GONE else View.VISIBLE + holder.topDivider?.visibility = if (!sortByGroup && position != 0) View.GONE else View.VISIBLE } else if (item is LocationItem && holder is ContactViewHolder) { holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr) } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SortByBottomSheet.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SortByBottomSheet.kt index 7c2808e3e7..228ade466e 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SortByBottomSheet.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SortByBottomSheet.kt @@ -64,7 +64,7 @@ class SortByBottomSheet : DialogFragment() { setOnClickListener { app.settings.liveNowSortType = sortType targetFragment?.also { target -> - target.onActivityResult(targetRequestCode, SORT_BY_REQUEST_CODE, null) + target.onActivityResult(targetRequestCode, SORTING_CHANGED_REQUEST_CODE, null) } dismiss() } @@ -82,7 +82,7 @@ class SortByBottomSheet : DialogFragment() { companion object { - const val SORT_BY_REQUEST_CODE = 3 + const val SORTING_CHANGED_REQUEST_CODE = 3 private const val TAG = "SortByBottomSheet" @@ -92,7 +92,7 @@ class SortByBottomSheet : DialogFragment() { ): Boolean { return try { SortByBottomSheet().apply { - setTargetFragment(target, SORT_BY_REQUEST_CODE) + setTargetFragment(target, SORTING_CHANGED_REQUEST_CODE) show(fm, TAG) } true