How to efficiently perform server queries? - android

I want to implement an article viewer with the help of tabs. Basically each tab will correspond to an article category (e.g. Sports, News and so on) and will contain a list underneath with all the available articles (much like the google play store implementation in the Movies>Top Selling or Music>Top Albums/New Releases).
The problem is that those articles will be pulled from a server and the server's query protocol is... impractical at best. It supports two kinds of queries. One that will result in a json file of the category, which is basically a list of the article titles, authors and id's and the other that will result in another json file with article-specific data (Author, Header, Body, et.c.).
My question is the following:
The way I see it, there are 5 categories, each containing 5 articles, so that means that I will possibly have to query the server 30 times to first get the data from the category-wide query to populate the listViews and each time a list item (i.e. an article) is being clicked, I'll have to query the server again for the article itself. Let alone the fact that I will have to have 10 SQLite tables on the device (5 for category data and another 5 which actually contain the articles).
This all sounds wildly inefficient to me, so does anyone have a better idea of implementing this?

Related

QuizApp - Firebase/ FireStore Reads

I want to make an online QuizGame using Android Studio and Firebase.
First step will be a game mode for one Player where he gets Questions from the server. The code itself is not a big problem but I have a question about the reads/pricing of Firestore.
The gameplay will look like this: One Round, 5 questions. I want to make a Database looking like this:
Project: Category(Collection) -> generatedID(Document) -> custom Object (My custom Object has an Arraylist of Question, Correct AnswerA, AnswerB, C and D).
My general question is, lets say I am looking for an ID. I have for example 50 IDs in my Category Collection. If I start a query it will check every entry if the saved ID == my searched ID. Will that be a total of 50 reads or only one?
Firestore pricing is based on document reads, writes and deletes. If you run a query, you will be charged for any documents returned by that query, not the total number of documents in the collection. You can avoid un-necessary cost by the use of cursors and pagination, if you need to return large datasets. If you are only searching for a single ID, then it is likely that'll only return one document and, therefore, it'll only cost you for one document read.
If your query returns no results, you will be charged for one document read.
You can get more details from the Cloud Firestore pricing page

Android RSS reader app SQLite DB schema

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... :)

Android ListView Sourced from REST JSON response

I can't seem to find exactly what I'm looking for after a few day's worth of hunting, so if anyone has seen exactly what I'm trying to do elsewhere, I'd love a link or two.
Anyway, I'm trying to build an app to connect into an ERP system that returns user access information in JSON format via REST request using an e-mail address and password. Most users of the system only have a singular access role, so no big deal for them, but others have multiple roles. The trouble I'm having is taking these multiple access roles and adding them into a ListView where they can select the role with which they wish to use to gain access.
Trouble is, I need a display that uses two lines per selection (to properly display all user-pertinent data) and some way to record the user selection. The data useful in the background for the selection would not be displayed, as it would not mean anything to the user. I've been able to take the JSON response and map it to a custom class I designed for it without any problems (not actually all that useful, mostly only helps for discerning the results count prior to displaying multiple results to the ListView). But I can't figure out how to properly build the ListView layout and map the data to the layout. I'm having trouble understanding how to build the view and insert data into new list items.
The best I figure, if I can get the results to display in a ListView and then record the selection in the shared preferences, I'll be golden.
If the listview items being populated from some JSONArray then you could use listview.setOnItemClickListener to get the position of the selected item and match it from the array.Your question seems a little vague. Can you post some code of what you've tried so that it becomes a little clearer?

How to get most popular post?

I am creating an app in which users can make posts and other users can like and comment over these posts.To achieve this facility i am using tables likes POSTS, LIKES, COMMENTS.(I am using parse.com database to store these table).
POSTS have fields like postId, content, userWhoMadeThePost, dateOfPosting
LIKES contains filelds as id, postOnWhichLikeWasMade (foreign key to POSTS(postId)), userWhoLiked, dateofLike
COMMENTS have id, content, postOnWhichCommentWasMade(foreign key to POSTS(postId)), userWhoCommented, dateOfComment
I want to retrieve most popular posts (posts with most no of likes and comments).
First way to do this is count no of post and likes for each post each time whenever a request is made for popular posts but this can become very time consuming if
there are millions of posts.
Other way to do this one way is to include 'noOfLikes' and 'noOfComments' in POSTS table, so in order to get popular posts I will have to access only post table, but the problem with this approach is whenever a user makes a comment over a post then I will have to increment 'noOfComments' in POSTS table as well as make a entry in COMMENTS table, problem starts when the increment is successfully made to POST table and before making change to the COMMENTS table connection is lost. In that case POST and COMMENTS table would be showing wrong data.
How to do this?
This would be simple, if you had control over the database, but doing this with Parse means that you have two main problems (one of which you already mentioned):
As far as I can tell, Parse does not allow grouping in queries. That means that (with your schema) it's actually impossible to get the most liked/commented posts without retrieving all of them. This is because you can't actually dynamically add a new column with the number of likes/comments like you would in a standard SQL query (using JOIN and GROUP BY).
You can't update more than one object within one transaction, so there is the possibility that a user could add a comment but the number of comments in the post object would not change.
That being said I think (at least if you insist on using parse) you must add the 'noOfLikes' and 'noOfComments' columns to the Post object. Not only does it provide the only viable solution for retrieving N top posts (without getting all of them), but the actual risk of inconsistencies is pretty low in my opinion. You can always catch network (or other) exceptions and temporarely store the update requests locally and retry them later.

ContentProvider appropriate for very dynamic data?

I'm an Android newbie, learning the SDK by creating some basic apps. I'm currently working on an app that will display content from a news aggregator with news items and comments on each item. Each news item has an 'id', and many comments associated with it.
Each results page will have a 'before' and 'after' reference id to the news item at the beginning of the page and the end, respectively. So each 'query' will be something like '/?before=$ID' or '/?after=$ID'.
It seems like ContentProviders are the preferred way to store data on android. However, the content of the site changes so much that I question whether or not using a ContentProvider would be wise.
I appreciate any insight.
Well content providers are used by the e-mail app to hold e-mail, gmail to store and sync its mail messages, gtalk and contacts to keep track of the people you know and their chat status, etc.
I am not sure just how dynamic you are thinking, but those are all pretty dynamic.
One way to look at it -- a content provider is just an API to access structured data across processes. If that API serves your purpose, well that's a good sign. The other aspect to them is that usually they are implemented on top of a SQLite database, and that is the easiest way to implement them because there is a lot of framework support for that. So you will most likely be using a SQLite database for your content provider impl. Is a database dynamic enough for you?

Categories

Resources