remove unused ui elements and add currentUser in telegramHelper

This commit is contained in:
Chumva 2018-08-02 14:30:01 +03:00
parent e4698b416e
commit 862fd08e4c
4 changed files with 29 additions and 7 deletions

View file

@ -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">
<LinearLayout
@ -93,7 +94,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="@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">
<LinearLayout

View file

@ -67,6 +67,7 @@ class TelegramHelper private constructor() {
private var telegramAuthorizationRequestHandler: TelegramAuthorizationRequestHandler? = null
private var client: Client? = null
private var currentUser: TdApi.User? = null
private var haveFullChatList: Boolean = false
private var needRefreshActiveLiveLocationMessages: Boolean = true
@ -102,6 +103,10 @@ class TelegramHelper private constructor() {
fun getChat(id: Long) = chats[id]
fun getUser(id: Int) = users[id]
fun getCurrentUser() = currentUser
fun getCurrentUserId() = currentUser?.id
fun getUserMessage(user: TdApi.User) =
usersLocationMessages.values.firstOrNull { it.senderUserId == user.id }
@ -345,6 +350,20 @@ class TelegramHelper private constructor() {
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) {
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()

View file

@ -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}"
}
}
}

View file

@ -329,9 +329,10 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private fun updateList() {
val chatList = telegramHelper.getChatList()
val chats: MutableList<TdApi.Chat> = 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