use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class GalleryListScene method onApplySearch.
@Override
public void onApplySearch(String query) {
if (null == mUrlBuilder || null == mHelper || null == mSearchLayout) {
return;
}
if (mState == STATE_SEARCH || mState == STATE_SEARCH_SHOW_LIST) {
if (mSearchLayout.isSpecifyGallery()) {
int index = query.indexOf(' ');
if (index <= 0 || index >= query.length() - 1) {
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
return;
}
long gid;
String token;
try {
gid = Long.parseLong(query.substring(0, index));
} catch (NumberFormatException e) {
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
return;
}
token = query.substring(index + 1);
Bundle args = new Bundle();
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
args.putLong(GalleryDetailScene.KEY_GID, gid);
args.putString(GalleryDetailScene.KEY_TOKEN, token);
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
return;
} else {
try {
mSearchLayout.formatListUrlBuilder(mUrlBuilder, query);
} catch (EhException e) {
showTip(e.getMessage(), LENGTH_LONG);
return;
}
}
} else {
mUrlBuilder.reset();
mUrlBuilder.setKeyword(query);
}
onUpdateUrlBuilder();
mHelper.refresh();
setState(STATE_NORMAL);
}
use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class EhEngine method commentGallery.
public static GalleryComment[] commentGallery(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, String comment) throws Exception {
FormBody.Builder builder = new FormBody.Builder().add("commenttext_new", comment);
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
Document document = Jsoup.parse(body);
Elements elements = document.select("#chd + p");
if (elements.size() > 0) {
throw new EhException(elements.get(0).text());
}
return GalleryDetailParser.parseComments(document);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
}
use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class EhEngine method modifyFavorites.
public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
String catStr;
if (dstCat == -1) {
catStr = "delete";
} else if (dstCat >= 0 && dstCat <= 9) {
catStr = "fav" + dstCat;
} else {
throw new EhException("Invalid dstCat: " + dstCat);
}
FormBody.Builder builder = new FormBody.Builder();
builder.add("ddact", catStr);
for (long gid : gidArray) {
builder.add("modifygids[]", Long.toString(gid));
}
builder.add("apply", "Apply");
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
FavoritesParser.Result result;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
result = FavoritesParser.parse(body);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
if (callApi && result.galleryInfoList.size() > 0) {
fillGalleryListByApi(task, okHttpClient, result.galleryInfoList);
}
for (GalleryInfo info : result.galleryInfoList) {
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
}
return result;
}
use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class FavoritesParser method parse.
public static Result parse(String body) throws Exception {
if (body.contains("This page requires you to log on.</p>")) {
throw new EhException(GetText.getString(R.string.need_sign_in));
}
String[] catArray = new String[10];
int[] countArray = new int[10];
try {
Document d = Jsoup.parse(body);
Element ido = JsoupUtils.getElementByClass(d, "ido");
// noinspection ConstantConditions
Elements fps = ido.getElementsByClass("fp");
// Last one is "fp fps"
Assert.assertEquals(11, fps.size());
for (int i = 0; i < 10; i++) {
Element fp = fps.get(i);
countArray[i] = ParserUtils.parseInt(fp.child(0).text());
catArray[i] = ParserUtils.trim(fp.child(2).text());
}
} catch (Exception e) {
e.printStackTrace();
throw new ParseException("Parse favorites error", body);
}
GalleryListParser.Result result = GalleryListParser.parse(body);
Result re = new Result();
re.catArray = catArray;
re.countArray = countArray;
re.pages = result.pages;
re.galleryInfoList = result.galleryInfoList;
return re;
}
use of com.hippo.ehviewer.client.exception.EhException in project EhViewer by seven332.
the class EhEngine method downloadArchive.
public static Void downloadArchive(@Nullable EhClient.Task task, OkHttpClient okHttpClient, long gid, String token, String or, String res) throws Exception {
if (or == null || or.length() == 0) {
throw new EhException("Invalid form param or: " + or);
}
if (res == null || res.length() == 0) {
throw new EhException("Invalid res: " + res);
}
FormBody.Builder builder = new FormBody.Builder();
builder.add("hathdl_xres", res);
String url = EhUrl.getDownloadArchive(gid, token, or);
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
throwException(call, code, headers, body, null);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
Matcher m = PATTERN_NEED_HATH_CLIENT.matcher(body);
if (m.find()) {
throw new NoHAtHClientException("No H@H client");
}
return null;
}
Aggregations