Skip to content

Commit 1047b06

Browse files
authored
Merge pull request #21 from RubenDavidPerezJimenez/master
version 1.5.1
2 parents 5c4f206 + 8fc0d12 commit 1047b06

File tree

3 files changed

+80
-90
lines changed

3 files changed

+80
-90
lines changed

Changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

33
## Unreleased
4+
## 1.5.1
5+
Version code **8**
6+
- Fixed some bugs in search
7+
- Fixed rotation on MD file not working
8+
- Removed on long click image to bot
49

510
## 1.5.0
611
Version code **7**

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
// don't go bellow 19, otherwise you may introduce web-view security risks
88
minSdkVersion 19
99
targetSdkVersion 28
10-
versionCode 7
11-
versionName "1.5.0"
10+
versionCode 8
11+
versionName "1.5.1"
1212
}
1313
signingConfigs {
1414

app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java

+73-88
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
import android.annotation.SuppressLint;
44
import android.app.Activity;
5-
import android.content.Intent;
65
import android.net.Uri;
76
import android.os.Bundle;
8-
import android.util.Log;
9-
import android.view.ContextMenu;
107
import android.view.Menu;
118
import android.view.View;
129
import android.view.inputmethod.EditorInfo;
@@ -21,31 +18,34 @@
2118
import java.io.ByteArrayOutputStream;
2219
import java.io.IOException;
2320
import java.io.InputStream;
24-
import java.util.Objects;
2521
import java.util.zip.ZipEntry;
2622
import java.util.zip.ZipInputStream;
2723

24+
import de.simonlaux.ziphtmlviewer.R;
25+
2826
public class OpenActivity extends Activity implements View.OnClickListener {
27+
private static final String MD_TEXT = "MD_TEXT";
2928
private static final String FIRST_TIME_INIT = "FirstTimeInit";
3029
private static final String IS_SEARCHING = "Searching";
31-
private static final String ONE_TIME = "OneTime";
32-
private static final String TITLEWEB = "TitleWeb";
30+
private static final String TITLE_WEB = "TitleWeb";
3331
private boolean firstTimeInit = true;
34-
private boolean isSearching = true;
35-
private boolean onetime = false;
32+
private boolean isSearching = false;
33+
private JsObject jsObject;
3634
private String titleWEB ="ZHV";
37-
35+
3836
@Override
3937
protected void onCreate(Bundle savedInstanceState) {
4038
super.onCreate(savedInstanceState);
41-
if (onetime) {
42-
Toast.makeText(this, R.string.image_click_explain, Toast.LENGTH_SHORT).show();
43-
}
4439
if (savedInstanceState != null) {
4540
firstTimeInit = savedInstanceState.getBoolean(FIRST_TIME_INIT, true);
4641
isSearching = savedInstanceState.getBoolean(IS_SEARCHING, false);
47-
onetime = savedInstanceState.getBoolean(ONE_TIME, false);
48-
titleWEB =savedInstanceState.getString(TITLEWEB, titleWEB);
42+
titleWEB =savedInstanceState.getString(TITLE_WEB, titleWEB);
43+
String text=savedInstanceState.getString(MD_TEXT,"");
44+
if(text==""){
45+
jsObject=new JsObject("",false);
46+
}else{
47+
jsObject=new JsObject(text,true);
48+
}
4949
}
5050
/*Don't hide the bar for use it
5151
try {
@@ -63,22 +63,32 @@ protected void onCreate(Bundle savedInstanceState) {
6363
this.setTitle(titleWEB);
6464
}
6565
}
66-
66+
6767
@SuppressLint("SetJavaScriptEnabled")
6868
public void configureWebView(WebView web) {
6969
WebSettings webSettings = web.getSettings();
7070
webSettings.setJavaScriptEnabled(true);
7171
webSettings.setSupportZoom(true);
7272
webSettings.setBuiltInZoomControls(true);
7373
webSettings.setDomStorageEnabled(true);
74+
web.addJavascriptInterface(jsObject, "zhv");
75+
web.setWebChromeClient(new WebChromeClient() {
76+
77+
@Override
78+
public void onReceivedTitle(WebView view, String title) {
79+
super.onReceivedTitle(view, title);
80+
OpenActivity.this.titleWEB = title;
81+
OpenActivity.this.setTitle(title);
82+
}
83+
});
7484
}
75-
85+
7686
@Override
7787
public boolean onCreateOptionsMenu(Menu menu) {
7888
getMenuInflater().inflate(R.menu.search_menu, menu);
7989
final SearchView searchView = (SearchView) menu.findItem(R.id.search_menu_item).getActionView();
8090
searchView.setIconifiedByDefault(true);
81-
searchView.setIconified(true);
91+
//searchView.setIconified(true);
8292
searchView.setImeOptions(EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS | EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT);
8393
searchView.setOnSearchClickListener(this);
8494
searchView.setSubmitButtonEnabled(true);
@@ -93,10 +103,10 @@ public boolean onClose() {
93103
@Override
94104
public boolean onQueryTextSubmit(String query) {
95105
WebView myWebView = findViewById(R.id.webview);
96-
myWebView.findAllAsync(query);
106+
myWebView.findNext(true);
97107
return false;
98108
}
99-
109+
100110
@Override
101111
public boolean onQueryTextChange(String newText) {
102112
WebView myWebView = findViewById(R.id.webview);
@@ -105,9 +115,9 @@ public boolean onQueryTextChange(String newText) {
105115
}
106116
});
107117
return super.onCreateOptionsMenu(menu);
108-
118+
109119
}
110-
120+
111121
@Override
112122
public void onBackPressed() {
113123
if (isSearching) {
@@ -119,9 +129,9 @@ public void onBackPressed() {
119129
} else {
120130
super.onBackPressed();
121131
}
122-
132+
123133
}
124-
134+
125135
private void handleIntent() {
126136
Uri uri = getIntent().getData();
127137
if (uri == null) {
@@ -155,91 +165,41 @@ private void handleIntent() {
155165
} catch (IOException e) {
156166
e.printStackTrace();
157167
}
158-
168+
159169
if (text == null) {
160170
tellUserThatCouldNotOpenFile();
161171
return;
162172
}
163-
173+
164174
WebView myWebView = findViewById(R.id.webview);
165-
175+
jsObject = new JsObject(text, isMarkdown);
166176
configureWebView(myWebView);
167-
168-
registerForContextMenu(myWebView);
169-
177+
170178
// myWebView.setWebContentsDebuggingEnabled(true);
171-
172-
final boolean isMarkdownReader = isMarkdown;
173-
final String contentText = text;
174-
class JsObject {
175-
@JavascriptInterface
176-
public int getVersion() {
177-
return BuildConfig.VERSION_CODE;
178-
}
179-
180-
@JavascriptInterface
181-
public String toString() {
182-
return "[ZippedHTMLViewer Object]";
183-
}
184-
185-
@JavascriptInterface
186-
public String getMarkdown() {
187-
if (isMarkdownReader) {
188-
return contentText;
189-
} else {
190-
return "";
191-
}
192-
}
193-
}
194-
myWebView.addJavascriptInterface(new JsObject(), "zhv");
195-
myWebView.setWebChromeClient(new WebChromeClient() {
196-
@Override
197-
public void onReceivedTitle(WebView view, String title) {
198-
super.onReceivedTitle(view, title);
199-
OpenActivity.this.titleWEB = title;
200-
OpenActivity.this.setTitle(title);
201-
}
202-
});
179+
203180
myWebView.loadData("", "text/html", null);
204-
if (isMarkdown) {
181+
if(isMarkdown){
205182
// markdown mode
206183
myWebView.loadUrl("file:///android_asset/markdown-reader.html");
207184
} else {
208185
// html mode
209-
myWebView.loadDataWithBaseURL("file://index.html", contentText, "text/html", null, null);
186+
myWebView.loadDataWithBaseURL("file://index.html", text, "text/html", null, null);
210187
}
211188
firstTimeInit = false;
212189
}
213-
214-
//on Long touch Not Seen Images send to bot
215-
@Override
216-
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
217-
super.onCreateContextMenu(menu, v, menuInfo);
218-
Log.d("TAG", "onCreateContextMenu: " + v.toString());
219-
WebView myWebView = findViewById(R.id.webview);
220-
WebView.HitTestResult hitTestResult = myWebView.getHitTestResult();
221-
if (hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE) {
222-
Intent intent = new Intent(Intent.ACTION_SEND);
223-
intent.putExtra(Intent.EXTRA_EMAIL, "");
224-
intent.putExtra(Intent.EXTRA_HTML_TEXT, "/web " + hitTestResult.getExtra());
225-
intent.putExtra(Intent.EXTRA_TEXT, "/web " + hitTestResult.getExtra());
226-
intent.setType("text/html");
227-
startActivity(Intent.createChooser(intent, getString(R.string.open_delta)));
228-
}
229-
}
230-
190+
231191
private void tellUserThatCouldNotOpenFile() {
232192
Toast.makeText(this, getString(R.string.could_not_open_file), Toast.LENGTH_SHORT).show();
233193
}
234-
194+
235195
public static String getStringFromZip(InputStream stream) throws IOException {
236196
ByteArrayOutputStream fout = new ByteArrayOutputStream();
237197
if (!unpackZip(stream, fout)) {
238198
throw new IOException();
239199
}
240200
return fout.toString();
241201
}
242-
202+
243203
private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
244204
ZipInputStream zis;
245205
try {
@@ -250,9 +210,10 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
250210
while ((ze = zis.getNextEntry()) != null) {
251211
if (ze.isDirectory())
252212
continue;
253-
if (!Objects.equals(ze.getName(), "index.html"))
213+
//Objects esta del api 19 en adelante
214+
if (!ze.getName().contentEquals("index.html"))
254215
continue;
255-
216+
256217
while ((count = zis.read(buffer)) != -1) {
257218
fout.write(buffer, 0, count);
258219
}
@@ -265,19 +226,43 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
265226
}
266227
return true;
267228
}
268-
229+
269230
@Override
270231
protected void onSaveInstanceState(Bundle outState) {
271232
WebView myWebView = findViewById(R.id.webview);
272233
myWebView.saveState(outState);
273234
outState.putBoolean(IS_SEARCHING, isSearching);
274235
outState.putBoolean(FIRST_TIME_INIT, firstTimeInit);
275-
outState.putString(TITLEWEB,titleWEB);
236+
outState.putString(TITLE_WEB,titleWEB);
237+
outState.putString(MD_TEXT,jsObject.getMarkdown());
276238
super.onSaveInstanceState(outState);
277239
}
278-
240+
279241
@Override
280242
public void onClick(View v) {
281243
isSearching = true;
282244
}
245+
246+
247+
class JsObject {
248+
String contentText="";
249+
boolean isMarkdownReader=false;
250+
public JsObject(String contentText,boolean isMarkdownReader){
251+
this.contentText=contentText;
252+
this.isMarkdownReader=isMarkdownReader;
253+
}
254+
255+
@JavascriptInterface
256+
public int getVersion() { return BuildConfig.VERSION_CODE; }
257+
@JavascriptInterface
258+
public String toString() { return "[ZippedHTMLViewer Object]"; }
259+
@JavascriptInterface
260+
public String getMarkdown() {
261+
if(isMarkdownReader){
262+
return contentText;
263+
} else {
264+
return "";
265+
}
266+
}
267+
}
283268
}

0 commit comments

Comments
 (0)