Add whats hot
This commit is contained in:
1 parent
bdc80578cf
commit
f674e2331e
8 files changed
+175
-9
No files matched your search
@@ -54,6 +54,7 @@ public class EhClient {
|
||||
public static final int METHOD_ADD_FAVORITES_RANGE = 10;
|
||||
public static final int METHOD_MODIFY_FAVORITES = 11;
|
||||
public static final int METHOD_GET_TORRENT_LIST = 12;
|
||||
public static final int METHOD_GET_WHATS_HOT = 13;
|
||||
|
||||
private final ThreadPoolExecutor mRequestThreadPool;
|
||||
private final OkHttpClient mOkHttpClient;
|
||||
@@ -171,6 +172,8 @@ public class EhClient {
|
||||
return EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (long[]) params[1], (Integer) params[2], (Boolean) params[3]);
|
||||
case METHOD_GET_TORRENT_LIST:
|
||||
return EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_WHATS_HOT:
|
||||
return EhEngine.getWhatsHot(this, mOkHttpClient);
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.hippo.ehviewer.client.parser.GalleryTokenApiParser;
|
||||
import com.hippo.ehviewer.client.parser.RateGalleryParser;
|
||||
import com.hippo.ehviewer.client.parser.SignInParser;
|
||||
import com.hippo.ehviewer.client.parser.TorrentParser;
|
||||
import com.hippo.ehviewer.client.parser.WhatsHotParser;
|
||||
import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
|
||||
@@ -518,4 +519,31 @@ public class EhEngine {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<GalleryInfo> getWhatsHot(EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
String url = EhUrl.HOST_G;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
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();
|
||||
List<GalleryInfo> list = WhatsHotParser.parse(body);
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public class EhUrl {
|
||||
public static final String DOMAIN_LOFI = "lofi.e-hentai.org";
|
||||
|
||||
public static final String HOST_EX = "http://" + DOMAIN_EX + "/";
|
||||
public static final String HOST_G = "http://" + DOMAIN_G + "/";
|
||||
|
||||
public static final String API_SIGN_IN = "http://forums.e-hentai.org/index.php?act=Login&CODE=01";
|
||||
public static final String API_REGISTER = "http://forums.e-hentai.org/index.php?act=Reg&CODE=00";
|
||||
|
||||
@@ -43,7 +43,7 @@ public class GalleryApiParser {
|
||||
gi.category = EhUtils.getCategory(g.getString("category"));
|
||||
gi.thumb = g.getString("thumb");
|
||||
gi.uploader = g.getString("uploader");
|
||||
gi.posted = g.getString("posted"); // TODO long to date
|
||||
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted")) * 1000);
|
||||
gi.rating = Float.parseFloat(g.getString("rating"));
|
||||
// tags
|
||||
JSONArray tagJa = g.getJSONArray("tags");
|
||||
|
||||
@@ -18,8 +18,19 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ParserUtils {
|
||||
|
||||
public static final DateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||
|
||||
public static synchronized String formatDate(long time) {
|
||||
return sDateFormat.format(new Date(time));
|
||||
}
|
||||
|
||||
public static String trim(String str) {
|
||||
// Avoid null
|
||||
if (str == null) {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WhatsHotParser {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static List<GalleryInfo> parse(String body) throws ParseException {
|
||||
try {
|
||||
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
|
||||
Document d = Jsoup.parse(body);
|
||||
Element pp = d.getElementById("pp");
|
||||
Elements id1List = pp.getElementsByClass("id1");
|
||||
for (int i = 0, n = id1List.size(); i < n; i++) {
|
||||
GalleryInfo galleryInfo = new GalleryInfo();
|
||||
Element id1 = id1List.get(i);
|
||||
Element id3 = JsoupUtils.getElementByClass(id1, "id3");
|
||||
Element temp = JsoupUtils.getElementByTag(id3, "a");
|
||||
String url = temp.attr("href");
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(url);
|
||||
galleryInfo.gid = result.gid;
|
||||
galleryInfo.token = result.token;
|
||||
temp = JsoupUtils.getElementByTag(temp, "img");
|
||||
galleryInfo.thumb = temp.attr("src");
|
||||
galleryInfo.title = temp.attr("title");
|
||||
galleryInfo.generateSLang();
|
||||
galleryInfoList.add(galleryInfo);
|
||||
}
|
||||
return galleryInfoList;
|
||||
} catch (Exception e) {
|
||||
throw new ParseException("Parse whats hot error", body);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,7 +374,10 @@ public final class MainActivity extends StageActivity
|
||||
startSceneFirstly(new Announcer(GalleryListScene.class)
|
||||
.setArgs(args));
|
||||
} else if (id == R.id.nav_whats_hot) {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_WHATS_HOT);
|
||||
startSceneFirstly(new Announcer(GalleryListScene.class)
|
||||
.setArgs(args));
|
||||
} else if (id == R.id.nav_favourite) {
|
||||
startScene(new Announcer(FavoritesScene.class));
|
||||
} else if (id == R.id.nav_history) {
|
||||
|
||||
@@ -82,6 +82,7 @@ import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
|
||||
public final class GalleryListScene extends BaseScene
|
||||
implements EasyRecyclerView.OnItemClickListener, EasyRecyclerView.OnItemLongClickListener,
|
||||
@@ -798,13 +799,22 @@ public final class GalleryListScene extends BaseScene
|
||||
protected void getPageData(int taskId, int type, int page) {
|
||||
mUrlBuilder.setPageIndex(page);
|
||||
|
||||
String url = mUrlBuilder.build();
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_GALLERY_LIST);
|
||||
request.setCallback(new GetGalleryListListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), taskId));
|
||||
request.setArgs(url, Settings.getShowJpnTitle()); // TODO check tag filter
|
||||
mClient.execute(request);
|
||||
if (ListUrlBuilder.MODE_WHATS_HOT == mUrlBuilder.getMode()) {
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_WHATS_HOT);
|
||||
request.setCallback(new GetWhatsHotListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), taskId));
|
||||
request.setArgs();
|
||||
mClient.execute(request);
|
||||
} else {
|
||||
String url = mUrlBuilder.build();
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_GALLERY_LIST);
|
||||
request.setCallback(new GetGalleryListListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), taskId));
|
||||
request.setArgs(url, Settings.getShowJpnTitle());
|
||||
mClient.execute(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -852,6 +862,56 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
}
|
||||
|
||||
private void onGetWhatsHotSuccess(List<GalleryInfo> result, int taskId) {
|
||||
if (mHelper != null && mSearchBarMover != null &&
|
||||
mHelper.isCurrentTask(taskId)) {
|
||||
mHelper.setPages(taskId, 1);
|
||||
mHelper.onGetPageData(taskId, result);
|
||||
SimpleHandler.getInstance().post(mReturnSearchBarRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
private void onGetWhatsHotFailure(Exception e, int taskId) {
|
||||
if (mHelper != null && mSearchBarMover != null &&
|
||||
mHelper.isCurrentTask(taskId) && isViewCreated()) {
|
||||
mHelper.onGetExpection(taskId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetWhatsHotListener extends EhCallback<GalleryListScene, List<GalleryInfo>> {
|
||||
|
||||
private final int mTaskId;
|
||||
|
||||
public GetWhatsHotListener(Context context, int stageId, String sceneTag, int taskId) {
|
||||
super(context, stageId, sceneTag);
|
||||
mTaskId = taskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<GalleryInfo> result) {
|
||||
GalleryListScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onGetWhatsHotSuccess(result, mTaskId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
GalleryListScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onGetWhatsHotFailure(e, mTaskId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
|
||||
@Override
|
||||
public boolean isInstance(SceneFragment scene) {
|
||||
return scene instanceof GalleryListScene;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetGalleryListListener extends EhCallback<GalleryListScene, GalleryListParser.Result> {
|
||||
|
||||
private final int mTaskId;
|
||||
|
||||
Reference in new issue
Block a user