Skip to content

Commit

Permalink
Merge pull request #21 from RubenDavidPerezJimenez/master
Browse files Browse the repository at this point in the history
version 1.5.1
  • Loading branch information
Simon-Laux authored Sep 15, 2020
2 parents 5c4f206 + 8fc0d12 commit 1047b06
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 90 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## Unreleased
## 1.5.1
Version code **8**
- Fixed some bugs in search
- Fixed rotation on MD file not working
- Removed on long click image to bot

## 1.5.0
Version code **7**
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
// don't go bellow 19, otherwise you may introduce web-view security risks
minSdkVersion 19
targetSdkVersion 28
versionCode 7
versionName "1.5.0"
versionCode 8
versionName "1.5.1"
}
signingConfigs {

Expand Down
161 changes: 73 additions & 88 deletions app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.EditorInfo;
Expand All @@ -21,31 +18,34 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import de.simonlaux.ziphtmlviewer.R;

public class OpenActivity extends Activity implements View.OnClickListener {
private static final String MD_TEXT = "MD_TEXT";
private static final String FIRST_TIME_INIT = "FirstTimeInit";
private static final String IS_SEARCHING = "Searching";
private static final String ONE_TIME = "OneTime";
private static final String TITLEWEB = "TitleWeb";
private static final String TITLE_WEB = "TitleWeb";
private boolean firstTimeInit = true;
private boolean isSearching = true;
private boolean onetime = false;
private boolean isSearching = false;
private JsObject jsObject;
private String titleWEB ="ZHV";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (onetime) {
Toast.makeText(this, R.string.image_click_explain, Toast.LENGTH_SHORT).show();
}
if (savedInstanceState != null) {
firstTimeInit = savedInstanceState.getBoolean(FIRST_TIME_INIT, true);
isSearching = savedInstanceState.getBoolean(IS_SEARCHING, false);
onetime = savedInstanceState.getBoolean(ONE_TIME, false);
titleWEB =savedInstanceState.getString(TITLEWEB, titleWEB);
titleWEB =savedInstanceState.getString(TITLE_WEB, titleWEB);
String text=savedInstanceState.getString(MD_TEXT,"");
if(text==""){
jsObject=new JsObject("",false);
}else{
jsObject=new JsObject(text,true);
}
}
/*Don't hide the bar for use it
try {
Expand All @@ -63,22 +63,32 @@ protected void onCreate(Bundle savedInstanceState) {
this.setTitle(titleWEB);
}
}

@SuppressLint("SetJavaScriptEnabled")
public void configureWebView(WebView web) {
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
web.addJavascriptInterface(jsObject, "zhv");
web.setWebChromeClient(new WebChromeClient() {

@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
OpenActivity.this.titleWEB = title;
OpenActivity.this.setTitle(title);
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu, menu);
final SearchView searchView = (SearchView) menu.findItem(R.id.search_menu_item).getActionView();
searchView.setIconifiedByDefault(true);
searchView.setIconified(true);
//searchView.setIconified(true);
searchView.setImeOptions(EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS | EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT);
searchView.setOnSearchClickListener(this);
searchView.setSubmitButtonEnabled(true);
Expand All @@ -93,10 +103,10 @@ public boolean onClose() {
@Override
public boolean onQueryTextSubmit(String query) {
WebView myWebView = findViewById(R.id.webview);
myWebView.findAllAsync(query);
myWebView.findNext(true);
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
WebView myWebView = findViewById(R.id.webview);
Expand All @@ -105,9 +115,9 @@ public boolean onQueryTextChange(String newText) {
}
});
return super.onCreateOptionsMenu(menu);

}

@Override
public void onBackPressed() {
if (isSearching) {
Expand All @@ -119,9 +129,9 @@ public void onBackPressed() {
} else {
super.onBackPressed();
}

}

private void handleIntent() {
Uri uri = getIntent().getData();
if (uri == null) {
Expand Down Expand Up @@ -155,91 +165,41 @@ private void handleIntent() {
} catch (IOException e) {
e.printStackTrace();
}

if (text == null) {
tellUserThatCouldNotOpenFile();
return;
}

WebView myWebView = findViewById(R.id.webview);

jsObject = new JsObject(text, isMarkdown);
configureWebView(myWebView);

registerForContextMenu(myWebView);


// myWebView.setWebContentsDebuggingEnabled(true);

final boolean isMarkdownReader = isMarkdown;
final String contentText = text;
class JsObject {
@JavascriptInterface
public int getVersion() {
return BuildConfig.VERSION_CODE;
}

@JavascriptInterface
public String toString() {
return "[ZippedHTMLViewer Object]";
}

@JavascriptInterface
public String getMarkdown() {
if (isMarkdownReader) {
return contentText;
} else {
return "";
}
}
}
myWebView.addJavascriptInterface(new JsObject(), "zhv");
myWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
OpenActivity.this.titleWEB = title;
OpenActivity.this.setTitle(title);
}
});

myWebView.loadData("", "text/html", null);
if (isMarkdown) {
if(isMarkdown){
// markdown mode
myWebView.loadUrl("file:///android_asset/markdown-reader.html");
} else {
// html mode
myWebView.loadDataWithBaseURL("file://index.html", contentText, "text/html", null, null);
myWebView.loadDataWithBaseURL("file://index.html", text, "text/html", null, null);
}
firstTimeInit = false;
}

//on Long touch Not Seen Images send to bot
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
Log.d("TAG", "onCreateContextMenu: " + v.toString());
WebView myWebView = findViewById(R.id.webview);
WebView.HitTestResult hitTestResult = myWebView.getHitTestResult();
if (hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "");
intent.putExtra(Intent.EXTRA_HTML_TEXT, "/web " + hitTestResult.getExtra());
intent.putExtra(Intent.EXTRA_TEXT, "/web " + hitTestResult.getExtra());
intent.setType("text/html");
startActivity(Intent.createChooser(intent, getString(R.string.open_delta)));
}
}


private void tellUserThatCouldNotOpenFile() {
Toast.makeText(this, getString(R.string.could_not_open_file), Toast.LENGTH_SHORT).show();
}

public static String getStringFromZip(InputStream stream) throws IOException {
ByteArrayOutputStream fout = new ByteArrayOutputStream();
if (!unpackZip(stream, fout)) {
throw new IOException();
}
return fout.toString();
}

private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
ZipInputStream zis;
try {
Expand All @@ -250,9 +210,10 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
while ((ze = zis.getNextEntry()) != null) {
if (ze.isDirectory())
continue;
if (!Objects.equals(ze.getName(), "index.html"))
//Objects esta del api 19 en adelante
if (!ze.getName().contentEquals("index.html"))
continue;

while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
Expand All @@ -265,19 +226,43 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
}
return true;
}

@Override
protected void onSaveInstanceState(Bundle outState) {
WebView myWebView = findViewById(R.id.webview);
myWebView.saveState(outState);
outState.putBoolean(IS_SEARCHING, isSearching);
outState.putBoolean(FIRST_TIME_INIT, firstTimeInit);
outState.putString(TITLEWEB,titleWEB);
outState.putString(TITLE_WEB,titleWEB);
outState.putString(MD_TEXT,jsObject.getMarkdown());
super.onSaveInstanceState(outState);
}

@Override
public void onClick(View v) {
isSearching = true;
}


class JsObject {
String contentText="";
boolean isMarkdownReader=false;
public JsObject(String contentText,boolean isMarkdownReader){
this.contentText=contentText;
this.isMarkdownReader=isMarkdownReader;
}

@JavascriptInterface
public int getVersion() { return BuildConfig.VERSION_CODE; }
@JavascriptInterface
public String toString() { return "[ZippedHTMLViewer Object]"; }
@JavascriptInterface
public String getMarkdown() {
if(isMarkdownReader){
return contentText;
} else {
return "";
}
}
}
}

0 comments on commit 1047b06

Please sign in to comment.