Android - associate a user to some list item - android

i'm developing an android application which allows different users to login and see a list of favourite songs.
Each user has its list of songs, and a song is an instance of the corresponding class Song, with some attributes (singer, year, title...). The MainActivity contains the form for the login, so the user has to set its Name and Password. After login, a second activity is started, and it contains the ListView with the user's favourite songs.
How can i associate a single user to its corresponding song's list?
I thinked to use a database to store the songs, but then?

Look at Parse it's very easy to use and let you focus on your android App, instead of spending much time writing and configuring a server-side application.
You need also to implement on your android application a service to handle json ( or xml, it's your choice ). This is an awesome library to handle json JSONP.
Look also to this link for an overview on RESTfulservices.
For example (getting user info):
You need an info on userA.
You format a json with the right info.
Start an http request to your server. It will answer you with another json containing some info.
Parse this json recieved and use the data in your app.
I hope I made myself clear.

Related

How do I allow end-user to add data to JSON file

I'm a novice when it comes to programming so bear with me. Currently I have a recycler view which pulls data from a JSON file in my assets folder and displays it. On the same screen where it is displayed I have created an 'add' button. This takes the user to another screen with a bunch of edit text fields where they can enter their own data, however, it currently does nothing. From my understanding, JSON files are read-only and so in order to add an element to the JSON array it needs to be saved to either internal or external storage (which I have no clue how to do). I have basically just followed this tutorial (https://www.youtube.com/watch?v=zdfbHzBmzk8&t=1859s) and now want to add a button where the user can input data and it gets added to the JSON.
Context:
The application is supposedly for a car dealership. I need to be able to create a list which displays the current stock of vehicles the dealership has. This is the data in the JSON file. The user should be able to add vehicles to the list, delete vehicles from the list or mark the vehicle as sold which should move it to a different activity and delete it from the current stock list. I will also need to be able to sort the list 3 different ways using a bubble, insertion and selection sort and I have a feeling this would be easier with my data stored in the JSON file.
TL/DR: How can I allow the user to add elements to a JSON file/array?
You can't perform the add/remove function on the JSON file which is in the app's asset folder. You can simply achieve this functionality in two ways:
Either you create a file that is stored locally on the mobile device and every time you need to add or remove some data from that file, you will need to read and then update that file.
Or you can create a local DB in your app, where you can store, add or update data based on your requirement.
From the above 2 ways, the second one (with DB) is more efficient than the first one. Also, you will find many resources that can help you in implementing that functionality.

How can I retrieve more data from Prestashop API to my flutter app?

I looking for documentation about Prestashop API without success.
I am developing a mobile app with flutter which retrieve data from Prestashop API, the problem is I just can do a couple calls to the api as: list products, list clients, show misc info, etc...
I would like to be able to create a new order, add products to cart, create cart, etc... But I can't find any other solutions.
Should I create my own custom api service?
Edit:
This is the data already have
http://example.com/prestashop/api/products
http://example.com/prestashop/api/images
http://example.com/prestashop/api/customers
And I would like to get the and create the next one (i.e):
http://example.com/prestashop/api/cart/create
http://example.com/prestashop/api/cart/add_product/?id=number
http://example.com/prestashop/api/product/create
Thanks a lot
The lines of documentation you need are here:
https://devdocs.prestashop.com/1.7/webservice/getting-started/#create-a-resource
How to create a new order via Prestashop API?
This process is called create a resource. So, if you want to create a new order, just:
Take all the same XML (or JSON) schema you see in http://example.com/prestashop/api/orders?schema=blank (add "&output_format=JSON" for JSON),
Fill it with your values (with no "id") and send with POST HTTP request back to http://example.com/prestashop/api/orders/
How to edit an order via Prestashop API?
This process is called update a resource. So, if you want to edit an order ID 1, just:
Take all the same XML (or JSON) schema you see in http://example.com/prestashop/api/orders/1 (add "&output_format=JSON" for JSON),
Fill it with your values and send with PUT HTTP request back to http://example.com/prestashop/api/orders/1
The same process is for all entities you see in Prestashop back office > Advanced parameters > Webservice.
Note: Please check if API is enabled and all check boxes are checked for the entity permissions you need. You can find it in Prestashop back office > Advanced parameters > Webservice.

How to maintain data or show stored data in app until recieve response from server?

I need functionality like facebook app in my app.
the functionality is that when i login in facebook app then feed data load first time and if i click another tab ,like notification tab then load notification list in facebook.
but if i click again feed tab then all feed data showing instantly ,it's maintain cache or database and it's perform like and share functionality.
in my app when i click home tab then loader visible to fetch data from server and click to another tab then fetch data from server.
the question is that i dont want to load every time loader in my app,it's should be first time in every tab, if data addded in my appp from server then i call webservice.
Thanks in Advance.
Forgive me if any type of grammatical mistake.
Well I am not going to help you with code. that's your part. What I can do is give you some idea how to do that.
--> When the application first launches.
What you can do is fetch the data the first time you load app and store it in your SQLlite DB. the relations should match the server side but you can store data how ever suites you best.
--> when you switch tabs.
Save the state of the previous tab this question might help.
--> when you switch to a tab
trigger a run in background or Async Task or a thread to retrieve data from serve and store it in the same local DB. and bind the views to that data for example if you are updating a list calling notifyDataSetChanged() will actually update that list on the screen.
Thats it. Hope that helps.

Android RSS Feed parsing and running app as service

I am making an app for my college where we have to parse RSS feed and display it. I am using SAX Parser to parse it and its working smoothly. Now I want two functionality in my app. First of all I want to run it as a service so that it may notify users about new events i.e new updates from RSS and how should I differentiate between the old RSS feed parsed and the new one so that I can show only the new updates.
Please give a overview on how can I implement these two things.
I don't know about the first question (how to make it a service) but I've done the second in a past life. The way I went about it was:
Compute the hash (sha1) from the title (you might want add other fields too)
Store the hash into a database along with time stamp
If the hash matches the entry in the database don't add it
if (3) fails add to database
Display everything in the database in descending order of timestamp (latest first)

Android JSON user registration

I'm in the process of building an Android application that interacts via a JSON API with my website. I've basically got everything together except for user registration on the app. I have an idea on how I want to implement it, but I want to see if there might be an easier way.
My approach is:
When the RegisterActivity is started, display a loading indicator, and make an asynchronous JSON request (via google-gson) to the server get all the fields needed for registration.
When the listener receives a response, populate the spinners, checkboxes, etc. with the possible registration field values.
Allow the user to complete the form and submit via JSON.
You're probably thinking, "Why don't you just store the possible registration spinner/checkbox values in the app itself?" The possible values for each field will be changing over time as I continue to test/push the product, and I don't want to break a build simply because I added/removed some possible options on the server. This is why I'm dynamically building the form based upon a JSON request.
Given that, I'm wondering:
Am I thinking about this the wrong way?
If this is a good approach, is there a JAR or sample implementation someone has out there that already accomplishes this?
You could always just use a WebView and have your registration page written in HTML and hosted on your server. That simplifies things dramatically.
http://developer.android.com/guide/webapps/webview.html

Categories

Resources