Added Pagination Handlers for the Replay Center
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package eu.crushedpixel.replaymod.api.client.pagination;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadedFilePagination implements Pagination {
|
||||
|
||||
private int page;
|
||||
private HashMap<Integer, FileInfo> files = new HashMap<Integer, FileInfo>();
|
||||
|
||||
public DownloadedFilePagination() {
|
||||
this.page = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> getFiles() {
|
||||
return new ArrayList<FileInfo>(files.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoadedPages() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchPage() {
|
||||
page++;
|
||||
|
||||
HashMap<Integer, File> f = ReplayMod.downloadedFileHandler.getDownloadedFiles();
|
||||
List<Integer> toAdd = new ArrayList<Integer>();
|
||||
for(int i : f.keySet()) {
|
||||
if(!files.containsKey(i)) {
|
||||
toAdd.add(i);
|
||||
if(toAdd.size() >= Pagination.PAGE_SIZE) break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd);
|
||||
if(fis.length <= 1) {
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(FileInfo info : fis) {
|
||||
files.put(info.getId(), info);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package eu.crushedpixel.replaymod.api.client.pagination;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FavoritedFilePagination implements Pagination {
|
||||
|
||||
private int page;
|
||||
private HashMap<Integer, FileInfo> files = new HashMap<Integer, FileInfo>();
|
||||
|
||||
public FavoritedFilePagination() {
|
||||
this.page = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> getFiles() {
|
||||
return new ArrayList<FileInfo>(files.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoadedPages() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchPage() {
|
||||
page++;
|
||||
|
||||
try {
|
||||
int[] f = ReplayMod.apiClient.getFavorites(AuthenticationHandler.getKey());
|
||||
List<Integer> toAdd = new ArrayList<Integer>();
|
||||
for(int i : f) {
|
||||
if(!files.containsKey(i)) {
|
||||
toAdd.add(i);
|
||||
if(toAdd.size() >= Pagination.PAGE_SIZE) break;
|
||||
}
|
||||
}
|
||||
|
||||
FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd);
|
||||
if(fis.length <= 1) {
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(FileInfo info : fis) {
|
||||
files.put(info.getId(), info);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package eu.crushedpixel.replaymod.api.client.pagination;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mariusmetzger on 16/05/15.
|
||||
*/
|
||||
public interface Pagination {
|
||||
public List<FileInfo> getFiles();
|
||||
|
||||
public int getLoadedPages();
|
||||
|
||||
public boolean fetchPage();
|
||||
|
||||
public static final int PAGE_SIZE = 30; //defined by the Website API
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package eu.crushedpixel.replaymod.api.client;
|
||||
package eu.crushedpixel.replaymod.api.client.pagination;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.client.SearchQuery;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchPagination {
|
||||
public class SearchPagination implements Pagination {
|
||||
|
||||
private final SearchQuery searchQuery;
|
||||
private int page;
|
||||
@@ -18,14 +19,17 @@ public class SearchPagination {
|
||||
this.searchQuery = searchQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> getFiles() {
|
||||
return new ArrayList<FileInfo>(files);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoadedPages() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchPage() {
|
||||
page++;
|
||||
searchQuery.offset = page;
|
||||
Reference in New Issue
Block a user