Skip to content

Commit 827ede7

Browse files
committed
fix chm reader activity %20
1 parent c8972b7 commit 827ede7

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

PowerFileExplorer/src/main/java/chm/cblink/nb/chmreader/CHMActivity.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import net.gnu.explorer.R;
4141
import org.jsoup.Jsoup;
4242
import org.jsoup.nodes.Document;
43+
import java.net.*;
4344

4445
public class CHMActivity extends AppCompatActivity {
4546
WebView webview;
@@ -57,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
5758
super.onCreate(savedInstanceState);
5859
setContentView(R.layout.activity_chm);
5960
Intent revIntent = getIntent();
60-
chmFilePath = revIntent.getDataString().substring("file://".length());//.getStringExtra("fileName");
61+
chmFilePath = URLDecoder.decode(revIntent.getDataString()).substring("file://".length());//.getStringExtra("fileName");
6162
Log.d(TAG, "chmFilePath " + chmFilePath);
6263
Utils.chm = null;
6364
listSite = new ArrayList<>();
@@ -148,7 +149,7 @@ private void handleIntent(Intent intent) {
148149
} catch (Exception ignored) {
149150
}
150151
} else {
151-
chmFilePath = intent.getDataString().substring("file://".length());//.getStringExtra("fileName");
152+
chmFilePath = URLDecoder.decode(intent.getDataString()).substring("file://".length());//.getStringExtra("fileName");
152153
Log.d(TAG, "chmFilePath " + chmFilePath);
153154
Utils.chm = null;
154155
listSite = new ArrayList<>();
@@ -168,7 +169,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
168169
webview.loadUrl("file://" + extractPath + "/" + listSite.get(0));
169170
break;
170171
case R.id.menu_back_page:
171-
temp = webview.getUrl().replaceAll("%20", " ").substring(("file://" + extractPath).length() + 1);
172+
temp = URLDecoder.decode(webview.getUrl()).substring(("file://" + extractPath).length() + 1);
172173
if (temp.contains("#")) {
173174
temp = temp.substring(0, temp.indexOf("#"));
174175
}
@@ -183,7 +184,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
183184
}
184185
break;
185186
case R.id.menu_next_page:
186-
temp = webview.getUrl().replaceAll("%20", " ").substring(("file://" + extractPath).length() + 1);
187+
temp = URLDecoder.decode(webview.getUrl()).substring(("file://" + extractPath).length() + 1);
187188
if (temp.contains("#")) {
188189
temp = temp.substring(0, temp.indexOf("#"));
189190
}
@@ -279,9 +280,9 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
279280
insideFileName = insideFileName.substring(0, insideFileName.indexOf("?"));
280281
}
281282
if (insideFileName.contains("%20")) {
282-
insideFileName = insideFileName.replaceAll("%20", " ");
283+
insideFileName = URLDecoder.decode(insideFileName);
283284
}
284-
if (url.endsWith(".gif") || url.endsWith(".jpg") || url.endsWith(".png")) {
285+
if (url.endsWith(".gif") || url.endsWith(".jpg") || url.endsWith(".jpeg") || url.endsWith(".bmp") || url.endsWith(".ico") || url.endsWith(".png")) {
285286
try {
286287
return new WebResourceResponse("image/*", "", Utils.chm.getResourceAsStream(insideFileName));
287288
} catch (IOException e) {
@@ -398,8 +399,12 @@ protected void onPostExecute(Void aVoid) {
398399
protected void onPause() {
399400
super.onPause();
400401
try {
402+
if (progress != null) {
403+
progress.dismiss();
404+
progress = null;
405+
}
401406
Utils.saveBookmark(extractPath, md5File, listBookmark);
402-
String url = webview.getUrl().replaceAll("%20", " ").substring(("file://" + extractPath).length() + 1);
407+
String url = URLDecoder.decode(webview.getUrl()).substring(("file://" + extractPath).length() + 1);
403408
int index = listSite.indexOf(url);
404409
if (index != -1) {
405410
Utils.saveHistory(extractPath, md5File, index);
@@ -447,7 +452,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
447452
public void onClick(View v) {
448453
switch (v.getId()) {
449454
case R.id.btn_addbookmark:
450-
String url = webview.getUrl().replaceAll("%20", " ").substring(("file://" + extractPath).length() + 1);
455+
String url = URLDecoder.decode(webview.getUrl()).substring(("file://" + extractPath).length() + 1);
451456
if (listBookmark.indexOf(url) == -1) {
452457
listBookmark.add(url);
453458
adapter.notifyDataSetChanged();

PowerFileExplorer/src/main/java/chm/cblink/nb/chmreader/lib/Utils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ public static String checkSum(String path) {
353353
byte[] hash = md.digest();
354354
checksum = new BigInteger(1, hash).toString(16); //don't use this, truncates leading zero
355355
} catch (IOException ex) {
356+
ex.printStackTrace();
356357
} catch (NoSuchAlgorithmException ex) {
358+
ex.printStackTrace();
357359
}
358360
return checksum.trim();
359361
}

0 commit comments

Comments
 (0)