From bc1a6952935fb6121d38629c6eb18cb201c933e4 Mon Sep 17 00:00:00 2001 From: luanqian Date: Thu, 16 Jan 2020 15:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93uri=E6=97=A0=E6=B3=95=E6=89=93?= =?UTF-8?q?=E5=BC=80=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8Croute=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E7=AB=8B=E5=8D=B3=E7=94=9F=E6=95=88=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=AD=89html=E5=8A=A0=E8=BD=BD=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/gradle.properties | 2 +- .../com/douban/rexxar/route/RouteManager.java | 4 +- .../douban/rexxar/view/RexxarWebViewCore.java | 111 ++++++++++-------- 3 files changed, 67 insertions(+), 50 deletions(-) diff --git a/core/gradle.properties b/core/gradle.properties index 0790c27..741ae0b 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -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 diff --git a/core/src/main/java/com/douban/rexxar/route/RouteManager.java b/core/src/main/java/com/douban/rexxar/route/RouteManager.java index 138c424..b878fd1 100644 --- a/core/src/main/java/com/douban/rexxar/route/RouteManager.java +++ b/core/src/main/java/com/douban/rexxar/route/RouteManager.java @@ -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() { }.getType()); @@ -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)); diff --git a/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java b/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java index 536defb..96922c4 100644 --- a/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java +++ b/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java @@ -298,7 +298,7 @@ public void loadPartialUri(String uri, UriLoadCallback callback) { *

* 如果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"); @@ -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); - } } - } - }); - } - }); + }); + } + }); + } } }