Storing custom configuration in android - java

I am creating an android application and i need to manage how to display data of list view in some fragment .. My list view consists of multiple sections with a header on each section.. The data of these sections are loaded from a web service(web call for each section) and i need to manage which sections to display to the user and also sort the sections by priority so that the important sections are displayed at the top of the view.
My question is how can i make this configurable and loaded once in my application so that when getting the data i can construct the list view properly using an already loaded configuration, i thought of using SharedPreferences or maybe an XML file as a configuration storage.
Again, my interests are to:
Manage which sections to be viewed in my list view. (for all users and not per user)
Sort the sections by priorities.
Thanks in advance for the help.

I believe you should have a database and store the settings for each user there. Based on data stored in the database you can generate XML, if needed. This would be very useful, as if you open the application with another android phone, but log in with your user, your settings would be loaded as well.

Related

Android: initializing a list with a large number of items

I need to use a list with more than 31 thousand strings for a dropdown menu. Now, if I declare this List/Array in java, I get the error that says the code is too large to compile. On the other hand, if I put these values in string-array in strings.xml, I get the message Resource compilation failed when I try to build the application.
What else can be done to store this list?
I don't want to keep the data in server and fetch it using API because it will increase my server cost.
You could put the data into a table in a local SQLite Database (no servers needed), and then retrieve only the visible part when needed. I suggest to use a RecyclerView to show the list of item: it needs a bit more time to be implemented, but works very well with big lists of data.
Assuming that the list is static, you can include a pre-filled Database in your assets folder and copy it into the /databases folder when your application first launches. No need to fill it by the app using big arrays.

Can i replace my table-arranged dummy values with actual data froma database?

[So as you can see in the picture, i'm a newbie in android programming and i just had an assignment concerning creating a management system app for university.
The views you see in the picture are just customly made with xml(Table layout) and the data are just dummy data placed on the respective textviews in the tables. I desire to create a database for students and all those data e.g names, gender, should be fetched from the database or sent. Remember, as for courses the number of courses would differ from one degree prog to another(imagine a student with less ormore courses than the tables i sampled there).
How do i acomplish this
As for database, im thinking of using SQLite or Firebase ]1
There are many ways to approach this, depending on the requirements of your program. If you need to share data between multiple people or devices, you probably want a database that lives on a web server, and you would write an API (application programming interface) which you would call from your app, and it would go and get the data from the database and return it to your app.
If your app is meant to be 'stand alone', where you could use it without being connected to the internet, then yes, a SQLite database is a good solution and it is pretty easy to integrate into your app.
To create a SQLite database, you can download the free tool SQLiteStudio. Once you create the database (usually saved with a .db file extension) you can add it to your project in the Assets folder (create it if it doesn't exist). The folder lives at the same level as the bin and gen folders in your project.
Next, search for a class called DatabaseHelper.java, it has a number of methods for opening, closing and querying a SQLite database, copy that to your project.
At the start of your program, you should check to see if you have a copy of the database in your local data/databases folder in your App's file storage area. If you don't have a copy there, which on the first execution of your program, it will not be there, then you have to copy the database .db file from your Assets folder to the data/databases folder, then open it there. If it is found, you've already done this, so, just open it.
When you want to read data into your app, you execute a SELECT statement to retrieve data from your database into a Cursor object, and return that cursor from your DatabaseHelper class to your activity. In your activity, you will iterate through the Cursor, reading one row at a time, and copy the data into program variables. Sometimes, you will create a class object to hold one record, with attributes that match a row from your query, and you'll create an instance of your class, fill it with the data from the Cursor, then add that object to an Array List of objects which your program can use at a later time, say, to display a list of people or whatever it is you queried for. Once the Cursor has been read to the end, you close the Database by calling a close method in the DatabaseHelper class.
That's the general idea. If you search for a copy of the DatabaseHelper.java class, that will get you started. Then, search for some example projects that use that DatabaseHelper.java class so you can figure out how to use it.
Good luck!!

Vaadin dynamically reflect changed data to all users' screens

I am trying to dynamically reflect the changes of the data to all logged in users' screens.
There are items being added to the database or one of their attributes is being changed by users or by scheduled tasks(cron-jobs).
What I want to do is reflecting those changes to all logged-in users' screens without a need of page refresh. This includes certain parts of all screens. One part is left menu side of all screens, the other one is table contents.
I am able to do that for one logged-in user via re assigning the changed datasource to the table and re building the left-side menu after re-assignment of the datasource. But this is only for the current user. I need to change all user screens which are currently in use at that moment.
I have checked Vaadin PUSH but could not really relate to it.
How can I do that with Vaadin?
Thank you in advance.
Check this out:
https://vaadin.com/docs/v8/framework/articles/BroadcastingMessagesToOtherUsers.html
In short, you can use the Observer Pattern to notify all the UIs about changes in the database. You also need to enable push and modify the UI using the UI.access(Runnable) method.

Customer Creation from backend with store_id using magento REST api

I was creating a magento customer using REST api. But the customer is being created with some default store_id = 0 .
As a result when I try to login to the magento store I am getting error saying I
Invalid login or password.
In the magento customer creation they haven't mentioned anything about this. How Can I do this? Any kind of heads up will be appreciated.
If I create a customer from front-end page then its getting *store_id=1* and for back-end its *store_id=0*. Both of them have same *website_id=1* So, when trying to login to magento I think we are trying to login different store.
If you set the website ID instead it should take care of this for you.
For your reference
Global: This refers to the entire installation.
Website: Websites are ‘parents’ of stores. A website consists of one or more stores. Websites can be set up to share customer data, or not to share any data
Store (or store view group): Stores are ‘children’ of websites. Products and Categories are managed on the store level. A root category is configured for each store view group, allowing multiple stores under the same website to have totally different catalog structures.
Store View: A store needs one or more store views to be browse-able in the front-end. The catalog structure per store view will always be the same, it simply allows for multiple presentations of the data in the front. 90% of implementations will likely use store views to allow customers to switch between 2 or more languages.

Best option to update Facebook contact list in Android app

I'm working on an application that retrieves the list of Facebook contacts to later perform different actions with it (for example, open a chat).
I have retrieved the list, but I have doubts about which is the best strategy to preserve and applying it to the changes that occur (eg chat be available for a new contact).
What is the best approach? As a first option I created a java class and serialized entire contact list (with their profile picture). After I have saved on the SD card and leave it available for later retrieval when needed. But I'm thinking maybe it is better to create a service in Android that instantiates a class that store a HashMap of contacts and leave it in memory for watching it constantly updating.
What do you think about this?
thanks

Categories