添加文件搜索
This commit is contained in:
1 parent
d89db7754f
commit
79ffce2f3e
8 files changed
+265
-21
No files matched your search
@@ -66,7 +66,7 @@
|
||||
style="@style/CardSubtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
android:title="@string/list_mode_title"
|
||||
android:entries="@array/list_mode_entries"
|
||||
android:entryValues="@array/list_mode_entry_values"
|
||||
android:defaultValue="1"
|
||||
android:defaultValue="0"
|
||||
android:summary="%s" />
|
||||
|
||||
<com.hippo.ehviewer.preference.NumberOfColumnsPreference
|
||||
|
||||
@@ -468,6 +468,119 @@ public class EhClient {
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Get Gallery List from file search
|
||||
|
||||
public static final int FILE_SEARCH_USE_SIMILARITY_SCAN = 0x1;
|
||||
public static final int FILE_SEARCH_ONLY_SEARCH_COVERS = 0x2;
|
||||
public static final int FILE_SEARCH_SHOW_EXPUNGED = 0x4;
|
||||
|
||||
public static String getFileSearchUrl(int apiMode) {
|
||||
switch (apiMode) {
|
||||
case MODE_EX:
|
||||
return "http://ul.exhentai.org/image_lookup.php";
|
||||
case MODE_G:
|
||||
default:
|
||||
return "http://ul.e-hentai.org/image_lookup.php";
|
||||
}
|
||||
}
|
||||
|
||||
public void getGListFromFileSearch(File file, int searchMode,
|
||||
Object checkFlag, OnGetGListListener listener) {
|
||||
getGListFromFileSearch(file, null, searchMode,
|
||||
Config.getApiMode(), checkFlag, listener);
|
||||
}
|
||||
|
||||
public void getGListFromFileSearch(Bitmap bmp, int searchMode,
|
||||
Object checkFlag, OnGetGListListener listener) {
|
||||
getGListFromFileSearch(null, bmp, searchMode,
|
||||
Config.getApiMode(), checkFlag, listener);
|
||||
}
|
||||
|
||||
private void getGListFromFileSearch(final File file, final Bitmap bitmap,
|
||||
final int searchMode, final int apiMode, final Object checkFlag,
|
||||
final OnGetGListListener listener) {
|
||||
if (file == null && bitmap == null)
|
||||
listener.onFailure(checkFlag, "All null"); // TODO
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
HttpHelper.FormData[] datas = new HttpHelper.FormData[5];
|
||||
HttpHelper.FormData data;
|
||||
// Add file or bitmap
|
||||
if (file != null) {
|
||||
data = new HttpHelper.FileData(file);
|
||||
data.setProperty("Content-Disposition", "form-data; name=\"sfile\"; filename=\"file\"");
|
||||
datas[0] = data;
|
||||
} else {
|
||||
data = new HttpHelper.BitmapData(bitmap);
|
||||
data.setProperty("Content-Disposition", "form-data; name=\"sfile\"; filename=\"hehe.jpg\"");
|
||||
datas[0] = data;
|
||||
}
|
||||
// Add
|
||||
data = new HttpHelper.StringData("File Search");
|
||||
data.setProperty("Content-Disposition", "form-data; name=\"f_sfile\"");
|
||||
datas[1] = data;
|
||||
// Add FILE_SEARCH_USE_SIMILARITY_SCAN
|
||||
if ((searchMode & FILE_SEARCH_USE_SIMILARITY_SCAN) != 0)
|
||||
data = new HttpHelper.StringData("on");
|
||||
else
|
||||
data = new HttpHelper.StringData("off");
|
||||
data.setProperty("Content-Disposition", "form-data; name=\"fs_similar\"");
|
||||
datas[2] = data;
|
||||
// Add FILE_SEARCH_ONLY_SEARCH_COVERS
|
||||
if ((searchMode & FILE_SEARCH_ONLY_SEARCH_COVERS) != 0)
|
||||
data = new HttpHelper.StringData("on");
|
||||
else
|
||||
data = new HttpHelper.StringData("off");
|
||||
data.setProperty("Content-Disposition", "form-data; name=\"fs_covers\"");
|
||||
datas[3] = data;
|
||||
// Add FILE_SEARCH_SHOW_EXPUNGED
|
||||
if ((searchMode & FILE_SEARCH_SHOW_EXPUNGED) != 0)
|
||||
data = new HttpHelper.StringData("on");
|
||||
else
|
||||
data = new HttpHelper.StringData("off");
|
||||
data.setProperty("Content-Disposition", "form-data; name=\"fs_exp\"");
|
||||
datas[4] = data;
|
||||
|
||||
String body = hp.postFormData(getFileSearchUrl(apiMode), datas);
|
||||
GetGListResponder responder;
|
||||
if (body != null) { // Get ok
|
||||
// If no element, it might be a notice
|
||||
if (!body.contains("<")) {
|
||||
responder = new GetGListResponder(listener, checkFlag, body);
|
||||
} else {
|
||||
final ListParser parser = new ListParser();
|
||||
switch (parser.parser(body, apiMode)) {
|
||||
case ListParser.ALL:
|
||||
responder = new GetGListResponder(listener, checkFlag,
|
||||
parser.giList, parser.pageNum);
|
||||
break;
|
||||
case ListParser.NOT_FOUND:
|
||||
responder = new GetGListResponder(listener, checkFlag,
|
||||
parser.giList, 0);
|
||||
break;
|
||||
case ListParser.INDEX_ERROR:
|
||||
responder = new GetGListResponder(listener, checkFlag,
|
||||
"index error"); // TODO
|
||||
break;
|
||||
case ListParser.PARSER_ERROR:
|
||||
default:
|
||||
responder = new GetGListResponder(listener, checkFlag, "parser error"); // TODO
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
responder = new GetGListResponder(listener, checkFlag, hp.getEMsg());
|
||||
}
|
||||
|
||||
mHandler.post(responder);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
// Get gallery Detail
|
||||
public interface OnGetGDetailListener {
|
||||
public void onSuccess(GalleryDetail md);
|
||||
|
||||
@@ -50,7 +50,8 @@ public class EhInfo {
|
||||
|
||||
public static final String EX_HOST = "exhentai.org";
|
||||
public static final String[] COOKIABLE_HOSTS = {"exhentai.org",
|
||||
"g.e-hentai.org", "forums.e-hentai.org"};
|
||||
"g.e-hentai.org", "forums.e-hentai.org", "ul.exhentai.org",
|
||||
"ul.e-hentai.org"};
|
||||
|
||||
private static final String KEY_LOGIN = "login";
|
||||
private static final boolean DEFAULT_LOGIN = false;
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.hippo.ehviewer.network;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -27,8 +29,11 @@ import java.net.MalformedURLException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@@ -181,7 +186,7 @@ public class HttpHelper {
|
||||
boolean isCookiable = isUrlCookiable(url);
|
||||
while (redirectionCount++ < Constant.MAX_REDIRECTS) {
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setInstanceFollowRedirects(true);
|
||||
//conn.setInstanceFollowRedirects(true);
|
||||
conn.setRequestProperty("User-Agent", Constant.userAgent);
|
||||
conn.setConnectTimeout(Constant.DEFAULT_TIMEOUT);
|
||||
conn.setReadTimeout(Constant.DEFAULT_TIMEOUT);
|
||||
@@ -219,6 +224,7 @@ public class HttpHelper {
|
||||
case HttpURLConnection.HTTP_SEE_OTHER:
|
||||
case Constant.HTTP_TEMP_REDIRECT:
|
||||
final String location = conn.getHeaderField("Location");
|
||||
Log.d(TAG, "New location " + location);
|
||||
conn.disconnect();
|
||||
url = new URL(url, location);
|
||||
continue;
|
||||
@@ -462,6 +468,123 @@ public class HttpHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class FormData {
|
||||
private final Map<String, String> mProperties;
|
||||
|
||||
public FormData() {
|
||||
mProperties = new LinkedHashMap<String, String>();
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
mProperties.put(key, value);
|
||||
}
|
||||
|
||||
public void clearProperty(String key) {
|
||||
mProperties.remove(key);
|
||||
}
|
||||
|
||||
public void clearAllProperties() {
|
||||
mProperties.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put information to target OutputStream.
|
||||
*
|
||||
* @param os Target OutputStream
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract void output(OutputStream os) throws IOException;
|
||||
|
||||
public void doOutPut(OutputStream os) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String key : mProperties.keySet())
|
||||
sb.append(key).append(": ").append(mProperties.get(key)).append("\r\n");
|
||||
sb.append("\r\n");
|
||||
os.write(sb.toString().getBytes());
|
||||
output(os);
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringData extends FormData {
|
||||
private final String mStr;
|
||||
|
||||
public StringData(String str) {
|
||||
mStr = str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(OutputStream os) throws IOException {
|
||||
os.write(mStr.getBytes());
|
||||
os.write("\r\n".getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
public static class BitmapData extends FormData {
|
||||
private final Bitmap mBitmap;
|
||||
|
||||
public BitmapData(Bitmap bmp) {
|
||||
mBitmap = bmp;
|
||||
setProperty("Content-Type", "image/jpeg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(OutputStream os) throws IOException {
|
||||
mBitmap.compress(Bitmap.CompressFormat.JPEG, 80, os); //TODO I need a better quality
|
||||
os.write("\r\n".getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
public static class FileData extends FormData {
|
||||
private final File mFile;
|
||||
|
||||
public FileData(File file) {
|
||||
mFile = file;
|
||||
setProperty("Content-Type",
|
||||
URLConnection.guessContentTypeFromName(file.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(OutputStream os) throws IOException {
|
||||
Util.copy(new FileInputStream(mFile), os, 1024);
|
||||
os.write("\r\n".getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
private class PostFormDataHelper extends GetStringHelper {
|
||||
private static final String BOUNDARY = "------WebKitFormBoundary7eDB0hDQ91s22Tkf";
|
||||
|
||||
private final FormData[] mDatas;
|
||||
|
||||
|
||||
public PostFormDataHelper(String url, FormData[] datas) {
|
||||
super(url);
|
||||
mDatas = datas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeConnect(HttpURLConnection conn) throws Exception {
|
||||
super.onBeforeConnect(conn);
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.setUseCaches(false);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundary7eDB0hDQ91s22Tkf");
|
||||
|
||||
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
|
||||
|
||||
for (FormData data : mDatas) {
|
||||
out.write(BOUNDARY.getBytes());
|
||||
out.write("\r\n".getBytes());
|
||||
data.doOutPut(out);
|
||||
}
|
||||
out.write(BOUNDARY.getBytes());
|
||||
out.write("--".getBytes());
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
private class GetImageHelper implements RequestHelper {
|
||||
private final String mUrl;
|
||||
|
||||
@@ -692,6 +815,16 @@ public class HttpHelper {
|
||||
return (String)requst(new PostJsonHelper(url, json));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post form data, multipart/form-data
|
||||
* @param url
|
||||
* @param datas
|
||||
* @return
|
||||
*/
|
||||
public String postFormData(String url, FormData[] datas) {
|
||||
return (String)requst(new PostFormDataHelper(url, datas));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image
|
||||
* @param url
|
||||
|
||||
@@ -72,7 +72,7 @@ import com.readystatesoftware.systembartint.SystemBarTintManager.SystemBarConfig
|
||||
|
||||
public class SettingsActivity extends AbstractPreferenceActivity {
|
||||
@SuppressWarnings("unused")
|
||||
private static String TAG = "Settings";
|
||||
private static String TAG = SettingsActivity.class.getSimpleName();
|
||||
|
||||
public static final String KEY_FRAGMENT = "FRAGMENT";
|
||||
public static final int DEFAULT = -0x1;
|
||||
@@ -101,7 +101,7 @@ public class SettingsActivity extends AbstractPreferenceActivity {
|
||||
|
||||
mListView.setPadding(mListView.getPaddingLeft(),
|
||||
mSystemBarConfig.getStatusBarHeight() + mSystemBarConfig.getActionBarHeight(),
|
||||
originPaddingRight + mSystemBarConfig.getNavigationBarWidth(),
|
||||
originPaddingRight,
|
||||
originPaddingBottom);
|
||||
break;
|
||||
}
|
||||
@@ -145,17 +145,6 @@ public class SettingsActivity extends AbstractPreferenceActivity {
|
||||
originPaddingBottom = mListView.getPaddingBottom();
|
||||
|
||||
adjustPadding();
|
||||
|
||||
/*
|
||||
switch (savedInstanceState.getInt(KEY_FRAGMENT, DEFAULT)) {
|
||||
case DISPLAY:
|
||||
this.star.startPreferenceFragment(fragment, true);
|
||||
break;
|
||||
case DATA:
|
||||
break;
|
||||
case ABOUT:
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,7 +250,7 @@ public class SettingsActivity extends AbstractPreferenceActivity {
|
||||
case Ui.ORIENTATION_LANDSCAPE:
|
||||
mListView.setPadding(mListView.getPaddingLeft(),
|
||||
mSystemBarConfig.getStatusBarHeight() + mSystemBarConfig.getActionBarHeight(),
|
||||
originPaddingRight + mSystemBarConfig.getNavigationBarWidth(),
|
||||
originPaddingRight,
|
||||
originPaddingBottom);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public class Config {
|
||||
/****** Display ******/
|
||||
|
||||
private static final String KEY_LIST_MODE = "list_mode";
|
||||
private static final String DEFAULT_LIST_MODE = "1";
|
||||
private static final String DEFAULT_LIST_MODE = "0";
|
||||
|
||||
private static final String KEY_LIST_THUMB_COLUMNS_PORTRAIT = "list_thumb_columns_portrait";
|
||||
private static final int DEFAULT_LIST_THUMB_COLUMNS_PORTRAIT = 3;
|
||||
|
||||
@@ -48,6 +48,7 @@ public class SimpleGridLayout extends ViewGroup {
|
||||
|
||||
public SimpleGridLayout(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public SimpleGridLayout(Context context, AttributeSet attrs) {
|
||||
@@ -56,6 +57,7 @@ public class SimpleGridLayout extends ViewGroup {
|
||||
|
||||
public SimpleGridLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SimpleGridLayout, defStyle, 0);
|
||||
|
||||
@@ -81,9 +83,15 @@ public class SimpleGridLayout extends ViewGroup {
|
||||
typedArray.recycle();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
setWillNotDraw(true);
|
||||
}
|
||||
|
||||
public void setItemMargin(int itemMargin) {
|
||||
mItemMargin = itemMargin;
|
||||
requestLayout();
|
||||
if (mItemMargin != itemMargin) {
|
||||
mItemMargin = itemMargin;
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void setColumnCount(int columnCount) {
|
||||
|
||||
Reference in new issue
Block a user