What is the best practice for using room with RxJava? [closed] - android

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am trying my hands on Room and RxJava. I fairly new to both. My code is working fine but I was interested to know about the best practices.
Imagine an object with 10 fields say CompleteSong. In my app, I am making room return a Flowable<List<CompleteSong>> Whenever I make an update in the database, the Flowable updates with all the values. I am displaying that list with a RecyclerView. I have two possibilities to proceed with i.e.
1. I can store the object that is being changed and wait for the Flowable to update. When the flowable updates I update 1 item of RecyclerView
2. I can update the RecyclerView when the Flowable updates parsing through the list and looking for the changed instance of CompleteSong
I used to use the former approach, it seems to be less reactive but optimized whereas the latter seems to be more reactive but at the same time less optimized.
Can someone instruct me on this, what should be done? What approach should I follow or there's something else that I couldn't discover.
Note: I am new to reactive, so please consider updating me on the terminology if I messed something up.

Related

How do I decide how many ViewModels my app should have? Android, MVVM [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I see the recommendation is 1 view-model per 1 view (activity, fragment, custom view), but in most examples I see projects only have 1 view-model even though these have multiple views and fragments. Are developers just not following the guideline strictly or am I missing something?
As an example: an app in which there's a section for shopping list items in a recyclerView, and to-do list items in a different recyclerView.
Everything depends on your business logic.
For example one view model for authentication is normal. You have a repository with Api-Interface and Database for example. Then for content of page, It depends on the backend apis and other things. But one thing is recommended and that is you should be aware of SOLID principles specially single-responsibility here. Don't do all your stuffs in one or whatever viewmodels.
You can also see the open-source MVVM repositories and try to simulate the situation for your project.

Firebase retrival, getChildren vs getValue multiple times [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
My question is whether it is more efficient to getChildren in a query and then have all your if else statements sorting the data
Or whether it would be better to have multiple calls to the database which are obviously already sorted?
I would assume getting the children would be better since you are only making one call to the database?
My question is whether it is more efficient to getChildren in a query and then have all your if-else statements sorting the data Or whether it would be better to have multiple queries which are obviously already sorted?
Reading all the data within a node at once sounds not as a good solution to go ahead with. When you attach a listener on such a reference, you are reading all direct children that exist beneath that node, including the nested ones. Filtering the results on the client might be considered a waste of bandwidth and resources.
Suppose you have a node with 1000 objects and you are looking for only three of them. Imagine what would be the size of the result set when getting all 1000 objects? I can imagine that it will be huge. So the best option that you have is to use a query a do the filtering directly on the server. In this manner, the size of the result set will be very small, because only three elements will be returned and not 1000. So basically you are getting only the results you are interested in.
I would assume getting the children would be better since you are only making one call to the database?
That's actually the opposite. There nothing wrong in creating multiple Firebase database calls.

What is the proper modern way to use RecyclerView with ContentResolver to retrieve all media on the phone? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Basically I have an old RecyclerView with an Adapter that uses the Cursor directly. As far as I understand it, this isn't ideal because any time I do a Cursor operation like moveToNext() or similar, it performs disk IO, right? and that is happening on the UI thread.
So what is the recommended way for me to implement an infinite (basically keep loading items as the user scrolls) RecyclerView with ContentResolver to display videos or images stored on the phone?
Thanks.
I think that Jetpack's Paging library could be a good solution. As you found yourself it is possible to use it with a ContentProvider

How to store data for a to-do list app? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I am new to android programming and I'm currently working on a todo list app. I would like to store the name of the task and if it is completed or not. Later I might add things like priority or a date when the task has to be finished. I'm just unsure which method of storage i should use. Would SQL, JSON, XML or maybe something else like a CVS file be best fitted for the task?
You don't have to show me how to implement that method, I am just curious which method would be best suited.
Tanks for all answers
As for me, if you want some addition scalability from your app in future - it's better to use database. Preferences are not for storing large amount of data, but maybe they take less time for implementation. Don't store in xml/json if you are going to increase stored fields count, it would be a mess after some time.
If it's some kind of self educational project maybe you would like to use firebase or maybe realm, but it's only if you want to get something new. SQLite would be enough too.
This is more of a pref. Question. But, XML is pretty much the standard.

Why SQLBRITE and why we use it instead of SQLite? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am new to android to SQL Brite. i need to learn about SQLBrite how to use and why to use it.I searched in google but there is not much explanation about it only some GitHub codes which is very difficult to understand.
anyone please explain about SQLBrite?
A lightweight wrapper around SQLiteOpenHelper and ContentResolver which introduces reactive stream semantics to queries.
Instead of single executions, you can subscribe to queries using RxJava observables:
No attempt is made to hide SQL, Cursor, or the semantics of SQLiteOpenHelper (Android’s SQLite wrapper). Instead, those three concepts are given a superpower: data change notifications.
Whenever data in a table is updated from insert, update, or delete operations (whether in a transaction or as a one-off), subscribers to that data are updated.
When multiple queries are constantly refreshed with data, the UI updates in real-time instead of staying as a simple, static page.
For more reference : https://corner.squareup.com/2015/02/sqlbrite-reactive-sqlite-for-android.html

Categories

Resources