Skip to content

Commit

Permalink
fixed some more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
PureDark committed Aug 19, 2016
1 parent 71186d1 commit 0bafacf
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "ml.puredark.hviewer"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "0.1.0"
versionCode 2
versionName "0.1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
android:screenOrientation="portrait" />
<activity
android:name=".activities.AddSiteActivity"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"/>
<activity
android:name=".activities.MyCaptureActivity"
android:screenOrientation="portrait"
Expand All @@ -48,7 +49,8 @@
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".activities.ModifySiteActivity"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"/>
<activity
android:name=".activities.FavouriteActivity"
android:screenOrientation="portrait" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ void submit() {
showSnackBar("规则缺少必要参数,请检查");
return;
}
List<Site> sites = siteHolder.getSites();
int sid = 1;
for(Site site : sites){
sid = Math.max(sid, site.sid + 1);
}
newSite.sid = sid;

HViewerApplication.temp = newSite;
siteHolder.addSite(newSite);
Expand Down Expand Up @@ -159,9 +165,6 @@ public void onFailure(HViewerHttpClient.HttpError error) {
private Site parseSite(String json) {
try {
Site site = new Gson().fromJson(json, Site.class);
List<Site> sites = siteHolder.getSites();
int sid = (sites.size() > 0) ? sites.get(sites.size() - 1).sid + 1 : 1;
site.sid = sid;
if (site.indexRule == null || site.galleryRule == null)
showSnackBar("输入的规则缺少信息");
return site;
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/ml/puredark/hviewer/helpers/HProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ml.puredark.hviewer.utils.SharedPreferencesUtil;

public class HProxy {
private static final String PROXY_DEFAULT_SERVER = "https://h-viewer-proxy.herokuapp.com";
// private static final String PROXY_DEFAULT_SERVER = "";
// private static final String PROXY_DEFAULT_SERVER = "https://h-viewer-proxy.herokuapp.com";
private static final String PROXY_DEFAULT_SERVER = null;
private String mTarget;
private String mProxyUrl;

Expand All @@ -21,6 +21,8 @@ public HProxy(String target) {
}

this.mProxyUrl = getProxyServer() + target.substring(hostEndPos);
if(!mProxyUrl.startsWith("http"))
mProxyUrl = mTarget;
}

public static boolean isEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static void post(String url, String paramsString, List<Cookie> cookies, f
}

public static void get(String url, List<Cookie> cookies, final OnResponseListener callback) {
if(url==null||!url.startsWith("http")) {
callback.onFailure(new HttpError(HttpError.ERROR_WRONG_URL));
return;
}
if (HViewerApplication.isNetworkAvailable()) {
HRequestBuilder builder = new HRequestBuilder();
if(cookies!=null){
Expand All @@ -66,7 +70,7 @@ public static void get(String url, List<Cookie> cookies, final OnResponseListene
mClient.newCall(request).enqueue(new HCallback() {
@Override
void onFailure(IOException e) {
callback.onFailure(new HttpError(1009));
callback.onFailure(new HttpError(HttpError.ERROR_NETWORK));
}

@Override
Expand All @@ -75,11 +79,15 @@ void onResponse(String body) {
}
});
} else {
callback.onFailure(new HttpError(1009));
callback.onFailure(new HttpError(HttpError.ERROR_NETWORK));
}
}

public static void post(String url, RequestBody body, List<Cookie> cookies, final OnResponseListener callback) {
if(url==null||!url.startsWith("http")) {
callback.onFailure(new HttpError(HttpError.ERROR_WRONG_URL));
return;
}
if (HViewerApplication.isNetworkAvailable()) {
HRequestBuilder builder = new HRequestBuilder();
if(cookies!=null){
Expand All @@ -96,7 +104,7 @@ public static void post(String url, RequestBody body, List<Cookie> cookies, fina
mClient.newCall(request).enqueue(new HCallback() {
@Override
void onFailure(IOException e) {
callback.onFailure(new HttpError(1009));
callback.onFailure(new HttpError(HttpError.ERROR_NETWORK));
}

@Override
Expand All @@ -105,7 +113,7 @@ void onResponse(String body) {
}
});
} else {
callback.onFailure(new HttpError(1009));
callback.onFailure(new HttpError(HttpError.ERROR_NETWORK));
}
}

Expand Down Expand Up @@ -149,6 +157,7 @@ public static class HttpError {
// Error code constants
public static final int ERROR_UNKNOWN = 1000; //未知错误
public static final int ERROR_NETWORK = 1009; //网络错误
public static final int ERROR_WRONG_URL = 1011; //URL格式错误

private int errorCode;
private String errorString = "";
Expand All @@ -162,6 +171,9 @@ public HttpError(int errorCode) {
case ERROR_NETWORK:
errorString = "网络错误,请重试";
break;
case ERROR_WRONG_URL:
errorString = "URL格式错误";
break;
default:
errorString = "未定义的错误码";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,24 @@ public SitePropViewHolder(View view) {

public String joinSelector(Selector selector) {
String select = (selector.selector != null) ? "$(\"" + selector.selector + "\")" : "";
String function = (selector.fun != null) ? "." + selector.fun : "";
String parameter = (selector.param != null) ? "(\"" + selector.param + "\")" : "";
String function = (selector.fun != null && !"".equals(selector.fun)) ? "." + selector.fun : "";
String parameter = (selector.param != null && !"".equals(selector.param)) ? "(\"" + selector.param + "\")"
: ("".equals(function)) ? "" : "()";
String join = select + function + parameter;
return join;
}

public Selector splitSelector(Selector selector) {
Pattern pattern = Pattern.compile("\\$\\(\"(.*?)\"\\).?(\\w*)?\\(?\"?(\\w*)\"?\\)?", DOTALL);
Pattern pattern = Pattern.compile("\\$\\(\"(.*?)\"\\).?(\\w*)?\\(?\"?([a-zA-z_-]*)\"?\\)?", DOTALL);
Matcher matcher = pattern.matcher(selector.selector);
if (matcher.find() && matcher.groupCount() >= 3) {
selector.selector = matcher.group(1);
selector.fun = matcher.group(2);
selector.param = matcher.group(3);
if ("".equals(selector.fun))
selector.fun = null;
if ("".equals(selector.param))
selector.param = null;
}
return selector;
}
Expand Down
Loading

0 comments on commit 0bafacf

Please sign in to comment.