-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paginate scrolling in test result screen #511
Closed
Closed
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0f7e3c1
added paging library
aanorbel ecd88e0
modified viewmodel for result list fragment
aanorbel 15d0e10
modified item type and changed to enum
aanorbel c40104d
Merge branch 'master' of github.com:ooni/probe-android into issues/1911
aanorbel d951af1
updated pagination implementation
aanorbel 5512849
modified datasource for test restults
aanorbel df6caaf
added branch archive
aanorbel 35b223c
modified archive script for github actions
aanorbel 0e61235
Merge branch 'master' of github.com:ooni/probe-android into issues/1430
aanorbel ca18494
updated query datasource and pagination query parameters
aanorbel 8b58047
Update .github/workflows/archive.yml
aanorbel f09e5e7
Update app/src/main/java/org/openobservatory/ooniprobe/domain/QueryDa…
aanorbel 73051db
Merge branch 'master' of github.com:ooni/probe-android into issues/1430
aanorbel c68eb72
Merge branch 'master' into issues/1430
bassosimone f4a1da3
Merge branch 'master' of github.com:ooni/probe-android into issues/1430
aanorbel 30b50e1
Merge branches 'issues/1430' and 'master' of github.com:ooni/probe-an…
aanorbel c335a1e
Merge branches 'issues/1430' and 'master' of github.com:ooni/probe-an…
aanorbel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 298 additions & 0 deletions
298
app/src/main/java/org/openobservatory/ooniprobe/adapters/ResultListAdapter.java
Large diffs are not rendered by default.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/src/main/java/org/openobservatory/ooniprobe/adapters/diff/ResultComparator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.openobservatory.ooniprobe.adapters.diff | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.DiffUtil | ||
import org.openobservatory.ooniprobe.adapters.ResultListAdapter.UiModel | ||
|
||
class ResultComparator : DiffUtil.ItemCallback<UiModel>() { | ||
/** | ||
* This diff callback informs the PagedListAdapter how to compute list differences when new | ||
* PagedLists arrive. | ||
* | ||
* When you add a Cheese with the 'Add' button, the PagedListAdapter uses diffCallback to | ||
* detect there's only a single item difference from before, so it only needs to animate and | ||
* rebind a single view. | ||
* | ||
* @see DiffUtil | ||
*/ | ||
override fun areItemsTheSame(oldItem: UiModel, newItem: UiModel): Boolean { | ||
return if (oldItem is UiModel.ResultModel && newItem is UiModel.ResultModel) { | ||
oldItem.item.id == newItem.item.id | ||
} else if (oldItem is UiModel.SeparatorModel && newItem is UiModel.SeparatorModel) { | ||
oldItem.description == newItem.description | ||
} else { | ||
oldItem == newItem | ||
} | ||
} | ||
|
||
/** | ||
* Note that in kotlin, == checking on data classes compares all contents, but in Java, | ||
* typically you'll implement Object#equals, and use it to compare object contents. | ||
*/ | ||
override fun areContentsTheSame(oldItem: UiModel, newItem: UiModel): Boolean { | ||
return oldItem.equals(newItem) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/org/openobservatory/ooniprobe/domain/QueryDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.openobservatory.ooniprobe.domain; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.paging.PagingSource; | ||
import androidx.paging.PagingState; | ||
|
||
import com.raizlabs.android.dbflow.sql.language.SQLOperator; | ||
import com.raizlabs.android.dbflow.sql.language.SQLite; | ||
|
||
import org.openobservatory.ooniprobe.model.database.Result; | ||
import org.openobservatory.ooniprobe.model.database.Result_Table; | ||
|
||
import java.util.List; | ||
|
||
import kotlin.coroutines.Continuation; | ||
|
||
public class QueryDataSource extends PagingSource<Integer, Result> { | ||
private final String testGroupNameFilter; | ||
|
||
public QueryDataSource(String testGroupNameFilter) { | ||
this.testGroupNameFilter = testGroupNameFilter; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Integer getRefreshKey(@NonNull PagingState<Integer, Result> pagingState) { | ||
return 1; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public LoadResult.Page<Integer, Result> load(@NonNull LoadParams<Integer> loadParams, @NonNull Continuation<? super LoadResult<Integer, Result>> continuation) { | ||
// Key may be null during a refresh, if no explicit key is passed into Pager | ||
// construction. Use 0 as default, because our API is indexed started at index 0 | ||
int pageNumber = loadParams.getKey() != null ? loadParams.getKey() : 0; | ||
|
||
SQLOperator[] conditions = (testGroupNameFilter != null && !testGroupNameFilter.isEmpty()) | ||
? new SQLOperator[]{Result_Table.test_group_name.is(testGroupNameFilter)} | ||
: new SQLOperator[0]; | ||
|
||
List<Result> response = SQLite.select().from(Result.class) | ||
.where(conditions) | ||
.limit(20) | ||
.offset(pageNumber * 20) | ||
.orderBy(Result_Table.start_time, false) | ||
.queryList(); | ||
|
||
// Since 0 is the lowest page number, return null to signify no more pages should | ||
// be loaded before it. | ||
Integer prevKey = (pageNumber > 0) ? pageNumber - 1 : null; | ||
|
||
// This API defines that it's out of data when a page returns empty. When out of | ||
// data, we return `null` to signify no more pages should be loaded | ||
Integer nextKey = (!response.isEmpty()) ? pageNumber + 1 : null; | ||
return new LoadResult.Page<>( | ||
response, | ||
prevKey, | ||
nextKey | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If while you have fetched the first page of data, another result is written to the results table (because there is a test currently running), fetching the next page will be off by one.
You could instead use the
result_id
as a pagination handler and queryWHERE result_id < $last_result_id
to get the next page worth of data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query mechanism has been updated to use
result_id
based pagination