Improve detail scene
This commit is contained in:
1 parent
a01e43ea95
commit
3f6d3ea21c
47 files changed
+1647
-89
No files matched your search
@@ -19,8 +19,9 @@ package com.hippo.ehviewer.client;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
|
||||
import com.hippo.ehviewer.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.PreviewSet;
|
||||
import com.hippo.ehviewer.network.EhOkHttpClient;
|
||||
import com.hippo.network.ResponseCodeException;
|
||||
import com.hippo.util.PriorityThreadFactory;
|
||||
@@ -426,6 +427,10 @@ public final class EhClient {
|
||||
gd.tags = parser.tags;
|
||||
gd.comments = parser.comments;
|
||||
gd.previewPageCount = parser.previewPageCount;
|
||||
gd.previewSetArray = new PreviewSet[gd.previewPageCount];
|
||||
gd.previewSetArray[0] = parser.previewSet;
|
||||
gd.previewSetArray[0].setStartIndex(0);
|
||||
gd.previewSetArray[0].setGid(gd.gid);
|
||||
|
||||
return gd;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.data.Comment;
|
||||
import com.hippo.ehviewer.data.TagGroup;
|
||||
import com.hippo.ehviewer.client.data.Comment;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.client.data.NormalPreviewSet;
|
||||
import com.hippo.ehviewer.client.data.PreviewSet;
|
||||
import com.hippo.ehviewer.client.data.TagGroup;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.util.AssertUtils;
|
||||
import com.hippo.util.Utils;
|
||||
@@ -52,6 +55,7 @@ public class GalleryDetailParser {
|
||||
public static final int REQUEST_DETAIL = 0x1;
|
||||
public static final int REQUEST_TAG = 0x2;
|
||||
public static final int REQUEST_PREVIEW_INFO = 0x4;
|
||||
public static final int REQUEST_PREVIEW = 0x8;
|
||||
public static final int REQUEST_COMMENT = 0x10;
|
||||
|
||||
private static final CommentSort COMMENT_SORTER = new CommentSort();
|
||||
@@ -84,6 +88,8 @@ public class GalleryDetailParser {
|
||||
|
||||
public int previewPageCount;
|
||||
|
||||
public PreviewSet previewSet;
|
||||
|
||||
private String sortOut(String str) {
|
||||
// Avoid null
|
||||
if (str == null) {
|
||||
@@ -104,6 +110,36 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseNormalPreview(String body) {
|
||||
Pattern p = Pattern.compile("<div[^<>]*class=\"gdtm\"[^<>]*><div[^<>]*width:(\\d+)[^<>]*height:(\\d+)[^<>]*\\((.+?)\\)[^<>]*-(\\d+)px[^<>]*><a[^<>]*href=\"(.+?)\"[^<>]*>");
|
||||
Matcher m = p.matcher(body);
|
||||
NormalPreviewSet normalPreviewSet = new NormalPreviewSet();
|
||||
while (m.find()) {
|
||||
normalPreviewSet.addItem(m.group(3), Integer.parseInt(m.group(4)), 0,
|
||||
Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)),
|
||||
m.group(5));
|
||||
}
|
||||
previewSet = normalPreviewSet;
|
||||
}
|
||||
|
||||
private void parseLargePreview(String body) {
|
||||
Pattern p = Pattern.compile("<div class=\"gdtl\".+?<a href=\"(.+?)\"><img.+?src=\"(.+?)\"");
|
||||
Matcher m = p.matcher(body);
|
||||
LargePreviewSet largePreviewSet = new LargePreviewSet();
|
||||
while (m.find()) {
|
||||
largePreviewSet.addItem(m.group(2), m.group(1));
|
||||
}
|
||||
previewSet = largePreviewSet;
|
||||
}
|
||||
|
||||
private void parsePreview(String body) {
|
||||
if (body.contains("<div class=\"gdtm\"")) {
|
||||
parseNormalPreview(body);
|
||||
} else {
|
||||
parseLargePreview(body);
|
||||
}
|
||||
}
|
||||
|
||||
private void parse(String body, int request) throws EhException {
|
||||
Pattern p;
|
||||
Matcher m;
|
||||
@@ -240,6 +276,11 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
|
||||
// Get preview
|
||||
if ((request & REQUEST_PREVIEW_INFO) != 0) {
|
||||
parsePreview(body);
|
||||
}
|
||||
|
||||
// Get comment
|
||||
if ((request & REQUEST_COMMENT) != 0) {
|
||||
p = Pattern.compile("<div class=\"c3\">Posted on ([^<>]+) by: <a[^<>]+>([^<>]+)</a>.+?<div class=\"c6\"[^>]*>(.+?)</div><div class=\"c[78]\"");
|
||||
@@ -258,6 +299,10 @@ public class GalleryDetailParser {
|
||||
}
|
||||
Collections.sort(comments, COMMENT_SORTER);
|
||||
}
|
||||
|
||||
if ((request & REQUEST_COMMENT) != 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void parse(String body, int request, int source) throws Exception {
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.data.LofiGalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.LofiGalleryInfo;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.util.AssertException;
|
||||
import com.hippo.util.AssertUtils;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.util.Utils;
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Comment {
|
||||
public String time;
|
||||
public Date date;
|
||||
public String user;
|
||||
public String comment;
|
||||
|
||||
public Comment (String time, Date date, String user, String comment) {
|
||||
this.time = time;
|
||||
this.date = date;
|
||||
this.user = user;
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GalleryDetail extends GalleryInfo {
|
||||
|
||||
public String thumb;
|
||||
public String title;
|
||||
public String titleJpn;
|
||||
public int category;
|
||||
public String uploader;
|
||||
|
||||
public int torrentCount;
|
||||
public String torrentUrl;
|
||||
|
||||
public String posted;
|
||||
public String parent;
|
||||
public String visible;
|
||||
public String language;
|
||||
public String size;
|
||||
public String resize;
|
||||
public int pageCount;
|
||||
public int favoredTimes;
|
||||
public boolean isFavored;
|
||||
public float rating;
|
||||
public int ratedTimes;
|
||||
|
||||
public List<TagGroup> tags;
|
||||
public List<Comment> comments;
|
||||
|
||||
public int previewPageCount;
|
||||
|
||||
public PreviewSet[] previewSetArray;
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GalleryInfo implements Parcelable {
|
||||
|
||||
/**
|
||||
* ISO 639-1
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static final String S_LANG_JA = "JA";
|
||||
public static final String S_LANG_EN = "EN";
|
||||
public static final String S_LANG_ZH = "ZH";
|
||||
public static final String S_LANG_NL = "NL";
|
||||
public static final String S_LANG_FR = "FR";
|
||||
public static final String S_LANG_DE = "DE";
|
||||
public static final String S_LANG_HU = "HU";
|
||||
public static final String S_LANG_IT = "IT";
|
||||
public static final String S_LANG_KO = "KO";
|
||||
public static final String S_LANG_PL = "PL";
|
||||
public static final String S_LANG_PT = "PT";
|
||||
public static final String S_LANG_RU = "RU";
|
||||
public static final String S_LANG_ES = "ES";
|
||||
public static final String S_LANG_TH = "TH";
|
||||
public static final String S_LANG_VI = "VI";
|
||||
|
||||
public static final String[] S_LANGS = {
|
||||
S_LANG_EN,
|
||||
S_LANG_ZH,
|
||||
S_LANG_ES,
|
||||
S_LANG_KO,
|
||||
S_LANG_RU,
|
||||
S_LANG_FR,
|
||||
S_LANG_PT,
|
||||
S_LANG_TH,
|
||||
S_LANG_DE,
|
||||
S_LANG_IT,
|
||||
S_LANG_VI,
|
||||
S_LANG_PL,
|
||||
S_LANG_HU,
|
||||
S_LANG_NL,
|
||||
};
|
||||
|
||||
public static final String[] S_LANG_PATTERNS = {
|
||||
"[(\\[]eng(?:lish)?[)\\]]",
|
||||
"[((\\[]chinese[))\\]]|[汉漢]化|中[国國][语語]|中文|[(\\[]CN[)\\]]",
|
||||
"[(\\[]spanish[)\\]]|[(\\[]Español[)\\]]",
|
||||
"[(\\[]korean?[)\\]]",
|
||||
"[(\\[]rus(?:sian)?[)\\]]",
|
||||
"[(\\[]fr(?:ench)?[)\\]]",
|
||||
"[(\\[]portuguese",
|
||||
"[(\\[]thai(?: ภาษาไทย)?[)\\]]",
|
||||
"[(\\[]german[)\\]]",
|
||||
"[(\\[]italiano?[)\\]]",
|
||||
"[(\\[]vietnamese(?: Tiếng Việt)?[)\\]]",
|
||||
"[(\\[]polish[)\\]]",
|
||||
"[(\\[]hun(?:garian)?[)\\]]",
|
||||
"[(\\[]dutch[)\\]]",
|
||||
};
|
||||
|
||||
public int gid;
|
||||
public String token;
|
||||
public String title;
|
||||
public String posted;
|
||||
public int category;
|
||||
public String thumb;
|
||||
public String uploader;
|
||||
public float rating;
|
||||
/**
|
||||
* Will not be recond
|
||||
*/
|
||||
public int thumbWidth;
|
||||
/**
|
||||
* Will not be recond
|
||||
*/
|
||||
public int thumbHeight;
|
||||
/**
|
||||
* language get from title
|
||||
*/
|
||||
public String simpleLanguage;
|
||||
|
||||
public static final Creator<GalleryInfo> CREATOR =
|
||||
new Creator<GalleryInfo>() {
|
||||
@Override
|
||||
public GalleryInfo createFromParcel(Parcel source) {
|
||||
GalleryInfo p = new GalleryInfo();
|
||||
p.gid = source.readInt();
|
||||
p.token = source.readString();
|
||||
p.title = source.readString();
|
||||
p.posted = source.readString();
|
||||
p.category = source.readInt();
|
||||
p.thumb = source.readString();
|
||||
p.uploader = source.readString();
|
||||
p.rating = source.readFloat();
|
||||
p.simpleLanguage = source.readString();
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryInfo[] newArray(int size) {
|
||||
return new GalleryInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(gid);
|
||||
dest.writeString(token);
|
||||
dest.writeString(title);
|
||||
dest.writeString(posted);
|
||||
dest.writeInt(category);
|
||||
dest.writeString(thumb);
|
||||
dest.writeString(uploader);
|
||||
dest.writeFloat(rating);
|
||||
dest.writeString(simpleLanguage);
|
||||
}
|
||||
|
||||
public GalleryInfo() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public GalleryInfo(GalleryInfo gi) {
|
||||
gid = gi.gid;
|
||||
token = gi.token;
|
||||
title = gi.title;
|
||||
posted = gi.posted;
|
||||
category = gi.category;
|
||||
thumb = gi.thumb;
|
||||
uploader = gi.uploader;
|
||||
rating = gi.rating;
|
||||
simpleLanguage = gi.simpleLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GalleryInfo && ((GalleryInfo) o).gid == gid;
|
||||
}
|
||||
|
||||
public final void generateSLang() {
|
||||
for (int i = 0; i < S_LANGS.length; i++) {
|
||||
if (Pattern.compile(S_LANG_PATTERNS[i], Pattern.CASE_INSENSITIVE).matcher(title).find()) {
|
||||
simpleLanguage = S_LANGS[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
simpleLanguage = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2015 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.data;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.ehviewer.EhImageKeyFactory;
|
||||
import com.hippo.ehviewer.widget.LoadImageView;
|
||||
import com.hippo.widget.SimpleGridLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LargePreviewSet extends PreviewSet {
|
||||
|
||||
private List<Item> mItemList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return mItemList.size();
|
||||
}
|
||||
|
||||
public void addItem(String imageUrl, String pageUrl) {
|
||||
mItemList.add(new Item(imageUrl, pageUrl));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(SimpleGridLayout simpleGridLayout, LayoutInflater inflater, Conaco conaco) {
|
||||
ensureViewGroup(simpleGridLayout, inflater);
|
||||
|
||||
int size = mItemList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final Item item = mItemList.get(i);
|
||||
final int index = i + getStartIndex();
|
||||
final ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i);
|
||||
conaco.load((LoadImageView) viewGroup.getChildAt(0),
|
||||
EhImageKeyFactory.getLargePreviewKey(getGid(), index), item.imageUrl);
|
||||
((TextView) viewGroup.getChildAt(1)).setText(Integer.toString(index + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLoadTask(SimpleGridLayout simpleGridLayout, Conaco conaco) {
|
||||
int count = simpleGridLayout.getChildCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i);
|
||||
conaco.cancel((LoadImageView) viewGroup.getChildAt(0));
|
||||
}
|
||||
}
|
||||
|
||||
private class Item {
|
||||
|
||||
public String imageUrl;
|
||||
public String pageUrl;
|
||||
|
||||
public Item(String imageUrl, String pageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
this.pageUrl = pageUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.data;
|
||||
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.widget.AdvanceSearchTable;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class ListUrlBuilder {
|
||||
|
||||
// Mode
|
||||
public static final int MODE_NORMAL = 0x0;
|
||||
public static final int MODE_UPLOADER = 0x1;
|
||||
public static final int MODE_TAG = 0x2;
|
||||
public static final int MODE_POPULAR = 0x3;
|
||||
public static final int MODE_IMAGE_SEARCH = 0x4;
|
||||
|
||||
public static final int ALL_CATEGORT = EhUtils.UNKNOWN - 1;
|
||||
//DOUJINSHI|MANGA|ARTIST_CG|GAME_CG|WESTERN|NON_H|IMAGE_SET|COSPLAY|ASIAN_PORN|MISC;
|
||||
|
||||
public static final int DEFAULT_ADVANCE = AdvanceSearchTable.SNAME | AdvanceSearchTable.STAGS;
|
||||
public static final int DEFAULT_MIN_RATING = 2;
|
||||
|
||||
private int mMode = MODE_NORMAL;
|
||||
|
||||
private int mPageIndex = 0;
|
||||
|
||||
private int mCategory = EhUtils.NONE;
|
||||
private String mKeyword = null;
|
||||
|
||||
private int mAdvanceSearch = -1;
|
||||
private int mMinRating = -1;
|
||||
|
||||
/**
|
||||
* Make this ListUrlBuilder point to homepage
|
||||
*/
|
||||
public void reset() {
|
||||
mMode = MODE_NORMAL;
|
||||
mPageIndex = 0;
|
||||
mCategory = EhUtils.NONE;
|
||||
mKeyword = null;
|
||||
mAdvanceSearch = -1;
|
||||
mMinRating = -1;
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
public int getPageIndex() {
|
||||
return mPageIndex;
|
||||
}
|
||||
|
||||
public void setPageIndex(int pageIndex) {
|
||||
mPageIndex = pageIndex;
|
||||
}
|
||||
|
||||
public int getCategory() {
|
||||
return mCategory;
|
||||
}
|
||||
|
||||
public void setCategory(int category) {
|
||||
mCategory = category;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return mKeyword;
|
||||
}
|
||||
|
||||
public void setKeyword(String keyword) {
|
||||
mKeyword = keyword;
|
||||
}
|
||||
|
||||
public int getAdvanceSearch() {
|
||||
return mAdvanceSearch;
|
||||
}
|
||||
|
||||
public void setAdvanceSearch(int advanceSearch) {
|
||||
mAdvanceSearch = advanceSearch;
|
||||
}
|
||||
|
||||
public int getMinRating() {
|
||||
return mMinRating;
|
||||
}
|
||||
|
||||
public void setMinRating(int minRating) {
|
||||
mMinRating = minRating;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make them the same
|
||||
* @param glub The template
|
||||
*/
|
||||
public void set(ListUrlBuilder glub) {
|
||||
mMode = glub.mMode;
|
||||
mPageIndex = glub.mPageIndex;
|
||||
mCategory = glub.mCategory;
|
||||
mKeyword = glub.mKeyword;
|
||||
mAdvanceSearch = glub.mAdvanceSearch;
|
||||
mMinRating = glub.mMinRating;
|
||||
}
|
||||
|
||||
public String build(int source) throws UnsupportedSearchException {
|
||||
switch (mMode) {
|
||||
default:
|
||||
case MODE_NORMAL:
|
||||
case MODE_UPLOADER: {
|
||||
boolean filter = false;
|
||||
UrlBuilder ub = new UrlBuilder(EhClient.getUrlHeader(source));
|
||||
if (mCategory != EhUtils.NONE) {
|
||||
ub.addQuery("f_doujinshi", ((mCategory & EhUtils.DOUJINSHI) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_manga", ((mCategory & EhUtils.MANGA) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_artistcg", ((mCategory & EhUtils.ARTIST_CG) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_gamecg", ((mCategory & EhUtils.GAME_CG) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_western", ((mCategory & EhUtils.WESTERN) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_non-h", ((mCategory & EhUtils.NON_H) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_imageset", ((mCategory & EhUtils.IMAGE_SET) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_cosplay", ((mCategory & EhUtils.COSPLAY) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_asianporn", ((mCategory & EhUtils.ASIAN_PORN) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_misc", ((mCategory & EhUtils.MISC) == 0) ? "0" : "1");
|
||||
filter = true;
|
||||
}
|
||||
// Search key
|
||||
if (mKeyword != null) {
|
||||
try {
|
||||
ub.addQuery("f_search", URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
filter = true;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
// Page index
|
||||
if (mPageIndex != 0) {
|
||||
ub.addQuery("page", mPageIndex);
|
||||
}
|
||||
// Advance search
|
||||
if (mAdvanceSearch != -1) {
|
||||
ub.addQuery("advsearch", "1");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SNAME) != 0) ub.addQuery("f_sname", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.STAGS) != 0) ub.addQuery("f_stags", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SDESC) != 0) ub.addQuery("f_sdesc", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.STORR) != 0) ub.addQuery("f_storr", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.STO) != 0) ub.addQuery("f_sto", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SDT1) != 0) ub.addQuery("f_sdt1", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SDT2) != 0) ub.addQuery("f_sdt2", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SH) != 0) ub.addQuery("f_sh", "on");
|
||||
// Set min star
|
||||
if (mMinRating != -1) {
|
||||
ub.addQuery("f_sr", "on");
|
||||
ub.addQuery("f_srdd", mMinRating);
|
||||
}
|
||||
filter = true;
|
||||
}
|
||||
// Add filter foot
|
||||
if (filter) {
|
||||
ub.addQuery("f_apply", "Apply+Filter");
|
||||
}
|
||||
return ub.build();
|
||||
}
|
||||
case MODE_TAG: {
|
||||
if (source == EhClient.SOURCE_LOFI) {
|
||||
throw new UnsupportedSearchException("Lofi do not support tag search");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(EhClient.getUrlHeader(source));
|
||||
sb.append("tag/");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Empty
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
public class LofiGalleryInfo extends GalleryInfo {
|
||||
|
||||
public String[] lofiTags;
|
||||
|
||||
public static final Creator<LofiGalleryInfo> CREATOR =
|
||||
new Creator<LofiGalleryInfo>() {
|
||||
@Override
|
||||
public LofiGalleryInfo createFromParcel(Parcel source) {
|
||||
int length;
|
||||
|
||||
LofiGalleryInfo p = new LofiGalleryInfo();
|
||||
p.gid = source.readInt();
|
||||
p.token = source.readString();
|
||||
p.title = source.readString();
|
||||
p.posted = source.readString();
|
||||
p.category = source.readInt();
|
||||
p.thumb = source.readString();
|
||||
p.uploader = source.readString();
|
||||
p.rating = source.readFloat();
|
||||
p.simpleLanguage = source.readString();
|
||||
|
||||
length = source.readInt();
|
||||
p.lofiTags = new String[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
p.lofiTags[i] = source.readString();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LofiGalleryInfo[] newArray(int size) {
|
||||
return new LofiGalleryInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
public LofiGalleryInfo() {}
|
||||
|
||||
public LofiGalleryInfo(GalleryInfo galleryInfo) {
|
||||
gid = galleryInfo.gid;
|
||||
token = galleryInfo.token;
|
||||
title = galleryInfo.title;
|
||||
posted = galleryInfo.posted;
|
||||
category = galleryInfo.category;
|
||||
thumb = galleryInfo.thumb;
|
||||
uploader = galleryInfo.uploader;
|
||||
rating = galleryInfo.rating;
|
||||
simpleLanguage = galleryInfo.simpleLanguage;
|
||||
lofiTags = new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
||||
int length = lofiTags == null ? 0 : lofiTags.length;
|
||||
dest.writeInt(length);
|
||||
for (int i = 0; i < length; i++)
|
||||
dest.writeString(lofiTags[i]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright 2015 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.data;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.TransitionDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.conaco.BitmapHolder;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.conaco.Unikery;
|
||||
import com.hippo.ehviewer.EhImageKeyFactory;
|
||||
import com.hippo.util.Log;
|
||||
import com.hippo.widget.SimpleGridLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class NormalPreviewSet extends PreviewSet {
|
||||
|
||||
private List<Row> mRowArray = new ArrayList<>();
|
||||
|
||||
private Set<LoadImageTask> mLoadImageTasks = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (Row row : mRowArray) {
|
||||
size += row.itemArray.size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public void addItem(String imageUrl, int xOffset, int yOffset, int width,
|
||||
int height, String url) {
|
||||
Row row;
|
||||
int size = mRowArray.size();
|
||||
if (size == 0 || ! (row = mRowArray.get(size - 1)).imageUrl.equals(imageUrl)) {
|
||||
row = new Row(imageUrl);
|
||||
mRowArray.add(row);
|
||||
}
|
||||
row.addItem(xOffset, yOffset, width, height, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(SimpleGridLayout simpleGridLayout,
|
||||
LayoutInflater inflater, Conaco conaco) {
|
||||
ensureViewGroup(simpleGridLayout, inflater);
|
||||
|
||||
int i = 0;
|
||||
for (Row row : mRowArray) {
|
||||
int rowSize = row.itemArray.size();
|
||||
ImageView[] imageViews = new ImageView[rowSize];
|
||||
for (int j = 0; j < rowSize; j++) {
|
||||
ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i);
|
||||
imageViews[j] = (ImageView) viewGroup.getChildAt(0);
|
||||
((TextView) viewGroup.getChildAt(1)).setText(Integer.toString(i + getStartIndex() + 1));
|
||||
i++;
|
||||
}
|
||||
|
||||
LoadImageTask loadImageTask = new LoadImageTask(row, imageViews);
|
||||
mLoadImageTasks.add(loadImageTask);
|
||||
|
||||
String key;
|
||||
if (row.imageIndex != -1) {
|
||||
key = EhImageKeyFactory.getNormalPreviewKey(getGid(), row.imageIndex);
|
||||
} else {
|
||||
key = row.imageUrl;
|
||||
}
|
||||
conaco.load(loadImageTask, key, row.imageUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLoadTask(SimpleGridLayout simpleGridLayout, Conaco conaco) {
|
||||
for (LoadImageTask loadImageTask : mLoadImageTasks) {
|
||||
conaco.cancel(loadImageTask);
|
||||
}
|
||||
mLoadImageTasks.clear();
|
||||
}
|
||||
|
||||
class LoadImageTask implements Unikery {
|
||||
|
||||
private int mTaskId;
|
||||
private Row mRow;
|
||||
private ImageView[] mImageViews;
|
||||
|
||||
public LoadImageTask(Row row, ImageView[] imageViews) {
|
||||
mRow = row;
|
||||
mImageViews = imageViews;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBitmap(BitmapHolder bitmapHolder, Conaco.Source source) {
|
||||
bitmapHolder.obtain();
|
||||
Bitmap bitmap = bitmapHolder.getBitmap();
|
||||
int maxWidth = bitmap.getWidth();
|
||||
int maxHeight = bitmap.getHeight();
|
||||
|
||||
int size = mRow.itemArray.size();
|
||||
for(int i = 0; i < size; i++) {
|
||||
Item item = mRow.itemArray.get(i);
|
||||
if (item.xOffset + item.width > maxWidth) {
|
||||
item.width = maxWidth - item.xOffset;
|
||||
if (item.width <= 0) {
|
||||
// Bad area
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item.yOffset + item.height > maxHeight) {
|
||||
item.height = maxHeight - item.yOffset;
|
||||
if (item.height <= 0) {
|
||||
// Bad area
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap previewBitmap = Bitmap.createBitmap(bitmap, item.xOffset,
|
||||
item.yOffset, item.width, item.height);
|
||||
|
||||
if (source != Conaco.Source.MEMORY) {
|
||||
Drawable[] layers = new Drawable[2];
|
||||
layers[0] = new ColorDrawable(Color.TRANSPARENT);
|
||||
layers[1] = new BitmapDrawable(mImageViews[i].getResources(), previewBitmap);
|
||||
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
|
||||
mImageViews[i].setImageDrawable(transitionDrawable);
|
||||
transitionDrawable.startTransition(300);
|
||||
} else {
|
||||
mImageViews[i].setImageBitmap(previewBitmap);
|
||||
}
|
||||
}
|
||||
|
||||
bitmapHolder.release();
|
||||
|
||||
mLoadImageTasks.remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawable(Drawable drawable) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskId(int id) {
|
||||
mTaskId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTaskId() {
|
||||
return mTaskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
// TODO
|
||||
mLoadImageTasks.remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
||||
class Row {
|
||||
|
||||
public String imageUrl;
|
||||
public List<Item> itemArray = new ArrayList<>();
|
||||
public int imageIndex;
|
||||
|
||||
public Row(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
|
||||
int index1 = imageUrl.lastIndexOf('-');
|
||||
int index2 = imageUrl.lastIndexOf('.');
|
||||
|
||||
try {
|
||||
imageIndex = Integer.parseInt(imageUrl.substring(index1 + 1, index2)) - 1;
|
||||
} catch (Exception e) {
|
||||
Log.w("Can't get normal preview index", e);
|
||||
imageIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(int xOffset, int yOffset, int width, int height,
|
||||
String url) {
|
||||
itemArray.add(new Item(xOffset, yOffset, width, height, url));
|
||||
}
|
||||
}
|
||||
|
||||
class Item {
|
||||
|
||||
public int xOffset;
|
||||
public int yOffset;
|
||||
public int width;
|
||||
public int height;
|
||||
public String url;
|
||||
|
||||
public Item(int xOffset, int yOffset, int width, int height, String url) {
|
||||
this.xOffset = xOffset;
|
||||
this.yOffset = yOffset;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2015 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.data;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.widget.SimpleGridLayout;
|
||||
|
||||
public abstract class PreviewSet {
|
||||
|
||||
private int mStartIndex;
|
||||
private int mGid;
|
||||
|
||||
public void setStartIndex(int startIndex) {
|
||||
mStartIndex = startIndex;
|
||||
}
|
||||
|
||||
public int getStartIndex() {
|
||||
return mStartIndex;
|
||||
}
|
||||
|
||||
public abstract int size();
|
||||
|
||||
public void setGid(int gid) {
|
||||
mGid = gid;
|
||||
}
|
||||
|
||||
public int getGid() {
|
||||
return mGid;
|
||||
}
|
||||
|
||||
public abstract void bindView(SimpleGridLayout simpleGridLayout,
|
||||
LayoutInflater inflater, Conaco conaco);
|
||||
|
||||
protected void ensureViewGroup(SimpleGridLayout simpleGridLayout, LayoutInflater inflater) {
|
||||
int size = size();
|
||||
int diff = size - simpleGridLayout.getChildCount();
|
||||
|
||||
if (diff > 0) {
|
||||
for (int i = 0; i < diff; i++) {
|
||||
inflater.inflate(R.layout.item_preview, simpleGridLayout, true);
|
||||
}
|
||||
} else if (diff < 0) {
|
||||
diff = -diff;
|
||||
for (int i = 0; i < diff; i++) {
|
||||
simpleGridLayout.removeViews(size, diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void cancelLoadTask(SimpleGridLayout simpleGridLayout, Conaco conaco);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TagGroup {
|
||||
|
||||
public String groupName;
|
||||
private List<String> mTagList = new ArrayList<>();
|
||||
|
||||
public void addTag(String tag) {
|
||||
mTagList.add(tag);
|
||||
}
|
||||
|
||||
public int getTagCount() {
|
||||
return mTagList.size();
|
||||
}
|
||||
|
||||
public String getTagAt(int position) {
|
||||
return mTagList.get(position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.data;
|
||||
|
||||
public class UnsupportedSearchException extends Exception {
|
||||
|
||||
public UnsupportedSearchException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user