From dfcaa846fd34ff3a53c5ea699a400207e2baec56 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Thu, 9 Aug 2018 22:00:18 +0300 Subject: [PATCH] Extract logic for creating username into a separate method in the TelegramUiHelper --- .../telegram/helpers/TelegramUiHelper.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index 8540c8203b..7df00cc597 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -88,6 +88,17 @@ object TelegramUiHelper { else -> 0 } + fun getUserName(user: TdApi.User): String { + var name = "${user.firstName} ${user.lastName}".trim() + if (name.isEmpty()) { + name = user.username + } + if (name.isEmpty()) { + name = user.phoneNumber + } + return name + } + fun messageToLocationItem( helper: TelegramHelper, chat: TdApi.Chat, @@ -129,13 +140,7 @@ object TelegramUiHelper { return LocationItem().apply { chatId = chat.id chatTitle = chat.title - name = "${user.firstName} ${user.lastName}".trim() - if (name.isEmpty()) { - name = user.username - } - if (name.isEmpty()) { - name = user.phoneNumber - } + name = TelegramUiHelper.getUserName(user) latLon = LatLon(content.location.latitude, content.location.longitude) photoPath = helper.getUserPhotoPath(user) placeholderId = R.drawable.img_user_picture