From 862fd08e4c559708c9613b014249e53f7b2b76e9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 14:30:01 +0300 Subject: [PATCH 1/7] remove unused ui elements and add currentUser in telegramHelper --- .../res/layout/fragment_my_location_tab.xml | 3 ++- .../osmand/telegram/helpers/TelegramHelper.kt | 20 +++++++++++++++++++ .../osmand/telegram/ui/LiveNowTabFragment.kt | 8 ++++---- .../telegram/ui/MyLocationTabFragment.kt | 5 +++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml index 15af1401cb..5de891c56c 100644 --- a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml +++ b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml @@ -40,6 +40,7 @@ android:animateLayoutChanges="true" android:orientation="vertical" android:paddingLeft="@dimen/my_location_text_sides_margin" + android:layout_marginBottom="@dimen/content_padding_standard" android:paddingRight="@dimen/my_location_text_sides_margin"> + when (obj.constructor) { + TdApi.Error.CONSTRUCTOR -> { + val error = obj as TdApi.Error + if (error.code != IGNORED_ERROR_CODE) { + listener?.onTelegramError(error.code, error.message) + } + } + TdApi.User.CONSTRUCTOR -> currentUser = obj as TdApi.User + } + } + } + private fun requestMessage(chatId: Long, messageId: Long, onComplete: (TdApi.Message) -> Unit) { client?.send(TdApi.GetMessage(chatId, messageId)) { obj -> when (obj.constructor) { @@ -589,6 +608,7 @@ class TelegramHelper private constructor() { needRefreshActiveLiveLocationMessages = true if (haveAuthorization) { requestChats(true) + requestCurrentUser() } } val newAuthState = getTelegramAuthorizationState() diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index fd9f8b7812..d93ac18973 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -283,7 +283,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage holder.showOnMapState?.text = menuList[stateTextInd] holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE } else if (item is LocationItem && holder is ContactViewHolder) { - holder.description?.text = "Some description" + holder.description?.visibility = View.GONE } } @@ -292,11 +292,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage private fun getChatItemDescription(item: ChatItem): String { return when { item.chatWithBot -> getString(R.string.shared_string_bot) - item.privateChat -> "Chat description" // FIXME + item.privateChat -> "" // FIXME else -> { val live = getString(R.string.shared_string_live) - val all = getString(R.string.shared_string_all) - "$live ${item.liveMembersCount} • $all ${item.membersCount}" +// val all = getString(R.string.shared_string_all) + "$live ${item.liveMembersCount}" } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 19ac3bed8a..302215ebd3 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -329,9 +329,10 @@ class MyLocationTabFragment : Fragment(), TelegramListener { private fun updateList() { val chatList = telegramHelper.getChatList() val chats: MutableList = mutableListOf() + val currentUserId = telegramHelper.getCurrentUserId() for (orderedChat in chatList) { val chat = telegramHelper.getChat(orderedChat.chatId) - if (chat != null) { + if (chat != null && (chat.id != currentUserId?.toLong())) { chats.add(chat) } } @@ -360,7 +361,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false) holder.title?.text = chat.title - holder.description?.text = "Some description" // FIXME + holder.description?.visibility = View.GONE if (live) { holder.checkBox?.visibility = View.GONE holder.textInArea?.visibility = View.VISIBLE From 3b1a79c079b4bba19eedfdca21e0c343966a5ba0 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 14:57:08 +0300 Subject: [PATCH 2/7] add check for private chat --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 6 ++++-- .../src/net/osmand/telegram/ui/MyLocationTabFragment.kt | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 8b7fc8f069..e908f62875 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -106,8 +106,6 @@ class TelegramHelper private constructor() { fun getCurrentUser() = currentUser - fun getCurrentUserId() = currentUser?.id - fun getUserMessage(user: TdApi.User) = usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } @@ -138,6 +136,10 @@ class TelegramHelper private constructor() { return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup } + fun isPrivateChat(chat: TdApi.Chat): Boolean { + return chat.type is TdApi.ChatTypePrivate + } + private fun isChannel(chat: TdApi.Chat): Boolean { return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 302215ebd3..cd89ad6953 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -329,10 +329,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener { private fun updateList() { val chatList = telegramHelper.getChatList() val chats: MutableList = mutableListOf() - val currentUserId = telegramHelper.getCurrentUserId() + val currentUser = telegramHelper.getCurrentUser() for (orderedChat in chatList) { val chat = telegramHelper.getChat(orderedChat.chatId) - if (chat != null && (chat.id != currentUserId?.toLong())) { + if (chat != null) { + if (telegramHelper.isPrivateChat(chat)) { + if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) { + continue + } + } chats.add(chat) } } From c8acf1829498a1874e99f2e409d244fe1021cedd Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 15:19:34 +0300 Subject: [PATCH 3/7] remove unnecessary code --- .../src/net/osmand/telegram/helpers/TelegramHelper.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index e908f62875..cf72e507b5 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -136,9 +136,7 @@ class TelegramHelper private constructor() { return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup } - fun isPrivateChat(chat: TdApi.Chat): Boolean { - return chat.type is TdApi.ChatTypePrivate - } + fun isPrivateChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypePrivate private fun isChannel(chat: TdApi.Chat): Boolean { return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel From f58498dee922c9da715e2ebc0a90eaa93a9d46b7 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 15:29:41 +0300 Subject: [PATCH 4/7] remove animation and unnecessary dots --- .../res/layout/live_now_chat_card.xml | 3 ++- OsmAnd-telegram/res/layout/user_list_item.xml | 3 ++- .../osmand/telegram/ui/MyLocationTabFragment.kt | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/OsmAnd-telegram/res/layout/live_now_chat_card.xml b/OsmAnd-telegram/res/layout/live_now_chat_card.xml index 5ed191d2e7..4abb6b3c18 100644 --- a/OsmAnd-telegram/res/layout/live_now_chat_card.xml +++ b/OsmAnd-telegram/res/layout/live_now_chat_card.xml @@ -89,7 +89,8 @@ android:layout_marginRight="4dp" android:text="•" android:textColor="?attr/android:textColorSecondary" - android:textSize="@dimen/list_item_description_text_size"/> + android:textSize="@dimen/list_item_description_text_size" + android:visibility="invisible" /> diff --git a/OsmAnd-telegram/res/layout/user_list_item.xml b/OsmAnd-telegram/res/layout/user_list_item.xml index da4e6a1c41..a96bd241fa 100644 --- a/OsmAnd-telegram/res/layout/user_list_item.xml +++ b/OsmAnd-telegram/res/layout/user_list_item.xml @@ -87,7 +87,8 @@ android:layout_marginRight="4dp" android:text="•" android:textColor="?attr/android:textColorSecondary" - android:textSize="@dimen/list_item_description_text_size"/> + android:textSize="@dimen/list_item_description_text_size" + android:visibility="invisible" /> diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index cd89ad6953..f1ddd453cb 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -292,17 +292,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener { cornerRadiusTo.toFloat() ) - val marginAnimator = ValueAnimator.ofInt(marginFrom, marginTo) - marginAnimator.addUpdateListener { - val value = it.animatedValue as Int - val params = searchBox.layoutParams as LinearLayout.LayoutParams - params.setMargins(value, params.topMargin, value, params.bottomMargin) - searchBox.layoutParams = params - } +// val marginAnimator = ValueAnimator.ofInt(marginFrom, marginTo) +// marginAnimator.addUpdateListener { +// val value = it.animatedValue as Int +// val params = searchBox.layoutParams as LinearLayout.LayoutParams +// params.setMargins(value, params.topMargin, value, params.bottomMargin) +// searchBox.layoutParams = params +// } AnimatorSet().apply { duration = 200 - playTogether(cornerAnimator, marginAnimator) + play(cornerAnimator) addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { updateTitleTextColor() From b63d5c0992cd180acd71fbea74f866df8984e295 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 15:41:16 +0300 Subject: [PATCH 5/7] remove cornerAnimator --- .../telegram/ui/MyLocationTabFragment.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index f1ddd453cb..8332057d09 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -280,17 +280,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } private fun adjustSearchBox() { - val cornerRadiusFrom = if (appBarCollapsed) searchBoxHeight / 2 else 0 - val cornerRadiusTo = if (appBarCollapsed) 0 else searchBoxHeight / 2 - val marginFrom = if (appBarCollapsed) searchBoxSidesMargin else 0 - val marginTo = if (appBarCollapsed) 0 else searchBoxSidesMargin +// val cornerRadiusFrom = if (appBarCollapsed) searchBoxHeight / 2 else 0 +// val cornerRadiusTo = if (appBarCollapsed) 0 else searchBoxHeight / 2 +// val marginFrom = if (appBarCollapsed) searchBoxSidesMargin else 0 +// val marginTo = if (appBarCollapsed) 0 else searchBoxSidesMargin - val cornerAnimator = ObjectAnimator.ofFloat( - searchBoxBg, - "cornerRadius", - cornerRadiusFrom.toFloat(), - cornerRadiusTo.toFloat() - ) +// val cornerAnimator = ObjectAnimator.ofFloat( +// searchBoxBg, +// "cornerRadius", +// cornerRadiusFrom.toFloat(), +// cornerRadiusTo.toFloat() +// ) // val marginAnimator = ValueAnimator.ofInt(marginFrom, marginTo) // marginAnimator.addUpdateListener { @@ -302,7 +302,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { AnimatorSet().apply { duration = 200 - play(cornerAnimator) +// playTogether(cornerAnimator, marginAnimator) addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { updateTitleTextColor() From d4bbebda49d3feee68eabb2d5967cec6a5d3e80c Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 16:17:02 +0300 Subject: [PATCH 6/7] add adjustAppbar method --- .../telegram/ui/MyLocationTabFragment.kt | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 8332057d09..85b9eaa08d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -95,7 +95,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { if (collapsed != appBarCollapsed) { appBarCollapsed = collapsed adjustText() - adjustSearchBox() + adjustAppbar() optionsBtn.visibility = if (collapsed) View.VISIBLE else View.GONE } } @@ -279,44 +279,50 @@ class MyLocationTabFragment : Fragment(), TelegramListener { description.gravity = gravity } + private fun adjustAppbar() { + updateTitleTextColor() + if (Build.VERSION.SDK_INT >= 21) { + if (appBarCollapsed) { + appBarLayout.outlineProvider = appBarOutlineProvider + } else { + appBarLayout.outlineProvider = null + } + } + } + private fun adjustSearchBox() { -// val cornerRadiusFrom = if (appBarCollapsed) searchBoxHeight / 2 else 0 -// val cornerRadiusTo = if (appBarCollapsed) 0 else searchBoxHeight / 2 -// val marginFrom = if (appBarCollapsed) searchBoxSidesMargin else 0 -// val marginTo = if (appBarCollapsed) 0 else searchBoxSidesMargin + val cornerRadiusFrom = if (appBarCollapsed) searchBoxHeight / 2 else 0 + val cornerRadiusTo = if (appBarCollapsed) 0 else searchBoxHeight / 2 + val marginFrom = if (appBarCollapsed) searchBoxSidesMargin else 0 + val marginTo = if (appBarCollapsed) 0 else searchBoxSidesMargin -// val cornerAnimator = ObjectAnimator.ofFloat( -// searchBoxBg, -// "cornerRadius", -// cornerRadiusFrom.toFloat(), -// cornerRadiusTo.toFloat() -// ) + val cornerAnimator = ObjectAnimator.ofFloat( + searchBoxBg, + "cornerRadius", + cornerRadiusFrom.toFloat(), + cornerRadiusTo.toFloat() + ) -// val marginAnimator = ValueAnimator.ofInt(marginFrom, marginTo) -// marginAnimator.addUpdateListener { -// val value = it.animatedValue as Int -// val params = searchBox.layoutParams as LinearLayout.LayoutParams -// params.setMargins(value, params.topMargin, value, params.bottomMargin) -// searchBox.layoutParams = params -// } + val marginAnimator = ValueAnimator.ofInt(marginFrom, marginTo) + marginAnimator.addUpdateListener { + val value = it.animatedValue as Int + val params = searchBox.layoutParams as LinearLayout.LayoutParams + params.setMargins(value, params.topMargin, value, params.bottomMargin) + searchBox.layoutParams = params + } AnimatorSet().apply { duration = 200 -// playTogether(cornerAnimator, marginAnimator) + playTogether(cornerAnimator, marginAnimator) addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { - updateTitleTextColor() - if (appBarCollapsed && Build.VERSION.SDK_INT >= 21) { - appBarLayout.outlineProvider = appBarOutlineProvider - } + adjustAppbar() } }) start() } - if (!appBarCollapsed && Build.VERSION.SDK_INT >= 21) { - appBarLayout.outlineProvider = null - } + adjustAppbar() } private fun updateTitleTextColor() { From 526f763224072bf4b5f725d75f0bbcab7803d358 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 2 Aug 2018 16:35:32 +0300 Subject: [PATCH 7/7] remove unnecessary changes --- .../src/net/osmand/telegram/ui/MyLocationTabFragment.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 85b9eaa08d..cddf3b3ff0 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -316,13 +316,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener { playTogether(cornerAnimator, marginAnimator) addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { - adjustAppbar() + updateTitleTextColor() + if (appBarCollapsed && Build.VERSION.SDK_INT >= 21) { + appBarLayout.outlineProvider = appBarOutlineProvider + } } }) start() } - adjustAppbar() + if (!appBarCollapsed && Build.VERSION.SDK_INT >= 21) { + appBarLayout.outlineProvider = null + } } private fun updateTitleTextColor() {