How to Retrieve specific uid key when clicking on recyclerView an object - android

I have built an android application using firebase database. I have a recyclerView in which i saw some objects. When i click on one of the options i want to get the unique id so later i can change some values.
If it where a user i could get the id by FirebaseAuth.getInstance().getCurrentUser().getUid()
I want something like that but i cannot find it.
For example. I have those two Notifications Objects in the database.
Here when i click on one i need to get the key. I have not added the objects on a list so i can use list.get(position).getId(). Is it possible to get it from getAdapterPosition()?

Related

Retrieve firebase RTDB data into Recycleview in random

How can such scenario be implemented in a social app Android java. I have built my app with Firebase RTDB and I am retrieving the data into a Recycleview using collection.shufflelist too so that I get random data displayed.
How to add another condition to collection.shufflelist(); that will make the latest post show at the top in that same random order but post that are created within the last 24 hours should be randomly placed at the top.
I have tried to use the logic of
reference.child().orderChildBy(timestap).startAt(system.currentTime....).StopAt(1356890000...) but I only saved date into my database in Simple date format, YY-MM-DD.
So I cannot add another node to save timestamps because app already has installs in several users phone changing database structure or adding new nodes/child may affect the app.
My question now on this situation how possible is it to set my random retrieved data to have the latest at the top?

Reading and storing a set of data from Firebase Database?

I have set of data stored in Firebase Realtime Database (snapshot attached).
Click to View
I want to read this data when I press a button in my Android app and store it according to the person name, for example storing that Jack is 20 years old and Marry is an engineer, but I need to do this for more than just 3 users.
I'm able to call the data and read it but storing it in the way I described above is not working.
EDIT:
I added part of the code I'm working with, my main goal is when I click a button to call the data from Database, I'm able to do this but I can't figure out the best way to store this data in a way that I can use it. For example I want to display the name of the user and his role and age but I want to do this for as many users as available in database.
Code here

How do i differentiate between different level of users in firebaseAuth

I have two different types of users Teachers and Students . I use Firebase Auth with Email and password to Authenticate them and store them in the Firebase Real time database . My question is is there a way to create custom accesor methods such as getCurrentUser().getEmail, getDisplayname etc . I need to display different UI for different user type (Teacher/Student) from the current user-type
You got 2 type of users. So first of all, you can make only one firebase structure for both user and just add a boolean variable TEACHER that indicates if a user is a teacher or a student.
But what I usually do is to seperate the users in two different firebase structures meaning that you should create a firebase path teacher/user_id and an another student/user_id which will give you flexibility with retreiving data and display the data in different UI.

How to add users to groups in Firebase?

A newbie Firebase/Android user here, and I am attempting to create an application where users can be added to a group in my Firebase database.
I have defined my User and Group objects as per this post -
Group of users in firebase
My user and group object looks as in the above post and I understand from the documents on Firebase that in order to add a user to a group I need to also add a group reference to a user object but I do not know how I would code this.
I am just unsure of how best to add a User to a Group with Android programatically ,how would I best achieve this?
i think if you familiar with lists you will use it very well as it is very basic one that you have object of group and object of user
and all you want is to access the user and add the group object
like this
user.getGroups().add(group)

Parse.com data automatic update

I am developing a social network app that uses Parse.com as a back-end
I gave users the ability to change their name , email and profile picture (which is a parseFile)
And when users are logged in i gave them the ability to add posts
I add the posts by getting the user email and name by
ParseUser.getCurrentUser()
and saving the returned content to my ParseObject
but now the question is what if the user updated his data which is the profile picture or name or email how to update the post data dynamcly
You're going to have to write some cloud code. https://parse.com/docs/js/guide
I would create an beforeSave trigger for your users, check to see if the relevant fields are 'dirty' (have been changed), and, if they have been, create a new object of a customer class that just has a pointer to that user.
Save a pointer to the user on each post.
Create a background job that runs each day/hour/however often you want to do these updates that goes through all of your custom objects that contains a user, use Query.each() to go through each of those objects, and then do a query for all posts where the user key is equal to the user of the custom object. Then set the name/email fields as appropriate.
Make sure that when you're done, you delete all of the custom objects so that you don't continuously perform this job on more and more objects each time.
Alternatively, you could just add the user pointer to the post, and when you fetch your posts, include the user key, so that gets fetched as well. Then you can read the name/email directly from the user, which will always be dynamic. You have to make sure that your ACLs are set up so that users can't edit all of another user's info or something, though.

Categories

Resources