Loggin orders in firebase (Android application) - java

I have created a resturaunt app for android in Android studio. I am using firebase to store the data. Each month i will bill the resturaunt 1 dollar per order made via the app. So i need some way to register each order and sort it by month. This has me kinda stumped so i don't want to release yet. Any help would be deeply appreciated.
What i would like is to have a table "Orders" with the 12 months. And i want to store a variable "amount" for each month. Like in the image below here:
https://imgur.com/gy8HgSg
whenever an order is submitted i want to get the value of "amount" for the specific month and then increase it by 1. This was the only way i could think of, i am sure there would be better ways and i am very open to suggestions.

Related

Advanced filtering of a list with typo-tolerance, counting, user-specific etc.?

I am building an Android application, later on maybe also an iOS version of the app and a web application. I have a list, for example in this way:
City Name
State
Counter Clicked
More columns
Dallas
Texas
4
…
Boston
Massachusetts
3
…
New York City
New York
1
…
San Francisco
California
3
…
San Diego
California
3
…
Seattle
Washington
10
…
Boise
Idaho
0
…
I am searching for a solution how to meet the following requirements:
The list and its data are always up to date and transferred from a backend system (Google Firebase) when the user is online.
The solution needs to work on iOS / Android devices and if possible also on a website.
Typing in "D" only "Dallas" should be displayed.
Typing in "S" Seattle, San Diego, and San Francisco should be displayed in this order, because of the "Counter Clicked" value (the higher the value, the more relevant is the result)
Typing in "S" also Dallas, Boston, Boise should be displayed in this order (regarding "Counter Clicked") after the words beginning with "S", because they are containing the letter "S" within the word.
The "Counter Clicked" is handled per user. So the City Name can be selected and every time the user selects the city name, the "counter clicked" should be increased by 1.
The filter service should be offline ready, so the "Counter Clicked" should be handled on the device. I am not quite sure if it makes sense to upload the data back to the Firebase backend server, what do you think?
It would be great to have a typo tolerance. So for example typing "Bostn" or "Sen" (tolerance by one letter) "Boston" or "San …" should be displayed.
I will also have the possibility to have a facet filter so that I can filter before typing for one of the "State"s of the USA.
I am interested in a professional solution if this is available on the market, otherwise, I need to build it for myself.
I am building an Android application, later on maybe also an iOS version of the app and a web application.
You can achieve that using Firebase because:
Firebase is a platform developed by Google for creating mobile (iOS and Android) and web applications.
I am searching for a solution how to meet the following requirements
To answer your questions, I will use Cloud Firestore which is:
Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud. Like Firebase Realtime Database, it keeps your data in-sync across client apps through real-time listeners and offers offline support for mobile and web so you can build responsive apps that work regardless of network latency or Internet connectivity.
Let's get started:
The list and its data are always up to date and transferred from a backend system (Google Firebase) when the user is online.
You have the answer right above, "it keeps your data in-sync across client apps through realtime listeners". So your data will always up to date.
The solution needs to work on iOS / Android devices and if possible also on a website.
It will, as Firebase is a cross-platform solution.
Typing in "D" only "Dallas" should be displayed.
You can achieve that in a very simple way, by using Query's startAt() method:
Creates and returns a new Query that starts at the provided fields relative to the order of the query.
So you query should look in code like this:
ref.collection("cities").orderBy("cityName").startAt(name).endAt(name + "\uf8ff");
You can also check the docs for that, and see my answer from the following article:
How to filter Firestore data cheaper?
Typing in "S" Seattle, San Diego, and San Francisco should be displayed in this order, because of the "Counter Clicked" value (the higher the value, the more relevant is the result)
To solve this, you can use Query's orderBy(String field, Query.Direction direction) method:
Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.
So you can display those cities according to the number of the "Counter Clicked".
Typing in "S" also Dallas, Boston, Boise should be displayed in this order (regarding "Counter Clicked") after the words beginning with "S", because they are containing the letter "S" within the word.
Unfortunately, Firestore does not support full-text search. The official documentation regarding the full-text search in Cloud Firestore is up to date and stands for Algolia.
For Android, please see my answer from the following post:
Is it possible to use Algolia query in FirestoreRecyclerOptions?
Or:
Is there a way to search sub string at Firestore?
The "Counter Clicked" is handled per user. So the City Name can be selected and every time the user selects the city name, the "counter clicked" should be increased by 1.
This can be very simply achieved using FieldValue.increment(1) as explained in my answer from the following post:
What is the recommended way of saving durations in Firestore?
The filter service should be offline ready, so the "Counter Clicked" should be handled on the device. I am not quite sure if it makes sense to upload the data back to the Firebase backend server, what do you think?
According to the official documentation regarding Access data offline:
Cloud Firestore supports offline data persistence.
For Android and iOS, offline persistence is enabled by default.
For the web, offline persistence is disabled by default. To enable persistence, call the enablePersistence method.
So you have support for three platforms, and yes, it makes sense to upload the data to the server because in that way you'll always have consistent data.
It would be great to have a typo tolerance. So for example typing "Bostn" or "Sen" (tolerance by one letter) "Boston" or "San …" should be displayed.
That's nothing built-in Firestore that can help you with that. What you can do, is to create an additional field of type array and search within it. So that array might have typos like that "Bostn" or "Bston".
I will also have the possibility to have a facet filter so that I can filter before typing for one of the "State"s of the USA.
That's also nothing already built-in Firestore, but you can implement for sure something like that. Most likely you might consider defining some filters and use them before typing.
I am interested in a professional solution if this is available on the market, otherwise, I need to build it for myself.
For sure Firebase can help you achieve what you want, so I hope I was able to provide the best solutions for that.

