From d21bee44f8635b5e366e05ba05098e10e056b36e Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Fri, 17 Jul 2020 19:15:50 +0200 Subject: [PATCH] improve file type detection logic --- Changelog.md | 1 + .../java/de/simonlaux/ziphtmlviewer/OpenActivity.java | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index 8db43cb..5a518ac 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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** diff --git a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java index 8ce06cb..216f725 100644 --- a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java +++ b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java @@ -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]; @@ -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) {