From c97dccaf041040b1c96bbb79f58657b918680d4c Mon Sep 17 00:00:00 2001 From: seven332 Date: Wed, 7 May 2014 01:23:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20vote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/hippo/ehviewer/ehclient/EhClient.java | 121 +++++++++++++++--- .../hippo/ehviewer/ehclient/ListParser.java | 11 ++ .../hippo/ehviewer/ehclient/VoteParser.java | 19 +++ 3 files changed, 131 insertions(+), 20 deletions(-) create mode 100644 src/com/hippo/ehviewer/ehclient/ListParser.java create mode 100644 src/com/hippo/ehviewer/ehclient/VoteParser.java diff --git a/src/com/hippo/ehviewer/ehclient/EhClient.java b/src/com/hippo/ehviewer/ehclient/EhClient.java index 647f3437a..c0ce65863 100644 --- a/src/com/hippo/ehviewer/ehclient/EhClient.java +++ b/src/com/hippo/ehviewer/ehclient/EhClient.java @@ -146,12 +146,6 @@ public class EhClient { public void onFailure(String eMsg); } - public interface OnGetMangaListListener { - public void onSuccess(Object checkFlag, ArrayList lmdArray, - int indexPerPage, int maxPage); - public void onFailure(Object checkFlag, String eMsg); - } - public interface OnGetMangaDetailListener { public void onSuccess(GalleryDetail md); public void onFailure(String eMsg); @@ -490,6 +484,12 @@ public class EhClient { } // Get Manga List + public interface OnGetMangaListListener { + public void onSuccess(Object checkFlag, ArrayList lmdArray, + int indexPerPage, int maxPage); + public void onFailure(Object checkFlag, String eMsg); + } + private class GetMangaListPackage { public Object checkFlag; public ArrayList lmdArray; @@ -614,7 +614,52 @@ public class EhClient { eMsg = hp.getEMsg(); } } - + + /* + public void vote(final int gid, final String token, + final String group, final String tag, + final boolean isUp, final OnVoteListener listener) { + final JSONObject json = new JSONObject(); + try { + json.put("method", "taggallery"); + json.put("apiuid", APIUID); + json.put("apikey", APIKEY); + json.put("gid", gid); + json.put("token", token); + json.put("tags", group + ":" + tag); + if (isUp) + json.put("token", 1); + else + json.put("token", -1); + } catch (JSONException e) { + listener.onFailure(e.getMessage()); + return; + } + + new Thread(new Runnable() { + @Override + public void run() { + HttpHelper hp = new HttpHelper(mAppContext); + hp.setOnRespondListener(new HttpHelper.OnRespondListener() { + @Override + public void onSuccess(String pageContext) { + VoteParser parser = new VoteParser(); + if (parser.parser(pageContext)) { + listener.onSuccess(parser.mTagPane); + } else { + listener.onFailure("parser error"); // TODO + } + } + @Override + public void onFailure(String eMsg) { + listener.onFailure(eMsg); + } + }); + hp.postJson(E_API, json); + } + }).start(); + } + */ public void getMangaList(String url, final Object checkFlag, final OnGetMangaListListener listener) { @@ -1468,20 +1513,9 @@ public class EhClient { } - /** - * page start from 1 - * @param gid - * @param page - * @param token - * @return - */ - //public String getPageUrl(String gid, int page, String token) { - - //} - - /********** Use E-hentai API ************/ + // rate for gallery public interface OnRateListener { void onSuccess(float ratingAvg, int ratingCnt); void onFailure(String eMsg); @@ -1526,8 +1560,55 @@ public class EhClient { }).start(); } + // vote for tag + public interface OnVoteListener { + void onSuccess(String tagPane); + void onFailure(String eMsg); + } - + public void vote(final int gid, final String token, + final String group, final String tag, + final boolean isUp, final OnVoteListener listener) { + final JSONObject json = new JSONObject(); + try { + json.put("method", "taggallery"); + json.put("apiuid", APIUID); + json.put("apikey", APIKEY); + json.put("gid", gid); + json.put("token", token); + json.put("tags", group + ":" + tag); + if (isUp) + json.put("token", 1); + else + json.put("token", -1); + } catch (JSONException e) { + listener.onFailure(e.getMessage()); + return; + } + + new Thread(new Runnable() { + @Override + public void run() { + HttpHelper hp = new HttpHelper(mAppContext); + hp.setOnRespondListener(new HttpHelper.OnRespondListener() { + @Override + public void onSuccess(String pageContext) { + VoteParser parser = new VoteParser(); + if (parser.parser(pageContext)) { + listener.onSuccess(parser.mTagPane); + } else { + listener.onFailure("parser error"); // TODO + } + } + @Override + public void onFailure(String eMsg) { + listener.onFailure(eMsg); + } + }); + hp.postJson(E_API, json); + } + }).start(); + } /* diff --git a/src/com/hippo/ehviewer/ehclient/ListParser.java b/src/com/hippo/ehviewer/ehclient/ListParser.java new file mode 100644 index 000000000..a39506327 --- /dev/null +++ b/src/com/hippo/ehviewer/ehclient/ListParser.java @@ -0,0 +1,11 @@ +package com.hippo.ehviewer.ehclient; + +public class ListParser { + + + + boolean parser(String pageContext) { + + return false; + } +} diff --git a/src/com/hippo/ehviewer/ehclient/VoteParser.java b/src/com/hippo/ehviewer/ehclient/VoteParser.java new file mode 100644 index 000000000..32343463c --- /dev/null +++ b/src/com/hippo/ehviewer/ehclient/VoteParser.java @@ -0,0 +1,19 @@ +package com.hippo.ehviewer.ehclient; + +import org.json.JSONException; +import org.json.JSONObject; + +public class VoteParser { + + public String mTagPane; + + boolean parser(String pageContext) { + try { + JSONObject jsonObject = new JSONObject(pageContext); + mTagPane = jsonObject.getString("tagpane"); + return true; + } catch (JSONException e) { + return false; + } + } +}