How can I use Google Places API multiple times in a location aware app?

I am developing an app which will give you nearby Mosques within 10 km of your current location. Now that the Places API allows a certain number of queries per day, I have used firebase to store nearby Mosques for a certain location and I first check if the data is in database or not before querying. But this still doesn't solve the problem. e.g. if a user is on the go the whole day then the results must be changing every single minute, according to his/her location. How can I achieve the desirable results?
As mentioned earlier, I am saving nearby locations in a database with their relative location (around which they exist). But this doesn't quite solve the problem.
Any help will be greatly appreciated.
Places API is a commercial offering - you are meant to pay for using it, if you want to make applications around it.
There's a certain small number of calls that you can do for free, but this is only meant as testing grounds or private use. I am no lawyer, but I would guess that circumventing the fee by scraping the map (like setting a bot to go around a country to build a database of points of interests) would be illegal and would probably get you a letter from Google saying you should stop.
Use AutocompleteSessionToken class to generate a token and place it after your key , this token will reduce your usage because you can request the places api multiple times and still it will be considered as a single request. i hope this will help cause i didnt get your question very well. here is sample of the link:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=1600+Amphitheatre&key=&sessiontoken=1234567890.
For more details.see here

Overcoming a Very Long JSON String?

I am trying to build a weekly schedule, and I want to make an Android app to display it.
I have to send a Week object that contains a list of days, which contains a list of hours, which contains a list of events.
Every event has multiple variables.
The data comes from a local database I built on my PC, and on the app I set a GUI friendly query which returns the planned week in a JSON format.
Now that JSON has become 2000 lines long on the best case, and around 5000 lines worst case.
Any suggestions on how I can handle this?
Another problem is that the JSON comes back in packets, so I cannot parse parts on it until I receive it fully, and Java cannot handle such long strings.
I would suggest you to use Firebase as your database. Firebase is a cloud database which can be accessed by web and android app also. The data is kept synced at all times so you do not need to fire a different query in your app.
Just store the data in Firebase from your pc and access it via android app and display it.
Hope this helps.

Android in-app payment for physical items, where to store price information?

I am working on a Android app with the possibility to purchase a physical items. The payment will be implemented with help of the Paypal SDK.
Now i am facing a problem. I only offer two products which can be ordered. First one for say 10 Euro and the second one for 15 Euro.
Where do I have to place the price information which is then to be transfered to Paypal? I don´t think hardcoding the price for my items
into the app is a good approach, but I did not find any better solution for it. I decompiled the app of one competitioner and saw that he also just saves the
price into the app?
Once i hardcode the price information into the app, how should I change it in future? Old app installations will always have
the old price? Lets say it was 10 Euro and now it should be 12 Euro?! How should I change that?
One possibility would be to get the price informaton from my CloudService each time the user starts my app?
What are other solutions for that problem? I want to be flexibel to change the price of my products and to be safe from manipulation.
(I would verifiy the payment with my CloudService and Paypal)
Regards
Store price on your Server this is the best way
You set pricing in Google Play Console.
Go to your application, Store presence, In-app products.
You can add your products and pricing info in there.

Populate data in Listview on Weekly basis in android

I have to display data in Listview in android. For that I am retrieving data from sqlite database, having two column fields "date" and "amount". There are some more column fields but i don't need them. Now I want to show data in Listview weekly basis, with addition of the amount for the given week. Can anyone Please help me. How can I do this.(I thought of using strftime() function also but it add all the previous weeks data in one row. even thought for using Calendar class of java but don't know how can I achieve the solution using that.)
If I understand correctly your only problem is to make sure that a week has passed. If so:
I refer you to this solution: (Java / Android) Calculate days between 2 dates and present the result in a specific format , that uses no external Java libraries. You can just save the former list population day, the current day, and use the solution here to get the distance between them in days. Then all that remains is to check if the result >= 7. if so, a week has passed.

Categories