Fix updating of current user photo on first start

This commit is contained in:
Alex Sytnyk 2018-09-07 12:40:39 +03:00
parent 46382bf3de
commit f314d480ba
2 changed files with 23 additions and 10 deletions

View file

@ -496,7 +496,13 @@ class TelegramHelper private constructor() {
listener?.onTelegramError(error.code, error.message) listener?.onTelegramError(error.code, error.message)
} }
} }
TdApi.User.CONSTRUCTOR -> currentUser = obj as TdApi.User TdApi.User.CONSTRUCTOR -> {
val currUser = obj as TdApi.User
currentUser = currUser
if (!hasLocalUserPhoto(currUser) && hasRemoteUserPhoto(currUser)) {
requestUserPhoto(currUser)
}
}
} }
} }
} }
@ -1219,7 +1225,6 @@ class TelegramHelper private constructor() {
chat.photo?.small = updateFile.file chat.photo?.small = updateFile.file
} }
listener?.onTelegramChatChanged(chat) listener?.onTelegramChatChanged(chat)
return
} }
val user = downloadUserFilesMap.remove(remoteId) val user = downloadUserFilesMap.remove(remoteId)
if (user != null) { if (user != null) {
@ -1227,7 +1232,6 @@ class TelegramHelper private constructor() {
user.profilePhoto?.small = updateFile.file user.profilePhoto?.small = updateFile.file
} }
listener?.onTelegramUserChanged(user) listener?.onTelegramUserChanged(user)
return
} }
} }
} }

View file

@ -50,6 +50,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private lateinit var appBarLayout: AppBarLayout private lateinit var appBarLayout: AppBarLayout
private lateinit var imageContainer: FrameLayout private lateinit var imageContainer: FrameLayout
private lateinit var currentUserIcon: ImageView
private lateinit var textContainer: LinearLayout private lateinit var textContainer: LinearLayout
private lateinit var titleContainer: LinearLayout private lateinit var titleContainer: LinearLayout
private lateinit var optionsBtn: ImageView private lateinit var optionsBtn: ImageView
@ -119,13 +120,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
}) })
} }
TelegramUiHelper.setupPhoto( currentUserIcon = mainView.findViewById(R.id.user_icon)
app,
mainView.findViewById(R.id.user_icon),
telegramHelper.getUserPhotoPath(telegramHelper.getCurrentUser()),
R.drawable.img_user_placeholder,
false
)
optionsBtn = mainView.findViewById<ImageView>(R.id.options) optionsBtn = mainView.findViewById<ImageView>(R.id.options)
with(activity as MainActivity) { with(activity as MainActivity) {
@ -203,6 +198,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateCurrentUserPhoto()
telegramHelper.getActiveLiveLocationMessages(null) telegramHelper.getActiveLiveLocationMessages(null)
updateContent() updateContent()
updateEnable = true updateEnable = true
@ -265,6 +261,9 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
override fun onTelegramUserChanged(user: TdApi.User) { override fun onTelegramUserChanged(user: TdApi.User) {
if (user.id == telegramHelper.getCurrentUser()?.id) {
updateCurrentUserPhoto()
}
updateContent() updateContent()
} }
@ -289,6 +288,16 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} }
} }
private fun updateCurrentUserPhoto() {
TelegramUiHelper.setupPhoto(
app,
currentUserIcon,
telegramHelper.getUserPhotoPath(telegramHelper.getCurrentUser()),
R.drawable.img_user_placeholder,
false
)
}
private fun startHandler() { private fun startHandler() {
val updateAdapter = Handler() val updateAdapter = Handler()
updateAdapter.postDelayed({ updateAdapter.postDelayed({