Kotlin Messenger 10: Load User Info RecyclerView Item Click Listener
Вставка
- Опубліковано 4 жов 2024
- Now that our latest messages are showing up in our initial activity, we can move onto fetching the user information that belongs to each row. Once we display the user's info, we'll also need to click on each row to bring our app into the ChatLogActivity with the appropriate user. Let's go ahead and implement all of this in today's video!
Podcasts Course
www.letsbuildt...
Intermediate Training Core Data
www.letsbuildt...
Instagram Firebase Course
www.letsbuildt...
Facebook Group
/ 1240636442694543
Completed Source Code
www.letsbuildt...
Instagram: / buildthatapp
Twitter: / buildthatapp
Even this series are 5 years old, it still works like a charm with small modifications. Thanks a lot!!
Can u point me where is the next episode ?
Great series!!! Waiting for keyboard management video 😆 😉
Thank you Brian for the wonderful Series! waiting for the next video as well
YES! Bring us more Kotlin!!! :)
please continue this project
1. notifications
2.only friends you add appear in friends list
I have learned a lot from you and we can do the above items by learning from you
Hey Brian, I'm just coming to the end of this course and this is still by far the best kotlin tutorial playlist I've seen. If you ever get back into Kotlin I'm sure lots of us here wouldn't hesitate to buy a paid kotlin course from you. Keep up the good work!
Hey Brian! I looked up your channel again because I just wanted to say thank you for all your videos. I first started iOS programming 5 years ago as a hobby and have used your videos through out the past two years you’ve been around. Recently, I’ve just finished making my 20th fully functioning clone app without using tutorials. I’ve even sold a few scripts! I’m going to start applying to the industry, and hopefully get my first iOS job. Thank you for guiding a younger me to become a developer! You make a huge difference.
The best Kotlin course I've ever seen! Thank you very much for your job!
This was great! you just saved my degree
Can´t believe this is the end of this series, Thank you so much for this help Brian !
All your teaching tutorials are amazing, your the best out there that I have seen for sure, keep up the fantastic work, BIG THUMBS UP!!!!!!!!
you taught us how smart programmers code hats off to u man!!!!!
This was a great series! using this series I have been able to develop my very own Social Networking App. Thank-you!
Great series. Thanks for all of this
thanks for sharing knowledge and information, i liked your every video and subscribed! the reason is your way of explaining everything in details, simple english, simple logic, not skipping on even the most common things, free lessons! and compassionate about what you are doing! i learned a lot from you and still learning!
Thank you very much! I saw the 10 videos you made for this app and that helped me to learn enoght to complete an app I'm programming for a business, you are awesome, Really thanks to made this videos!. Muchas gracias maestro! Greatings from México!
Just wanted to say thank you so much for this series man, I really appreciate it. You flawlessly make every bit easy to understand, at least for me, which cannot be said for a lot of tutorials I've gone through. I'm looking forward to purchasing your kotlin course in the near future! Any update on when that's coming out? Keep on keeping on, Brian!
To do the keyboard managment: simply add the line android:windowSoftInputMode="adjustPan" in your activity on AndroidManifest.xml
Дай бог тебе здоровья добрый человек!)
Very cool lessons, thank you so much!
Thank you for everything, excelent tutorial
This was awesome, I was finally able to complete the app, great playlist, thank you!
Hey Hey.. Thank you for this exciting series..
Hi Brian, i finally understand the use of firebase along side of kotlin , you are amazing and great teacher , we need more about this series of kotlin messenger like ordering latest message at the top and mark messages which are read as well , thank yu again
I'm thinking about including a paid kotlin premium course on the website soon, so stay tuned.
@@LetsBuildThatApp can't wait
Thanks for the series Sir! .
I just wanted to know about the notification part for a new chat.
A little help will be appreciated.
Great series. Can't believe I finished it in just a couple of days. I decided to leave Xamarin in favor of Kotlin.
Hey Brian, this tutorial series has been extremely useful and by far the best Kotlin tutorial I have found. I feel like I struck gold with your channel. I was wondering whether you could do a video or explain how to order the chats (in the latest message activity), such that most recent appears at the top and also make the text bold if message is unread or have some indicator that there is an unread message.
Again thanks for the video, keep up the great work!!!
no
That's too much for tutorial 🤣
I was able to order my chats by creating another hash map and putting all the Users in there but with their 0 - timestamp as the key, then adding them to the adapter from there
private fun refreshMessages(){
adapter.clear()
val sortedMap = HashMap()
//new hashMap
latestMessagesMap.forEach {
sortedMap[0 - it.value.timestamp] = it.value
//add to new hashMap with 0 - timestamp as key
}
sortedMap.toSortedMap().values.forEach{
adapter.add(LatestMessage(it))
}
Really appreciate your video, waiting for 11th part
Thanks for this series Brian, it has been extremely helpful. I have learned how to store users in a Firebase database and how it all comes together in an Android app. I look forward to more of your videos in the future.
Great Series! This tutorial series has been extremely useful for me. Thanks man. Hope to get some new series of your soon.
Thanks Brian! These video series are absolutely awesome.
The best kotlin tutorial have i ever found
Thanks so much, highest quality tutorial series i have ever seen :)
Thanks a lot for your wonderful and awesome sessions...
I'm waiting your next video on this serie for a long time bro
I don’t even have the source code for this project on my computer anymore.
Great tutorial , i m just waiting for notifications when user send msg ... Btw thanks alot for this series 😇
Really great series!! You need to finish this one, please!
It would be great if you can add group chat messages and notifications!!
When are you uploading the next tutorial??
still waiting !!!
Thanks for this series, been super useful as I am just starting out, I have also added notifications to this in some form, just for the Latest Messages activity, so if a user clicks the message and they didn't send it then the DB will be updated with an additional "Read" Item on the Chat Message, when you send a message it adds an "Unread" Read receipt, this works quite well as I can then use it to update the viewholder background to the color yellow (notifying the user). The only issue is if the user is in the chat log they have seen the message so you also need to update the ReadReceipt which would be fine but the ()ListenForMessages function is always running so when a new message is added, it will automatically be set to "read" even if the user is not in the chatlog, I am unsure where to place to code in the chatlog activity so that when a new message comes in and if the user actually sees it (i..e. user is in the chat log activity) then update the DB. I understand you are no longer working on the tutorial so maybe someone in the comments has got it working :) ?
thanks man!! great tutorial!!! can't wait for the keyboard management. would definitely pay for advanced content for kotlin bro!!
Hello Brian
One item: in the class NewMessageActivity in the list appear the name and photo of the current user. This is a bug because is absurd send messages to itself. I fixed this implement the fun fetchCurrentUser that belongs to ChatLogActivity (copy/paste) and in the iteration of fetchUsersI simply put
if (user.username != currentUser?.username){
adapter.add(UserItem(user))
}
This way the current user does not appear in the RecyclerView.
Thanks for this superb tutorial.
Cool, glad you found that quirk in the program. On a side note, I message myself all the time on iMessages and Hangouts with important reminders and images so its not absurd to message yourself in my opinion.
Ok, maybe absurd is not the word. But I seems strange in an app similar to WhatsApp. I message myself too with email and similar...
It's definitely strange from a developers perspective, but at the same time a very nice option from a user's point of view.
Yup, is a clever think.
Another point: Will you implement the possibility of taking pictures with the camera?
I have the camera working for an upcoming paid kotlin course.
really appreciate your work. need more videos.
Great Teacher Brain 👍👍
Great Tutorial Sir. Waiting for your new tutorial in which new message comes in top of list with highlight or number wise 1 or 2 new message like that.
Thanks for this course !! :)
Thak you so much!!, Great series.
thank you so much!!! you're amazing, can you continue please
Thanks mate
I learned a lot!
great sir wd ua help i mad a wonderful app thnq sir
Haha finally I reach 10 without error!
thanks it was helpful
I love this, when is your next video
Great work bro!!! Waiting for Mail App. Hopefully its works to me ;)
Hello Brian, please upload next episode, please )
I juts wanna say Thank you very much Sir, I finally finished all Android kotlin tutorials from your channel, Thank you very much, you are amazing teacher. do you have plan to make tinder firestore or instagram firestore for Android Kotlin?
Thank you and I have a problem for notification. Please this tutorial series will introduce for this!!!
When will there be an instagram kotlin course ? :)
Can you show us how to put the newest messages right at the top?
hey!
I followed all your tutorials for this app, but now, how to use the timestamp and sort the list in LastMessageActivity ?
thanks!
can you make something like 3 or 4 videos to make a powerful project , to make us more practice ....it will be really awesome from you . thanks alot for everything
I have followed all these 10 videos from beginning until the end but how can I sort the message list by timestamp? It seems the messages are sorted by sender's UID but normally messages are sorted by timestamp of the latest message.
I figured out the notification part.. well mostly.. I have to figure out how to send notification when app is killed(not running). This setup will work with the app running in the background...
ok so in LatestMessageActivity you will first add this up top above the override Oncreate
lateinit var notificationManager: NotificationManager
lateinit var notificationChannel: NotificationChannel
lateinit var builder: Notification.Builder
val channelId = "com.example.notification"
val description = "Test Notification"
##############################
then under the OnCreate we will write this function..
private fun sendNoteMessage(){
notificationManager=getSystemService(Context.NOTIFICATION_SERVICE)as NotificationManager
val intent= Intent(applicationContext,LatestMessagesActivity::class.java)
val pendingIntent= PendingIntent.getActivity(this@LatestMessagesActivity,0,intent, PendingIntent.FLAG_UPDATE_CURRENT)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
notificationChannel= NotificationChannel(channelId,description, NotificationManager.IMPORTANCE_HIGH)
notificationChannel.enableLights(true)
notificationChannel.lightColor= Color.GREEN
notificationChannel.enableVibration(true)
notificationManager.createNotificationChannel(notificationChannel)
builder= Notification.Builder(this@LatestMessagesActivity, channelId)
.setContentTitle("Android")
.setContentText("New Message")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
}else{
builder= Notification.Builder(this@LatestMessagesActivity)
.setContentTitle("Android")
.setContentText("New Message")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
}
notificationManager.notify(0,builder.build())
}
#####################################
now we want to specify who is the receiver and who sent the message and of course we only want the receiving end to be notified..
Inside of the getMyLatestMessages( ) function and at the bottom of onChildChanged right after the recyclerView update call ->
we put this..
if(toId == chatMessage.toId){
sendNoteMessage()
}
#############################################################
now like I said this doesn't work when the app is killed and user gets a message.. just only when app is running or running in background but this is a good starting
point to make that happen...Here is the full edited LatestMessagesActivity script for the notifications..
################################################################
class LatestMessagesActivity : AppCompatActivity() {
companion object {
var currentUser: User? = null
}
lateinit var notificationManager: NotificationManager
lateinit var notificationChannel: NotificationChannel
lateinit var builder: Notification.Builder
val channelId = "com.example.notification"
val description = "Test Notification"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_latest_messages)
recyclerview_latest_messages.adapter = adapter
recyclerview_latest_messages.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
adapter.setOnItemClickListener{item, view ->
val intent = Intent(this, ChatLogActivity::class.java)
val row = item as LatestMessageRow
intent.putExtra(NewMessageActivity.USER_KEY, row.chatPartnerUser)
startActivity(intent)
finish()
}
getMyLatestMessages()
fetchCurrentUser()
verifyIfUserIsLoggedIn()
}
private fun sendNoteMessage(){
notificationManager=getSystemService(Context.NOTIFICATION_SERVICE)as NotificationManager
val intent= Intent(applicationContext,LatestMessagesActivity::class.java)
val pendingIntent= PendingIntent.getActivity(this@LatestMessagesActivity,0,intent, PendingIntent.FLAG_UPDATE_CURRENT)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
notificationChannel= NotificationChannel(channelId,description, NotificationManager.IMPORTANCE_HIGH)
notificationChannel.enableLights(true)
notificationChannel.lightColor= Color.GREEN
notificationChannel.enableVibration(true)
notificationManager.createNotificationChannel(notificationChannel)
builder= Notification.Builder(this@LatestMessagesActivity, channelId)
.setContentTitle("Android")
.setContentText("New Message")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
}else{
builder= Notification.Builder(this@LatestMessagesActivity)
.setContentTitle("Android")
.setContentText("New Message")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
}
notificationManager.notify(0,builder.build())
}
val latestMessagesMap = HashMap()
private fun refreshRecyclerView() {
adapter.clear()
latestMessagesMap.values.forEach {
adapter.add(LatestMessageRow(it))
}
}
private fun getMyLatestMessages() {
val toId = FirebaseAuth.getInstance().uid
val ref = FirebaseDatabase.getInstance().getReference("/latest-messages/$toId")
ref.addChildEventListener(object: ChildEventListener {
override fun onChildAdded(p0: DataSnapshot, p1: String?) {
val chatMessage = p0.getValue(ChatMessage::class.java) ?: return
latestMessagesMap[p0.key!!] = chatMessage
refreshRecyclerView()
}
override fun onChildChanged(p0: DataSnapshot, p1: String?) {
val chatMessage = p0.getValue(ChatMessage::class.java) ?: return
latestMessagesMap[p0.key!!] = chatMessage
refreshRecyclerView()
if(toId == chatMessage.toId){
sendNoteMessage()
}
}
override fun onCancelled(p0: DatabaseError) {
}
override fun onChildMoved(p0: DataSnapshot, p1: String?) {
}
override fun onChildRemoved(p0: DataSnapshot) {
}
})
}
val adapter = GroupAdapter()
private fun fetchCurrentUser() {
val uid = FirebaseAuth.getInstance().uid
val ref = FirebaseDatabase.getInstance().getReference("/users/$uid")
ref.addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(p0: DataSnapshot) {
currentUser = p0.getValue(User::class.java)
}
override fun onCancelled(p0: DatabaseError) {
}
})
}
private fun verifyIfUserIsLoggedIn(){
val uid = FirebaseAuth.getInstance().uid
if(uid == null) {
val intent = Intent(this, ProfileActivity::class.java)
startActivity(intent)
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when(item.itemId) {
R.id.menu_new_message -> {
val intent = Intent(this, NewMessageActivity::class.java)
startActivity(intent)
}
}
return super.onOptionsItemSelected(item)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.nav_menu, menu)
return super.onCreateOptionsMenu(menu)
}
}
###############
YOUR WELCOME lol
######################
Hi bro, thank u very much for the code, it really helped me a lot. One thing that i want in that is the message that should be shown in the notification should be the latest message along with the user name, i figured out the latest message part but cannot figure how to access the username. Please suggest me some ideas.
.......
private fun sendNoteMessage(text:String){
....
....
.setContentText(text)
....
....
}
Then in onchildChanged,
....
...
sendNoteMessage(chatMessage.text)
...
////////
Please tell me how do i pass anothet string which should contain the username of the sender
Thanks
@@davidwarner2491 wat I have done to accomplish this was to make another class to send to the user..
class NotifyUser(val id:String, val uid:String, val username:String, val text:String) now make another payload
but just send to user uid only like
("/notifications/$uid").push()
when u send the actual message
this will give access to the values of name and text when calling the list from firebase.. after the notification alerts the user have the notification delete itself from list by the id value..
val ref = Firebase bla bla("/notification/$uid/$id")
ref.setValue(null)
now a little tid bit.. if you want to have notifications to alert users even when the app is not running.. You want to launch a foreground service and have an addValueEventListener to constantly read new notifications from the users notification directory.. You can also start the foreground automatically when the device successfully boots up/starts from off position by calling a broadcast receiver and starting foreground when bootup is complete.. Hope this points you in the right direction.. P.s. im a girl bruh lol... happy coding =)
Thank u very much, your hints helped me a lot. Sorry for late reply. Thanks 'girl'!😅
@@davidwarner2491 np hun. I'm actually working on a tutorial series that goes over a lot that this tutorial series didnt such as password encryption on signup. 2 step email verification upon signup. 2 step password recovery and re-encrypt password. Sending pictures and videos in chat messages. How to block contacts. How to ublock contacts.
Firebase(Realtime)security rules and indexing for faster quering. Foreground service for constant notification handeling. And the onbootcomplete broadcast reciever to activate the forground service when device boots up. And yes android part all in kotlin. If you would like for me to send you the link when i post the tutorial let me know... 😊
@@pixelfox119 Sure why not, I would be very glad to watch it. I have also been working on this project, and I have created the profile page and how to update our profile and to see others profile, annd I am working on adding friends and groups too. I won't be making any tutorial series but would be glad to share with you. You can share your link here or on my gmail, www.belligerent@gmail.com .All the best for your tutorials.👍
You are god
How do i add on click listener on chatlogActivity two kinds of views.
still looking forward for the next lesson)
This was really great. Lets compete with Whatsapp bro...!
Excellent video, can you explain how to add stickers and upload images?
please continue this course
more kotlin!!!!!!!!!!
Anyone know how to fix the issue of having two app icons, one for registration page and one for login page?
you r awesome
Awesome...
Hi Brian, really like your vids. Great job. Will you continue in this Kotlin Messenger series? Thank you.
Can you kindly answer me? Thank you.
Hi i want to know if this series is finish ?
will there be continuation to these videos :(
there is one question when we go the chatlog from latest msg and send new msg it creates new thread in db and doesnt post msg why? and why is the login user also been seen in contacts list
Hi Brian! How can I enable notifications when new message arrivers?
thanks,,,please upload more tutorial kotlin android studio
putExtra does not work, how to solve the problem?
hello there!! thanks for the videos. The app allows to send emojis but when I try to send picture or GIF, it says text field does not support image or GIF insertion. Also how can I send voice recorded messages?
sir next video that u were told about?
how to display latest msg on top refresh recycler view not displaying on top
Hey Brian, do you have plan for making series on react native
I need help with something, the application is running, but when I click the send button sends a blank message what should I do?
hiii ...Do you have iOS swift + firestore videos if yes please provide the link . thanks
niiiiice
Anyone else's chats not loading correctly on the main screen? Only the text is loading for me, not the picture or the person's name
Just check yours against the source code
Hello where is the keyboard management
I mean ep 11 of Kotlin Messenger series
It’s in the making!
@@LetsBuildThatApp ok . Your toturials are next level , I'm a beginner to Android Studio and any programming language.
Thanks for making such outstanding toturials.
I hope it lasts long.
Maybe next year we’ll finally get that lesson :)
@@LetsBuildThatApp That is too far
Hey i just went inside my manifest and underneath the android name i put
android:windowSoftInputMode="adjustPan"
I hope this helps!
Hello sir can you make a code if the user is online or offline??
hello sir
could you please add how to send image and audio file
I missed the keyboard management part or what??
no more videos :(
❤️❤️
also add offline compatibility to it
Followed it word for word and went back to lessons to make sure everything was correct. No text or profile images come up on the chat screen and nothing on the recent messaged either.
Not sure, the sample download source code should be working still.
@@LetsBuildThatApp Let me check it out and I'll let you know
Had a look and yeah, It's being weird/glitchy when I used your sourced one, chat text doesn't come up but recent messages do pop up.... I dunno dude :/
It’s possible something changed with firebase then.
@@LetsBuildThatApp Yeah that's what I thought too 🤔
search recycleview with groupadapter please
where's the rest of the course :(
I think I shot this last episode 10 after I got back from my shanghai trip....Not sure if I even remember the source code for this project haha.
@@LetsBuildThatApp hope you will continue this awesome tutorial series :)
Чел, ну такой код нужно реально править, разделение на классы как миниму, расширяемость.....
DO STORY BAR PLEASE
hi thank you a lot. you helped me to be comfortable in kotlin but i have one problem. android studio is too slow to the extent that i can't do my project at all is there any alternative for android studio or can I use intellj ide and emulator to create android apps please may you help me please coz i have stop everything about android app and if it's possible can you make a tutorials to do that?. or i have forgotten to mention my Computer features i5 8 ram 500gb hard disk. i can't wait to see your reply
I feel you man. I have to restart android studio many times a day.
Lets Build That App i haven't understood
Hey, I've heard that you can also use Kotlin native for IOS development, is that practicle? or has a future?, I recently started learning programming (with kotlin) :P
Swift isn't too bad, I'd say learn Swift instead of some janky cross platform solution.
+Lets Build That App hello teatcher
thank you for this work
How to build app like instagram
how to make a multichat?