Hello!
Worth the task: upload user data, which includes: name, last name, ID photo and photo itself. After clicking on the rendered photo, it is necessary to open it in full size with some additional information on it, such as likes. There was a problem with the likes information. The server method, which provides information on these likes, prohibits making more than 3 requests per second. The solution immediately suggests itself: make a request to the server by clicking on a photo (see the FriendsInfoHolder code example). However, in the dialog box, when you first click on the photo, the previous value of the likes counter is displayed. The second press displays the correct amount. Tell me, please, how to solve this problem, if possible, with code examples.
RecyclerView is used, mThumbnailDownloader is a class object inherited from HandlerThread (I use it to load images in the background thread)
private inner class FriendInfoHolder(inflater: LayoutInflater, parent: ViewGroup) : RecyclerView.ViewHolder(inflater.inflate(R.layout.friends_list_fragment, parent, false)),View.OnClickListener { private lateinit var mFriend: Friends init { itemView.setOnClickListener(this) } override fun onClick(p0: View?) { val photoUrl = mFriend.mPhoto photoId = mFriend.mPhotoId FetchPhotoInfoTask().execute() var photo = mThumbnailDownloader.getBitmapFromCache(photoUrl) val outputStream = ByteArrayOutputStream() photo!!.compress(Bitmap.CompressFormat.PNG, 100, outputStream) //TODO проверить на NULL загруженную фотку val photoBytes = outputStream.toByteArray() val dialog = PhotoDialogFragment.newInstance(photoBytes, likesCounter) val manager = fragmentManager dialog.show(manager, DIALOG_PHOTO) } private val mFirstName: TextView = itemView.findViewById(R.id.first_name) private val mLastName: TextView = itemView.findViewById(R.id.last_name) private val mPhoto: ImageView = itemView.findViewById(R.id.friend_photo) fun bindFriend( friend: Friends, thumbnail: Drawable ) { mFriend = friend mFirstName.text = friend.mFirstName mLastName.text = friend.mLastName mPhoto.setImageDrawable(thumbnail) }}