Skip to content

Commit

Permalink
improve file type detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Laux committed Jul 17, 2020
1 parent 462cad7 commit d21bee4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Version code **7**
- On long click on a image it redirect to a bot
- Save the progress on the page in rotations
- Add retro style
- improve file type detection logic

## 1.4.0
Version code **6**
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ private void handleIntent() {
try {
InputStream inputStream = getContentResolver().openInputStream(uri);
if (uri.getPath() != null) {
if (!uri.getPath().contains("zip")) {
String path = uri.getPath();
if (path.endsWith(".html.zip") || path.endsWith(".htmlzip")) {
// zip html mode
text = getStringFromZip(inputStream);
} else {
// load file into memory (html or markdown)
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
Expand All @@ -142,13 +146,10 @@ private void handleIntent() {
result.write(buffer, 0, length);
}
text = result.toString();
if (uri.getPath().contains("md")) {
if (path.endsWith(".md")) {
// markdown mode
isMarkdown = true;
}
} else {
// zip html mode
text = getStringFromZip(inputStream);
}
}
} catch (IOException e) {
Expand Down

0 comments on commit d21bee4

Please sign in to comment.