Skip to content

Commit

Permalink
Fix two pagination issues
Browse files Browse the repository at this point in the history
1. Pagination not being reset on refresh
2. Pagination not being set on some views
  • Loading branch information
samfundev committed May 14, 2023
1 parent 70f67a0 commit 48a455b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ public void addToAdapter(List<StreamInfo> streamsToAdd) {
mAdapter.addList(streamsToAdd);
}

private String pagination = "";

@Override
public List<StreamInfo> getVisualElements() throws JSONException, MalformedURLException, UnsupportedEncodingException {
String languageFilter = settings.getGeneralFilterTopStreamsByLanguage() ? "&language=" + getSystemLanguage() : "";

String url = "https://api.twitch.tv/helix/streams?game_id=" + game.getGameId() + "&first=" + getLimit() + (!pagination.isEmpty() ? "&after=" + pagination : "") + languageFilter;
String url = "https://api.twitch.tv/helix/streams?game_id=" + game.getGameId() + "&first=" + getLimit() + (getCursor() != null ? "&after=" + getCursor() : "") + languageFilter;

List<StreamInfo> mResultList = new ArrayList<>();
String jsonString = Service.urlToJSONStringHelix(url, this);
JSONObject fullDataObject = new JSONObject(jsonString);
JSONArray topStreamsArray = fullDataObject.getJSONArray("data");
setCursor(fullDataObject.getJSONObject("pagination").getString("cursor"));

for (int i = 0; i < topStreamsArray.length(); i++) {
JSONObject streamObject = topStreamsArray.getJSONObject(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,17 @@ public void addToAdapter(List<StreamInfo> aObjectList) {
/**
* Methods for functionality and for controlling the SwipeRefreshLayout
*/

private String pagination = "";

@Override
public List<StreamInfo> getVisualElements() throws JSONException, MalformedURLException {
List<StreamInfo> resultList = new ArrayList<>();

//Indentation is meant to mimic the structure of the JSON code
final String URL = "https://api.twitch.tv/helix/streams?first=" + getLimit() + (!pagination.isEmpty() ? "&after=" + pagination : "");
final String URL = "https://api.twitch.tv/helix/streams?first=" + getLimit() + (getCursor() != null ? "&after=" + getCursor() : "");

String jsonString = Service.urlToJSONStringHelix(URL, this);
JSONObject fullDataObject = new JSONObject(jsonString);
JSONArray topFeaturedArray = fullDataObject.getJSONArray("data");
setCursor(fullDataObject.getJSONObject("pagination").getString("cursor"));

for (int i = 0; i < topFeaturedArray.length(); i++) {
// Get all the JSON objects we need to get all the required data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ public void addToAdapter(List<Game> aGamesList) {
return new GamesAdapter(recyclerView, getBaseContext(), this);
}

public String pagination = "";

@Override
public List<Game> getVisualElements() throws JSONException {
List<Game> resultList = new ArrayList<>();

//Indentation is meant to mimic the structure of the JSON code
final String URL = "https://api.twitch.tv/helix/games/top?first=" + getLimit() + (!pagination.isEmpty() ? "&after=" + pagination : "");
final String URL = "https://api.twitch.tv/helix/games/top?first=" + getLimit() + (getCursor() != null ? "&after=" + getCursor() : "");
String jsonString = Service.urlToJSONStringHelix(URL, this);
JSONObject fullDataObject = new JSONObject(jsonString);
JSONArray gamesArray = fullDataObject.getJSONArray("data");
this.pagination = fullDataObject.getJSONObject("pagination").getString("cursor");
setCursor(fullDataObject.getJSONObject("pagination").getString("cursor"));

for (int i = 0; i < gamesArray.length(); i++) {
// Get all the JSON objects we need to get all the required data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,16 @@ public void addToAdapter(List<StreamInfo> streamsToAdd) {
Log.i(LOG_TAG, "Adding Top Streams: " + streamsToAdd.size());
}

private String pagination = "";

@Override
public List<StreamInfo> getVisualElements() throws JSONException, MalformedURLException {
final String languageFilter = settings.getGeneralFilterTopStreamsByLanguage() ? "&language=" + getSystemLanguage() : "";
final String URL = "https://api.twitch.tv/helix/streams?first=" + getLimit() + (!pagination.isEmpty() ? "&after=" + pagination : "") + languageFilter;
final String URL = "https://api.twitch.tv/helix/streams?first=" + getLimit() + (getCursor() != null ? "&after=" + getCursor() : "") + languageFilter;

List<StreamInfo> mResultList = new ArrayList<>();
String jsonString = Service.urlToJSONStringHelix(URL, this);
JSONObject fullDataObject = new JSONObject(jsonString);
JSONArray topStreamsArray = fullDataObject.getJSONArray("data");
this.pagination = fullDataObject.getJSONObject("pagination").getString("cursor");
setCursor(fullDataObject.getJSONObject("pagination").getString("cursor"));

for (int i = 0; i < topStreamsArray.length(); i++) {
JSONObject streamObject = topStreamsArray.getJSONObject(i);
Expand Down

0 comments on commit 48a455b

Please sign in to comment.