Merge pull request #5770 from osmandapp/TelegramUiImprovements

Telegram ui improvements
This commit is contained in:
Alexander Sytnyk 2018-08-02 16:39:37 +03:00 committed by GitHub
commit d3b1900185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 10 deletions

View file

@ -40,6 +40,7 @@
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/my_location_text_sides_margin" android:paddingLeft="@dimen/my_location_text_sides_margin"
android:layout_marginBottom="@dimen/content_padding_standard"
android:paddingRight="@dimen/my_location_text_sides_margin"> android:paddingRight="@dimen/my_location_text_sides_margin">
<LinearLayout <LinearLayout
@ -93,7 +94,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding_half" android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half" android:layout_marginRight="@dimen/content_padding_half"
android:layout_marginTop="@dimen/content_padding_standard" android:visibility="gone"
tools:background="@drawable/btn_round"> tools:background="@drawable/btn_round">
<LinearLayout <LinearLayout

View file

@ -89,7 +89,8 @@
android:layout_marginRight="4dp" android:layout_marginRight="4dp"
android:text="•" android:text="•"
android:textColor="?attr/android:textColorSecondary" android:textColor="?attr/android:textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"/> android:textSize="@dimen/list_item_description_text_size"
android:visibility="invisible" />
</LinearLayout> </LinearLayout>

View file

@ -87,7 +87,8 @@
android:layout_marginRight="4dp" android:layout_marginRight="4dp"
android:text="•" android:text="•"
android:textColor="?attr/android:textColorSecondary" android:textColor="?attr/android:textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"/> android:textSize="@dimen/list_item_description_text_size"
android:visibility="invisible" />
</LinearLayout> </LinearLayout>

View file

@ -67,6 +67,7 @@ class TelegramHelper private constructor() {
private var telegramAuthorizationRequestHandler: TelegramAuthorizationRequestHandler? = null private var telegramAuthorizationRequestHandler: TelegramAuthorizationRequestHandler? = null
private var client: Client? = null private var client: Client? = null
private var currentUser: TdApi.User? = null
private var haveFullChatList: Boolean = false private var haveFullChatList: Boolean = false
private var needRefreshActiveLiveLocationMessages: Boolean = true private var needRefreshActiveLiveLocationMessages: Boolean = true
@ -103,6 +104,8 @@ class TelegramHelper private constructor() {
fun getUser(id: Int) = users[id] fun getUser(id: Int) = users[id]
fun getCurrentUser() = currentUser
fun getUserMessage(user: TdApi.User) = fun getUserMessage(user: TdApi.User) =
usersLocationMessages.values.firstOrNull { it.senderUserId == user.id } usersLocationMessages.values.firstOrNull { it.senderUserId == user.id }
@ -133,6 +136,8 @@ class TelegramHelper private constructor() {
return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup
} }
fun isPrivateChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypePrivate
private fun isChannel(chat: TdApi.Chat): Boolean { private fun isChannel(chat: TdApi.Chat): Boolean {
return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel
} }
@ -345,6 +350,20 @@ class TelegramHelper private constructor() {
listener?.onTelegramChatsRead() listener?.onTelegramChatsRead()
} }
private fun requestCurrentUser(){
client?.send(TdApi.GetMe()) { obj ->
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) { private fun requestMessage(chatId: Long, messageId: Long, onComplete: (TdApi.Message) -> Unit) {
client?.send(TdApi.GetMessage(chatId, messageId)) { obj -> client?.send(TdApi.GetMessage(chatId, messageId)) { obj ->
when (obj.constructor) { when (obj.constructor) {
@ -589,6 +608,7 @@ class TelegramHelper private constructor() {
needRefreshActiveLiveLocationMessages = true needRefreshActiveLiveLocationMessages = true
if (haveAuthorization) { if (haveAuthorization) {
requestChats(true) requestChats(true)
requestCurrentUser()
} }
} }
val newAuthState = getTelegramAuthorizationState() val newAuthState = getTelegramAuthorizationState()

View file

@ -283,7 +283,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
holder.showOnMapState?.text = menuList[stateTextInd] holder.showOnMapState?.text = menuList[stateTextInd]
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
} else if (item is LocationItem && holder is ContactViewHolder) { } 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 { private fun getChatItemDescription(item: ChatItem): String {
return when { return when {
item.chatWithBot -> getString(R.string.shared_string_bot) item.chatWithBot -> getString(R.string.shared_string_bot)
item.privateChat -> "Chat description" // FIXME item.privateChat -> "" // FIXME
else -> { else -> {
val live = getString(R.string.shared_string_live) val live = getString(R.string.shared_string_live)
val all = getString(R.string.shared_string_all) // val all = getString(R.string.shared_string_all)
"$live ${item.liveMembersCount}$all ${item.membersCount}" "$live ${item.liveMembersCount}"
} }
} }
} }

View file

@ -95,7 +95,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
if (collapsed != appBarCollapsed) { if (collapsed != appBarCollapsed) {
appBarCollapsed = collapsed appBarCollapsed = collapsed
adjustText() adjustText()
adjustSearchBox() adjustAppbar()
optionsBtn.visibility = if (collapsed) View.VISIBLE else View.GONE optionsBtn.visibility = if (collapsed) View.VISIBLE else View.GONE
} }
} }
@ -279,6 +279,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
description.gravity = gravity 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() { private fun adjustSearchBox() {
val cornerRadiusFrom = if (appBarCollapsed) searchBoxHeight / 2 else 0 val cornerRadiusFrom = if (appBarCollapsed) searchBoxHeight / 2 else 0
val cornerRadiusTo = if (appBarCollapsed) 0 else searchBoxHeight / 2 val cornerRadiusTo = if (appBarCollapsed) 0 else searchBoxHeight / 2
@ -329,9 +340,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private fun updateList() { private fun updateList() {
val chatList = telegramHelper.getChatList() val chatList = telegramHelper.getChatList()
val chats: MutableList<TdApi.Chat> = mutableListOf() val chats: MutableList<TdApi.Chat> = mutableListOf()
val currentUser = telegramHelper.getCurrentUser()
for (orderedChat in chatList) { for (orderedChat in chatList) {
val chat = telegramHelper.getChat(orderedChat.chatId) val chat = telegramHelper.getChat(orderedChat.chatId)
if (chat != null) { if (chat != null) {
if (telegramHelper.isPrivateChat(chat)) {
if ((chat.type as TdApi.ChatTypePrivate).userId == currentUser?.id) {
continue
}
}
chats.add(chat) chats.add(chat)
} }
} }
@ -360,7 +377,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false) TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false)
holder.title?.text = chat.title holder.title?.text = chat.title
holder.description?.text = "Some description" // FIXME holder.description?.visibility = View.GONE
if (live) { if (live) {
holder.checkBox?.visibility = View.GONE holder.checkBox?.visibility = View.GONE
holder.textInArea?.visibility = View.VISIBLE holder.textInArea?.visibility = View.VISIBLE