Android Paging Library - Data + Network with multiple sorting types
I recently saw that google has a great library for paginating data.
In this Google IO:
Android Jetpack: manage infinite lists with RecyclerView and Paging (Google I/O '18)
They explained how to make Data + Network DataSource
and grab data from database as Single Source of Truth
and when the database is out of data it request for more data from the network with BoundaryCallback
.
So assume that I have a list of Movies on the server. And client (Android user) can sort them by popularity, title, date_release and ...
So in the first time if the user sort movies by titles everything will work great because there is no data in database and data will be requested from the server to sort them by title and send them back.
But what if after that user tries to sort them by popularity for example? Because of the availability of chunk of movies in database (for example 50 movies), it will sort this small amount of movies by popularity and then tries to grab data from server and this is not a good experience.
I cant make table for every sort type because it is not a good practice. So how can I overcome to this problem?
Thanks very much


add a comment |
I recently saw that google has a great library for paginating data.
In this Google IO:
Android Jetpack: manage infinite lists with RecyclerView and Paging (Google I/O '18)
They explained how to make Data + Network DataSource
and grab data from database as Single Source of Truth
and when the database is out of data it request for more data from the network with BoundaryCallback
.
So assume that I have a list of Movies on the server. And client (Android user) can sort them by popularity, title, date_release and ...
So in the first time if the user sort movies by titles everything will work great because there is no data in database and data will be requested from the server to sort them by title and send them back.
But what if after that user tries to sort them by popularity for example? Because of the availability of chunk of movies in database (for example 50 movies), it will sort this small amount of movies by popularity and then tries to grab data from server and this is not a good experience.
I cant make table for every sort type because it is not a good practice. So how can I overcome to this problem?
Thanks very much


add a comment |
I recently saw that google has a great library for paginating data.
In this Google IO:
Android Jetpack: manage infinite lists with RecyclerView and Paging (Google I/O '18)
They explained how to make Data + Network DataSource
and grab data from database as Single Source of Truth
and when the database is out of data it request for more data from the network with BoundaryCallback
.
So assume that I have a list of Movies on the server. And client (Android user) can sort them by popularity, title, date_release and ...
So in the first time if the user sort movies by titles everything will work great because there is no data in database and data will be requested from the server to sort them by title and send them back.
But what if after that user tries to sort them by popularity for example? Because of the availability of chunk of movies in database (for example 50 movies), it will sort this small amount of movies by popularity and then tries to grab data from server and this is not a good experience.
I cant make table for every sort type because it is not a good practice. So how can I overcome to this problem?
Thanks very much


I recently saw that google has a great library for paginating data.
In this Google IO:
Android Jetpack: manage infinite lists with RecyclerView and Paging (Google I/O '18)
They explained how to make Data + Network DataSource
and grab data from database as Single Source of Truth
and when the database is out of data it request for more data from the network with BoundaryCallback
.
So assume that I have a list of Movies on the server. And client (Android user) can sort them by popularity, title, date_release and ...
So in the first time if the user sort movies by titles everything will work great because there is no data in database and data will be requested from the server to sort them by title and send them back.
But what if after that user tries to sort them by popularity for example? Because of the availability of chunk of movies in database (for example 50 movies), it will sort this small amount of movies by popularity and then tries to grab data from server and this is not a good experience.
I cant make table for every sort type because it is not a good practice. So how can I overcome to this problem?
Thanks very much




asked Jan 2 at 9:51


Saman SattariSaman Sattari
4172621
4172621
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your question makes sense. IMO you do not have to make tables for every sort types but you can keep a track of which endpoint the data came from. For example, you have three endpoints with query ?sort=default
, ?sort=ratings
, ?sort=released_date
. You can add three extra Boolean attributes (say fromDefault
, fromRatings
, fromReleasedDate
) to your db model class to keep track of which endpoint it came from & update those corresponding flag whenever same movie data arrives from multiple endpoints.
Now when you sort by rating, you will use SQL query to filter those where the flag fromRatings
is true
. But initially, you will have none so your BoundaryCallback
fires up the server request, gets the ratings sorted movie data and before saving, you'll have to override the fromRatings
to true
.
Hope it helps.
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004211%2fandroid-paging-library-data-network-with-multiple-sorting-types%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your question makes sense. IMO you do not have to make tables for every sort types but you can keep a track of which endpoint the data came from. For example, you have three endpoints with query ?sort=default
, ?sort=ratings
, ?sort=released_date
. You can add three extra Boolean attributes (say fromDefault
, fromRatings
, fromReleasedDate
) to your db model class to keep track of which endpoint it came from & update those corresponding flag whenever same movie data arrives from multiple endpoints.
Now when you sort by rating, you will use SQL query to filter those where the flag fromRatings
is true
. But initially, you will have none so your BoundaryCallback
fires up the server request, gets the ratings sorted movie data and before saving, you'll have to override the fromRatings
to true
.
Hope it helps.
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
add a comment |
Your question makes sense. IMO you do not have to make tables for every sort types but you can keep a track of which endpoint the data came from. For example, you have three endpoints with query ?sort=default
, ?sort=ratings
, ?sort=released_date
. You can add three extra Boolean attributes (say fromDefault
, fromRatings
, fromReleasedDate
) to your db model class to keep track of which endpoint it came from & update those corresponding flag whenever same movie data arrives from multiple endpoints.
Now when you sort by rating, you will use SQL query to filter those where the flag fromRatings
is true
. But initially, you will have none so your BoundaryCallback
fires up the server request, gets the ratings sorted movie data and before saving, you'll have to override the fromRatings
to true
.
Hope it helps.
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
add a comment |
Your question makes sense. IMO you do not have to make tables for every sort types but you can keep a track of which endpoint the data came from. For example, you have three endpoints with query ?sort=default
, ?sort=ratings
, ?sort=released_date
. You can add three extra Boolean attributes (say fromDefault
, fromRatings
, fromReleasedDate
) to your db model class to keep track of which endpoint it came from & update those corresponding flag whenever same movie data arrives from multiple endpoints.
Now when you sort by rating, you will use SQL query to filter those where the flag fromRatings
is true
. But initially, you will have none so your BoundaryCallback
fires up the server request, gets the ratings sorted movie data and before saving, you'll have to override the fromRatings
to true
.
Hope it helps.
Your question makes sense. IMO you do not have to make tables for every sort types but you can keep a track of which endpoint the data came from. For example, you have three endpoints with query ?sort=default
, ?sort=ratings
, ?sort=released_date
. You can add three extra Boolean attributes (say fromDefault
, fromRatings
, fromReleasedDate
) to your db model class to keep track of which endpoint it came from & update those corresponding flag whenever same movie data arrives from multiple endpoints.
Now when you sort by rating, you will use SQL query to filter those where the flag fromRatings
is true
. But initially, you will have none so your BoundaryCallback
fires up the server request, gets the ratings sorted movie data and before saving, you'll have to override the fromRatings
to true
.
Hope it helps.
answered Jan 5 at 12:42
realpacrealpac
28148
28148
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
add a comment |
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
TnQ very much..
– Saman Sattari
Jan 7 at 19:32
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
@SamanSattari Glad I could help :)
– realpac
Jan 8 at 8:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004211%2fandroid-paging-library-data-network-with-multiple-sorting-types%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown