Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
ServerBase: moved contains() to Util
Browse files Browse the repository at this point in the history
  • Loading branch information
tempura-san committed Oct 6, 2017
1 parent cbe4dc8 commit 71d3298
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public ArrayList<Manga> getMangasFiltered(int[][] filters, int pageNumber) throw
} else if (filters[0].length == 1) { // single genre selection
String web = genreVV + genre[0].replaceAll(" ", "-") + orderV[0];
for (int i = 0; i < genre.length; i++) {
if (contains(filters[0], i)) {
if (Util.getInstance().contains(filters[0], i)) {
web = genreVV + genre[i].replaceAll(" ", "-") + orderV[filters[2][0]];
if (pageNumber > 1) {
web = web + "?page=" + pageNumber;
Expand All @@ -222,9 +222,9 @@ public ArrayList<Manga> getMangasFiltered(int[][] filters, int pageNumber) throw
nav.addPost("mangaName", "");
nav.addPost("authorArtist", "");
for (int i = 0; i < genre.length; i++) {
if (contains(filters[0], i)) {
if (Util.getInstance().contains(filters[0], i)) {
nav.addPost("genres", "1");
} else if (contains(filters[1], i)) {
} else if (Util.getInstance().contains(filters[1], i)) {
nav.addPost("genres", "2");
} else {
nav.addPost("genres", "0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public ServerFilter[] getServerFilters() {
public ArrayList<Manga> getMangasFiltered(int[][] filters, int pageNumber) throws Exception {
String gens = "";
for (int i = 0; i < genre.length; i++) {
if (contains(filters[0], i)) {
if (Util.getInstance().contains(filters[0], i)) {
gens = gens + "1";
} else {
gens = gens + "0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,21 @@ public ArrayList<Manga> getMangasFiltered(int[][] filters, int pageNumber) throw
mBodyBuilder.addFormDataPart("searchTerm","");
mBodyBuilder.addFormDataPart("searchByLetter","");
for(int i = 0; i < genreV.length; i++){
if(contains(filters[0],i)){
if(Util.getInstance().contains(filters[0],i)){
mBodyBuilder.addFormDataPart(genreV[i],"1");
}else{
mBodyBuilder.addFormDataPart(genreV[i],"0");
}
}
for(int i = 0; i < subGenreV.length; i++){
if(contains(filters[1],i)){
if(Util.getInstance().contains(filters[1],i)){
mBodyBuilder.addFormDataPart(subGenreV[i],"1");
}else{
mBodyBuilder.addFormDataPart(subGenreV[i],"0");
}
}
for(int i = 0; i < typeV.length; i++){
if(contains(filters[2],i)){
if(Util.getInstance().contains(filters[2],i)){
mBodyBuilder.addFormDataPart(typeV[i],"1");
}else{
mBodyBuilder.addFormDataPart(typeV[i],"0");
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/ar/rulosoft/mimanganu/servers/ServerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,6 @@ public boolean testLogin(String user, String passwd) throws Exception {
return false;
}

/**
* Checks if a given integer is present in an array of integers.
*
* @param array the array for checking
* @param value the value to look for
* @return <code>true</code> if value is contained in array
*/
public boolean contains(int[] array, int value) {
for (int i : array) {
if (i == value) {
return true;
}
}
return false;
}

/**
* An enumeration for the type of filtering supported.
*/
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/ar/rulosoft/mimanganu/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,15 @@ public void removeAllCookies(Context context) {
}
}

public boolean contains(int[] array, int value) {
for (int i : array) {
if (i == value) {
return true;
}
}
return false;
}

private static class LazyHolder {
private static final Util utilInstance = new Util();
}
Expand Down

0 comments on commit 71d3298

Please sign in to comment.