Skip to content

Commit

Permalink
Merge pull request #1 from kerastinell/master
Browse files Browse the repository at this point in the history
Made app working again
  • Loading branch information
auzbuzzard committed Jul 29, 2018
2 parents daa27c9 + bf9bd2a commit 01d7941
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ private List<DerpibooruFilter> parseFilterArray(JSONArray array) throws JSONExce
/* TODO: clean-up */
List<Integer> hiddenIds = intListFromArray(f.getJSONArray("hidden_tag_ids"));
List<Integer> spoileredIds = intListFromArray(f.getJSONArray("spoilered_tag_ids"));
List<String> hidden = Arrays.asList(f.getString("hidden_tags").split(", "));
if (hidden.get(0).equals("")) {
hidden = Collections.emptyList();
}
List<String> spoilered = Arrays.asList(f.getString("spoilered_tags").split(", "));
if (spoilered.get(0).equals("")) {
spoilered = Collections.emptyList();
}
List<String> hidden = stringListFromArray(f.getJSONArray("hidden_tags"));
List<String> spoilered = stringListFromArray(f.getJSONArray("spoilered_tags"));

/* for some reason, Derpibooru sets "system" to "null" for non-system
* filters, so getBoolean() does not work */
Expand All @@ -65,4 +59,12 @@ private List<Integer> intListFromArray(JSONArray array) throws JSONException {
}
return out;
}

private List<String> stringListFromArray(JSONArray array) throws JSONException {
List<String> out = new ArrayList<>();
for (int y = 0; y < array.length(); y++) {
out.add(array.getString(y));
}
return out;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ private String parseUploader(Document doc) {
}

private String parseDescription(Document doc) {
Element descr = doc.select("div.image-description").first();
Element descr = doc.select("image-description__text").first();
String imageDescription = "";
if (descr != null) {
descr.select("h3").first().remove();
imageDescription = descr.html();
}
return imageDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<DerpibooruImageThumb> parseResponse(String rawResponse) throws JSONE
return imageThumbs;
}

private JSONArray getRootArray(JSONObject json) throws JSONException {
public JSONArray getRootArray(JSONObject json) throws JSONException {
if (!json.isNull("images")) {
return json.getJSONArray("images");
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package derpibooru.derpy.server.parsers;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import derpibooru.derpy.data.server.DerpibooruTagDetailed;
import derpibooru.derpy.server.providers.RankingImageListProvider.RankingsType;

public class RankingImageListParser extends ImageListParser {
private RankingsType mRankingsType;

public RankingImageListParser(RankingsType rankingsType, List<DerpibooruTagDetailed> spoileredTags) {
super(spoileredTags);
mRankingsType = rankingsType;
}

@Override
public JSONArray getRootArray(JSONObject json) throws JSONException {
return json.getJSONArray(mRankingsType == RankingsType.TopScoring ?
"top_scoring" : "top_commented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onQueryFailed() {
}).tags(mFilter.getSpoileredTags()).fetch();
}

private void fetchImages(List<DerpibooruTagDetailed> spoileredTags) {
public void fetchImages(List<DerpibooruTagDetailed> spoileredTags) {
super.executeQuery(new ImageListParser(spoileredTags));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import derpibooru.derpy.data.server.DerpibooruFilter;
import derpibooru.derpy.data.server.DerpibooruImageThumb;
import derpibooru.derpy.data.server.DerpibooruTagDetailed;
import derpibooru.derpy.server.QueryHandler;
import derpibooru.derpy.server.parsers.RankingImageListParser;

public class RankingImageListProvider extends ImageListProvider {
private static final String ALL_TIME = "520w";
Expand Down Expand Up @@ -67,14 +69,7 @@ public RankingImageListProvider inWeeks(int weeks) {
protected String generateUrl() {
StringBuilder sb = new StringBuilder();
sb.append(DERPIBOORU_DOMAIN);
switch (mListType) {
case TopScoring:
sb.append("lists/top_scoring.json");
break;
case MostCommented:
sb.append("lists/top_commented.json");
break;
}
sb.append("lists.json");
sb.append("?last=");
sb.append(mTime);
sb.append("&perpage=");
Expand All @@ -84,6 +79,11 @@ protected String generateUrl() {
return sb.toString();
}

@Override
public void fetchImages(List<DerpibooruTagDetailed> spoileredTags) {
super.executeQuery(new RankingImageListParser(mListType, spoileredTags));
}

public enum RankingsType {
TopScoring(1),
MostCommented(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public FilterChangeRequester(Context context, final QueryHandler<Boolean> handle

@Override
protected Map<String, String> generateForm() {
Map<String, String> form = new HashMap<>(2);
form.put("_method", "patch");
Map<String, String> form = new HashMap<>(1);
form.put("authenticity_token", mAuthenticityToken);
return form;
}
Expand Down

0 comments on commit 01d7941

Please sign in to comment.