Skip to content

Commit

Permalink
当uri无法打开的时候,route刷新立即生效,不需要等html加载完成
Browse files Browse the repository at this point in the history
  • Loading branch information
qluan committed Jan 16, 2020
1 parent d314d3e commit bc1a695
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 50 deletions.
2 changes: 1 addition & 1 deletion core/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJ_GROUP=com.douban.rexxar
PROJ_VERSION=0.6.9
PROJ_VERSION=0.7.0
PROJ_NAME=rexxar-android
PROJ_WEBSITEURL=https://github.com/douban/rexxar-android
PROJ_ISSUETRACKERURL=https://github.com/douban/rexxar-android/issues
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/com/douban/rexxar/route/RouteManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,10 @@ public void onFail() {
* @param callback
*/
public void refreshRouteFast(final RouteRefreshCallback callback) {
mRouteRefreshCallback = callback;
RouteFetcher.fetchRoutes(new RouteRefreshCallback() {
@Override
public void onSuccess(String data) {
try {
mCheckingRouteString = null;
saveCachedRoutes(data);
mRoutes = GsonHelper.getInstance().fromJson(data, new TypeToken<Routes>() {
}.getType());
Expand Down Expand Up @@ -436,7 +434,7 @@ public void handleRemote(final String uri, final UriHandleCallback callback) {
if (null == callback) {
return;
}
RouteManager.getInstance().refreshRoute(new RouteManager.RouteRefreshCallback() {
RouteManager.getInstance().refreshRouteFast(new RouteManager.RouteRefreshCallback() {
@Override
public void onSuccess(String data) {
callback.onResult(handleByNative(uri));
Expand Down
111 changes: 65 additions & 46 deletions core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void loadPartialUri(String uri, UriLoadCallback callback) {
* <p>
* 如果map能够匹配上,则
*/
private void loadUri(final String uri, final UriLoadCallback callback, boolean page) {
private void loadUri(final String uri, final UriLoadCallback callback, final boolean page) {
LogUtils.i(TAG, "loadUri , uri = " + (null != uri ? uri : "null"));
if (TextUtils.isEmpty(uri)) {
throw new IllegalArgumentException("[RexxarWebView] [loadUri] uri can not be null");
Expand All @@ -311,60 +311,79 @@ private void loadUri(final String uri, final UriLoadCallback callback, boolean p
}
if (null == route) {
LogUtils.i(TAG, "route not found");
if (null != callback) {
callback.onFail(RxLoadError.ROUTE_NOT_FOUND);
}
return;
}
if (null != callback) {
callback.onStartLoad();
}
if (CacheHelper.getInstance().cacheEnabled() && CacheHelper.getInstance().hasHtmlCached(route.getHtmlFile())) {
// show cache
doLoadCache(uri, route);
if (null != callback) {
callback.onSuccess();
}
} else {
if (null != callback) {
callback.onStartDownloadHtml();
}
HtmlHelper.prepareHtmlFile(route.getHtmlFile(), new Callback() {
RouteManager.getInstance().refreshRouteFast(new RouteManager.RouteRefreshCallback() {
@Override
public void onFailure(Call call, IOException e) {
if (null != callback) {
RxLoadError error = RxLoadError.HTML_DOWNLOAD_FAIL;
error.extra = route.getHtmlFile();
callback.onFail(error);
public void onSuccess(String data) {
Route temp = page ? RouteManager.getInstance().findRoute(uri) : RouteManager.getInstance().findPartialRoute(uri);
if (null == temp) {
// 没有找到通知外面route找不到
if (null != callback) {
callback.onFail(RxLoadError.ROUTE_NOT_FOUND);
}
} else {
// 如果找到重新加载
loadUri(uri, callback, page);
}
}

@Override
public void onResponse(Call call, final Response response) throws IOException {
mMainHandler.post(new Runnable() {
@Override
public void run() {
if (response.isSuccessful()) {
LogUtils.i(TAG, "download success");
final CacheEntry cacheEntry = CacheHelper.getInstance().findHtmlCache(route.getHtmlFile());
if (null != cacheEntry && cacheEntry.isValid()) {
// show cache
doLoadCache(uri, route);
public void onFail() {
if (null != callback) {
callback.onFail(RxLoadError.ROUTE_NOT_FOUND);
}
}
});
} else {
if (null != callback) {
callback.onStartLoad();
}
if (CacheHelper.getInstance().cacheEnabled() && CacheHelper.getInstance().hasHtmlCached(route.getHtmlFile())) {
// show cache
doLoadCache(uri, route);
if (null != callback) {
callback.onSuccess();
}
} else {
if (null != callback) {
callback.onStartDownloadHtml();
}
HtmlHelper.prepareHtmlFile(route.getHtmlFile(), new Callback() {
@Override
public void onFailure(Call call, IOException e) {
if (null != callback) {
RxLoadError error = RxLoadError.HTML_DOWNLOAD_FAIL;
error.extra = route.getHtmlFile();
callback.onFail(error);
}
}

@Override
public void onResponse(Call call, final Response response) throws IOException {
mMainHandler.post(new Runnable() {
@Override
public void run() {
if (response.isSuccessful()) {
LogUtils.i(TAG, "download success");
final CacheEntry cacheEntry = CacheHelper.getInstance().findHtmlCache(route.getHtmlFile());
if (null != cacheEntry && cacheEntry.isValid()) {
// show cache
doLoadCache(uri, route);
if (null != callback) {
callback.onSuccess();
}
}
} else {
if (null != callback) {
callback.onSuccess();
RxLoadError error = RxLoadError.HTML_DOWNLOAD_FAIL;
error.extra = route.getHtmlFile();
callback.onFail(error);
}
}
} else {
if (null != callback) {
RxLoadError error = RxLoadError.HTML_DOWNLOAD_FAIL;
error.extra = route.getHtmlFile();
callback.onFail(error);
}
}
}
});
}
});
});
}
});
}
}
}

Expand Down

0 comments on commit bc1a695

Please sign in to comment.