Use user own apiuid and apikey
This commit is contained in:
1 parent
0aad8ca1e8
commit
8abefdb6d4
10 files changed
+43
-17
No files matched your search
@@ -159,7 +159,7 @@ public class EhClient {
|
||||
case METHOD_GET_PREVIEW_SET:
|
||||
return EhEngine.getPreviewSet(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_RATE_GALLERY:
|
||||
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Float) params[2]);
|
||||
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]);
|
||||
case METHOD_GET_COMMENT_GALLERY:
|
||||
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
case METHOD_GET_GALLERY_TOKEN:
|
||||
@@ -179,7 +179,7 @@ public class EhClient {
|
||||
case METHOD_GET_PROFILE:
|
||||
return EhEngine.getProfile(this, mOkHttpClient);
|
||||
case METHOD_VOTE_COMMENT:
|
||||
return EhEngine.voteComment(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (Integer) params[3]);
|
||||
return EhEngine.voteComment(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Long) params[4], (Integer) params[5]);
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
|
||||
@@ -77,9 +77,6 @@ public class EhEngine {
|
||||
private static final String SAD_PANDA_TYPE = "image/gif";
|
||||
private static final String SAD_PANDA_LENGTH = "9615";
|
||||
|
||||
public static final long APIUID = 1363542;
|
||||
public static final String APIKEY = "f4b5407ab1727b9d08d7";
|
||||
|
||||
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
public static EhFilter sEhFilter;
|
||||
@@ -336,11 +333,12 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static RateGalleryParser.Result rateGallery(EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long gid, String token, float rating) throws Exception {
|
||||
OkHttpClient okHttpClient, long apiUid, String apiKey, long gid,
|
||||
String token, float rating) throws Exception {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "rategallery");
|
||||
json.put("apiuid", APIUID);
|
||||
json.put("apikey", APIKEY);
|
||||
json.put("apiuid", apiUid);
|
||||
json.put("apikey", apiKey);
|
||||
json.put("gid", gid);
|
||||
json.put("token", token);
|
||||
json.put("rating", (int) Math.ceil(rating * 2));
|
||||
@@ -675,11 +673,11 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static VoteCommentParser.Result voteComment(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, long commentId, int commentVote) throws Exception {
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Exception {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "votecomment");
|
||||
json.put("apiuid", APIUID);
|
||||
json.put("apikey", APIKEY);
|
||||
json.put("apiuid", apiUid);
|
||||
json.put("apikey", apiKey);
|
||||
json.put("gid", gid);
|
||||
json.put("token", token);
|
||||
json.put("comment_id", commentId);
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.Arrays;
|
||||
|
||||
public class GalleryDetail extends GalleryInfo {
|
||||
|
||||
public long apiUid = -1L;
|
||||
public String apiKey;
|
||||
public int torrentCount;
|
||||
public String torrentUrl;
|
||||
public String parent;
|
||||
|
||||
@@ -54,7 +54,7 @@ import java.util.regex.Pattern;
|
||||
public class GalleryDetailParser {
|
||||
|
||||
private static final Pattern PATTERN_ERROR = Pattern.compile("<div class=\"d\">\n<p>([^<]+)</p>");
|
||||
private static final Pattern PATTERN_DETAIL = Pattern.compile("var gid = (\\d+).+?var token = \"([a-f0-9]+)\"", Pattern.DOTALL);
|
||||
private static final Pattern PATTERN_DETAIL = Pattern.compile("var gid = (\\d+);.+?var token = \"([a-f0-9]+)\";.+?var apiuid = ([\\-\\d]+);.+?var apikey = \"([a-f0-9]+)\";", Pattern.DOTALL);
|
||||
private static final Pattern PATTERN_TORRENT = Pattern.compile("<a[^<>]*onclick=\"return popUp\\('([^']+)'[^)]+\\)\">Torrent Download \\( (\\d+) \\)</a>");
|
||||
private static final Pattern PATTERN_TAG_GROUP = Pattern.compile("<tr><td[^<>]+>([\\w\\s]+):</td><td>(?:<div[^<>]+><a[^<>]+>[\\w\\s]+</a></div>)+</td></tr>");
|
||||
private static final Pattern PATTERN_TAG = Pattern.compile("<div[^<>]+><a[^<>]+>([\\w\\s]+)</a></div>");
|
||||
@@ -109,6 +109,8 @@ public class GalleryDetailParser {
|
||||
if (matcher.find()) {
|
||||
gd.gid = Long.parseLong(matcher.group(1));
|
||||
gd.token = matcher.group(2);
|
||||
gd.apiUid = NumberUtils.parseLongSafely(matcher.group(3), -1L);
|
||||
gd.apiKey = matcher.group(4);
|
||||
} else {
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
|
||||
@@ -84,10 +84,14 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
public static final String TAG = GalleryCommentsScene.class.getSimpleName();
|
||||
|
||||
public static final String KEY_API_UID = "api_uid";
|
||||
public static final String KEY_API_KEY = "api_key";
|
||||
public static final String KEY_GID = "gid";
|
||||
public static final String KEY_TOKEN = "token";
|
||||
public static final String KEY_COMMENTS = "comments";
|
||||
|
||||
private long mApiUid;
|
||||
private String mApiKey;
|
||||
private long mGid;
|
||||
private String mToken;
|
||||
@Nullable
|
||||
@@ -126,7 +130,9 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
mGid = args.getLong(KEY_GID, -1);
|
||||
mApiUid = args.getLong(KEY_API_UID, -1L);
|
||||
mApiKey = args.getString(KEY_API_KEY);
|
||||
mGid = args.getLong(KEY_GID, -1L);
|
||||
mToken = args.getString(KEY_TOKEN, null);
|
||||
Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS);
|
||||
if (parcelables instanceof GalleryComment[]) {
|
||||
@@ -139,7 +145,9 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onRestore(@NonNull Bundle savedInstanceState) {
|
||||
mGid = savedInstanceState.getLong(KEY_GID, -1);
|
||||
mApiUid = savedInstanceState.getLong(KEY_API_UID, -1L);
|
||||
mApiKey = savedInstanceState.getString(KEY_API_KEY);
|
||||
mGid = savedInstanceState.getLong(KEY_GID, -1L);
|
||||
mToken = savedInstanceState.getString(KEY_TOKEN, null);
|
||||
Parcelable[] parcelables = savedInstanceState.getParcelableArray(KEY_COMMENTS);
|
||||
if (parcelables instanceof GalleryComment[]) {
|
||||
@@ -150,6 +158,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putLong(KEY_API_UID, mApiUid);
|
||||
outState.putString(KEY_API_KEY, mApiKey);
|
||||
outState.putLong(KEY_GID, mGid);
|
||||
outState.putString(KEY_TOKEN, mToken);
|
||||
outState.putParcelableArray(KEY_COMMENTS, mComments);
|
||||
@@ -244,7 +254,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_VOTE_COMMENT)
|
||||
.setArgs(mGid, mToken, id, vote)
|
||||
.setArgs(mApiUid, mApiKey, mGid, mToken, id, vote)
|
||||
.setCallback(new VoteCommentListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
@@ -259,8 +269,9 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
final GalleryComment comment = mComments[position];
|
||||
String[] menuArray;
|
||||
Resources resources = context.getResources();
|
||||
if (0 == comment.id) {
|
||||
if (0 == comment.id || mApiUid < 0) {
|
||||
// 0 id is uploader comment, can't vote
|
||||
// Not sign in, can't vote
|
||||
menuArray = new String[1];
|
||||
menuArray[0] = resources.getString(R.string.copy_comment_text);
|
||||
} else {
|
||||
@@ -586,8 +597,10 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
comment.score = result.score;
|
||||
if (result.expectVote > 0) {
|
||||
comment.voteUp = 0 != result.vote;
|
||||
comment.voteDown = false;
|
||||
} else {
|
||||
comment.voteDown = 0 != result.vote;
|
||||
comment.voteUp = false;
|
||||
}
|
||||
|
||||
mAdapter.notifyItemChanged(position);
|
||||
|
||||
@@ -1127,6 +1127,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
if (mGalleryDetail == null) {
|
||||
return;
|
||||
}
|
||||
if (mGalleryDetail.apiUid < 0) {
|
||||
showTip(R.string.sign_in_first, LENGTH_SHORT);
|
||||
return;
|
||||
}
|
||||
RateDialogHelper helper = new RateDialogHelper();
|
||||
Dialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.rate)
|
||||
@@ -1142,6 +1146,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return;
|
||||
}
|
||||
Bundle args = new Bundle();
|
||||
args.putLong(GalleryCommentsScene.KEY_API_UID, mGalleryDetail.apiUid);
|
||||
args.putString(GalleryCommentsScene.KEY_API_KEY, mGalleryDetail.apiKey);
|
||||
args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
|
||||
args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
|
||||
args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments);
|
||||
@@ -1689,7 +1695,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_RATE_GALLERY)
|
||||
.setArgs(mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
|
||||
.setArgs(mGalleryDetail.apiUid, mGalleryDetail.apiKey,
|
||||
mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
|
||||
.setCallback(new RateGalleryListener(context,
|
||||
activity.getStageId(), getTag(), mGalleryDetail.gid));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
Reference in new issue
Block a user