I have a simple Firebase database:
I would like to create an Android app where everybody can posts short texts. However, on the main screen I would like to show only those posts from other users who I followed. On the example, this means that if I logged in like Mrs. Nobody into the app, I can see only the first post created by Mr. Nobody.
Is that possible? (I tried to receive every posts in "posts" and after that I could show only posts what are relevant for me, but data traffic was really high in this case)
I have another idea, but I try to find a more efficient one. My idea is to receive every relations from "relations" where follow_uid is mine. After that, I iterate through all the elements and I download those posts where uid is equals with the uid from "relations"
Related
I'm working on an android app which uses Firebase Realtime database.
This app is quite similar like a social media app with limited functionality.
The app will show the post contain text data to the users.
I'm stuck with the two problem in which I solved the first one with the help of Pagination but couldn't able to solve the second .
The problem is How can I identify if the post is already seen by the other users and then not show it again.
like other social media platforms
For example Quora, Quora will show different answer every time we open the app.
Do I need to remap my data get this functionality ?
My user object and post object will look something like this.
User{
Name;
Id;
Post;
}
Post {
dateCreated;
data;
userId;
}
My database tree structure will look something like this
ROOT
/ \
POST Users
I'm keeping the copy of the post in child node of ROOT that is POST and also in every users node to get the post posted by the user.
PS: sorry for the poor English.
If you want to
1- Show posts with NO views yet, you can filter posts where for example num_reads < 3. The num_reads will be increased everytime a user sees the post.
2- Show posts to use which the user himself didn't read yet. In this case it is better to create a collection user_post_read which will be many-to-many (ie. link user to post read). Get all posts where the is no entry for current user in user_post_read
Working with Firebase for the first time and looking for advice of setting up the right structure for my project which is basically an "offers/coupon" type starter project.
The scenario is this:
I have a node containing a list of all offers available to users
This list of offers is displayed to users after successful Firebase authentication
When a user redeems an offer, I want to be able to count/record that activity in their child node under user and hide that offer so that they cannot see it again once used.
My question is what would be the best way to do this given that offers may be added, may expire, or may change at some point in the future. So, in effect, the user should receive the list of most updated offers, minus the ones he/she have used in the past.
a) would it be more effective to have a master list of offers, and then run a cloud/server function to clone this list for each new user an track that way
Firebase Structure 1
or
b) Keep a master list of offers in one node, then track user specific offer usage
Firebase Structure 2
Appreciate your guidance
The second solution is better because you'll save bandwith. This practice is called denormalization and is a common practice when it comes to Firebase. The first solution is not good becase every time you want to display the users you donwload unnecessary data. If you want to read more details about how you can structure a Firebase database in a efficient way, please read this post, Structuring your Firebase Data correctly for a Complex App. Also, you can take a look a this tutorial, Denormalization is normal with the Firebase Database, for a better understanding.
Second solution is much good. Because in first one we are having redundancy of data in our database. And second one obviously removing that cause.
But instead of using true or false because it is only showing you, "it's available or not", so you can use a string type parameter as "expired", "going to expire" and "updated" or whatever sooo. So it. Will be able to trace all you information related to offer for particular user. I think this is your requirement also.
Happy coding.
For this question, I am not looking for specific answers, or code or anything, but moreso suggestions on what techniques to employ to accomplish my goal.
I am very new to Android development. I have a bit of a background in Java.
The App I'm looking to build would have two types of users. The Narrator and the Participant.
The Participants would fill out a few fields, and click a button. This data would be integer and string values. Nothing terribly complex. The participants don't really need any sort of feedback beyond success or failure.
The Narrator's app would receive this information, and build a list displaying the information the Participants sent. Possibly the Narrator is able to send a message to the Participant devices prompting them to fill out and send their inputs, but not necessary.
What I am looking for is direction on which sorts of methods or techniques to accomplish this. It could be accomplished over Bluetooth, but even accomplishing it over the internet is arguably better.
It would need to be able to generate a unique session that users can locate and "connect to", as well.
If there are other questions that have info that would help me, feel free to link them. I assume there are. The rub is that I wasn't exactly sure how to ask this question with enough brevity to yield useful search results.
Thanks very much.
Look at realtime cloud db solutions to create the realtime, connect to session that you want to create.
In your app create a registration activity where the user can register as a participant or narrator. Store the user details on the cloud once register with a usertype key under your user model/map.
For example to define a value to usertype use like this.
usertype = 0 for participant
usertype = 1 for narrator
For your main activity you can create 2 layouts:
Layout1 (participant)
Layout2(narrator)
When user login you read the usertype value and assign layout in the oncreate method.
Example
if(usertype==0){
setContentView(Layout1)}
Within the layouts you will add your edittexts, views and buttons as per required for narrators and participants.
You will also write your functions for narrator in its own class/void and the same for participant.
Then use the usertype value to access the defined classes/voids.
You can have a look at firebase as a realtime database or there are plenty other options.
Happy coding.
So according to your explanation, participants will send something to other users which are Narrator. So something like chat system. In that case, you can use Firebase Realtime database. First, see how Firebase real-time database works. You can check this to get an idea.
So when participants fill up something it must receive by the narrator. When participants submit something you just need to send a push notification to all participants. So when participants click on the notifications you will redirect him to a specific activity and can load the participant's submitted form in that.
I am building a social app, I have a database on firebase that is structured like this:
tJWRbfqUUbSQn5eI8ZS5vPG9znr1
bio:
coverPhotoUrl:
email:
firstname:
imgUrl:
lastname:
name:
phone:
posts
-KPN0b7QmNp8AjYy4yFl
-KPXmtvZdiQ--QjZ-j3m
-KPc7PpDkmFNU9JjlIJP
-KPc7PptOulQdrpsrGEp
-KPc7Pq6JC7bjt8-sRFU
-KPc7PqJ2651EIQWXIv6
the top level key is th user id, so i have that for every user, each user has posts too, inside the posts node, i have comments, pushed in the exact the same way as posts.
My question is that I am a bit curious about how i am going to model a Newsfeed, right now A Newsfeed to me is a list of posts from you and your everyone you are following in the exact order of the time they were posted while a timeline is just posts from the said user in that order too.
I have correctly done the timeline by just iterating over posts from the user
I have tried to do the Newsfeed part in two ways, which has bugs and I think is not very efficient
Since every user maintains a list of his followers in his own node, i made it such that anytime a user makes a post, he not only writes in his own 'posts node' but also in every other person following him's 'Newsfeed' node
Cons of this method
a. in the event of an unfollow, i am not able to remove user A's posts from User B's timeline
b. i am giving every user access to write in every other person's node, which as i have read, is not a very good practice.
Maintain the url of User A's post node in user B's Timeline node, which would solve the con B of method 1.
Cons of this method
a. I dont know how to implement it.
I dont know if there is any textbook way to do this(of course there has to be, there is only so much social network platforms out there), if there is i want to know, also if you could point me to how(not help me to) implement my method 2, i will very much appreciate it.
Also, i was following this similar question
which does not completely answer my question but looks like a very interesting approach
I think the solution you are looking for is referred to as client-side fan-out. This Firebase Blog post provides a great explanation and will point you in the right direction.
Client-side fan-out for data consistency
It looks like you need a new datastructure for keeping score who is following who. Use that information to build your newsfeed. That way there is no need for one user to write "into" another user. Every posting is only stored once for the user why created the post. If the follow and unfollow changes, you can simply recalculate on the fly which posts to include in a newsfeed
this is my first question so I hope I wont mess anything :)
I'm working on an assignment for my university class. I'm implementing Android RSS reader app. All the parsing and UI code is done but I have some problems with SQLite DB schema. I need to store two data sets - blogs that user subscribes and posts for each blog.
Blog dataset contains: blogTitle, blogUrl and rssUrl
Post dataset contains: postTitle, postUrl, postPublicationDate and two booleans (isRead and isFavourite)
There is list of all posts (sorted by postPublicationDate)
There is separate list of all favourite posts
User is able to set post as fav or "un fav" it (from both lists)
After reading post (opening it in separate Activity) post is marked as "read" - with different color on the list - after user leaves app and goes back after some time read posts are not shown (or removed from db - not sure which way is better to implement it)
Posts set as "favourite" are shown in "favourite posts" list even when already read (so they are stored permanently for as long as user removes them manually)
I think it would be wise to limit number of posts stored for each blog (again, not sure if it's necessary) and remove oldest posts (lets say the limit will be 40)
There is "blogs" list which shows all subscribed blogs (with number of unread items)
I implemented it already but I think my implementation is a little bit "hacky". All the functionality above is my own design so feel free to point out some newbie mistakes (I'm not very experienced with databases and programming in general). I hope someone will help, cause I have short deadline for this assignment... :)