Add download
This commit is contained in:
1 parent
3aaf14ef3f
commit
4a80ea7dcd
43 files changed
+2167
-270
No files matched your search
@@ -289,8 +289,10 @@ public final class EhClient {
|
||||
// Clear
|
||||
mEhHttpRequest = null;
|
||||
mListener = null;
|
||||
} else if (status == Status.FINISHED) {
|
||||
mEhHttpRequest.disconnect();
|
||||
} else if (status == Status.RUNNING) {
|
||||
if (mEhHttpRequest != null) {
|
||||
mEhHttpRequest.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class EhEngine {
|
||||
String body = response.getString();
|
||||
return SignInParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
@@ -71,7 +71,7 @@ class EhEngine {
|
||||
String body = response.getString();
|
||||
return GalleryListParser.parse(body, source);
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
@@ -93,7 +93,7 @@ class EhEngine {
|
||||
String body = response.getString();
|
||||
return PopularParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
@@ -116,7 +116,7 @@ class EhEngine {
|
||||
GalleryDetailParser.REQUEST_PREVIEW |
|
||||
GalleryDetailParser.REQUEST_COMMENT);
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
@@ -134,7 +134,7 @@ class EhEngine {
|
||||
String body = response.getString();
|
||||
return GalleryDetailParser.parsePreview(body, source);
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
@@ -174,7 +174,7 @@ class EhEngine {
|
||||
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
@@ -203,7 +203,7 @@ class EhEngine {
|
||||
|
||||
return RateGalleryParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
if (httpRequest.getState() == HttpRequest.STATE_DISCONNECT) {
|
||||
if (httpRequest.isCancelled()) {
|
||||
throw new CanceledException();
|
||||
} else {
|
||||
throw e;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 com.hippo.ehviewer.dao.DownloadInfoObj;
|
||||
import com.hippo.ehviewer.util.DBUtils;
|
||||
|
||||
public class DownloadInfo {
|
||||
|
||||
public static final int STATE_NONE = 0x0;
|
||||
public static final int STATE_WAIT = 0x1;
|
||||
public static final int STATE_DOWNLOAD = 0x2;
|
||||
public static final int STATE_FINISH = 0x3;
|
||||
|
||||
public String tag;
|
||||
public GalleryBase galleryBase;
|
||||
public int state = STATE_NONE;
|
||||
// byte/second, -1 for can't get speed now
|
||||
public long speed;
|
||||
// -1 for unknown
|
||||
public int download = -1;
|
||||
// -1 for unknown
|
||||
public int total = -1;
|
||||
// Integer.MAX_VALUE for unknown
|
||||
public int legacy = Integer.MAX_VALUE;
|
||||
|
||||
public static DownloadInfo fromDownloadInfoObj(DownloadInfoObj obj) {
|
||||
GalleryBase galleryBase = DBUtils.getGalleryBase((int) (long) obj.getGid());
|
||||
if (galleryBase != null) {
|
||||
DownloadInfo downloadInfo = new DownloadInfo();
|
||||
downloadInfo.galleryBase = galleryBase;
|
||||
downloadInfo.tag = obj.getTag();
|
||||
downloadInfo.state = obj.getState();
|
||||
downloadInfo.legacy = obj.getLegacy();
|
||||
return downloadInfo;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user