From 00ace172fc7e3c36381a4b6766dde94b2f9c8606 Mon Sep 17 00:00:00 2001 From: heckler01 Date: Wed, 11 Apr 2018 19:16:08 -0400 Subject: Replace deprecated create((Observable.OnSubscribe) --- .../java/de/danoeh/antennapod/activity/AboutActivity.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 041053a25..e29f4f525 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -75,7 +75,7 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.create((Observable.OnSubscribe) subscriber -> { + subscription = Observable.fromCallable(()-> { InputStream input = null; try { TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( @@ -85,8 +85,7 @@ public class AboutActivity extends AppCompatActivity { res.recycle(); input = getAssets().open(filename); String webViewData = IOUtils.toString(input, Charset.defaultCharset()); - if(!webViewData.startsWith("")) { - //webViewData = webViewData.replace("\n\n", "

"); + if (!webViewData.startsWith("")) { webViewData = webViewData.replace("%", "%"); webViewData = "" + @@ -111,13 +110,13 @@ public class AboutActivity extends AppCompatActivity { depth = 0; } webViewData = String.format(webViewData, colorString); - subscriber.onNext(webViewData); + return webViewData; } catch (IOException e) { - subscriber.onError(e); + Log.e(TAG, Log.getStackTraceString(e)); + throw e; } finally { IOUtils.closeQuietly(input); } - subscriber.onCompleted(); }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) -- cgit v1.2.3 From b3d8a4c69f93b20ee0500695e5f9006f8ae3cbf0 Mon Sep 17 00:00:00 2001 From: heckler01 Date: Wed, 11 Apr 2018 20:49:21 -0400 Subject: Let webview handle if it can go back. When navigating the links, depth would increment, but never return to 0, and then get stuck on the about page. --- .../de/danoeh/antennapod/activity/AboutActivity.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index e29f4f525..c97463155 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -36,8 +36,6 @@ public class AboutActivity extends AppCompatActivity { private WebView webview; private LinearLayout webviewContainer; - private int depth = 0; - private Subscription subscription; @Override @@ -60,14 +58,12 @@ public class AboutActivity extends AppCompatActivity { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - if(url.startsWith("http")) { - depth++; - return false; - } else { + if (!url.startsWith("http")) { url = url.replace("file:///android_asset/", ""); loadAsset(url); return true; } + return false; } }); @@ -105,9 +101,6 @@ public class AboutActivity extends AppCompatActivity { " " + "

" + webViewData + "

"; webViewData = webViewData.replace("\n", "
"); - depth++; - } else { - depth = 0; } webViewData = String.format(webViewData, colorString); return webViewData; @@ -129,10 +122,7 @@ public class AboutActivity extends AppCompatActivity { @Override public void onBackPressed() { - Log.d(TAG, "depth: " + depth); - if(depth == 1) { - loadAsset("about.html"); - } else if(depth > 1) { + if (webview.canGoBack()) { webview.goBack(); } else { super.onBackPressed(); -- cgit v1.2.3 From 4c014bd3e34adb992b8ff40dfb047a24c28b4729 Mon Sep 17 00:00:00 2001 From: heckler01 Date: Wed, 11 Apr 2018 20:50:03 -0400 Subject: Remove unnecessary version check --- app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index c97463155..c0bdc7722 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -48,8 +48,7 @@ public class AboutActivity extends AppCompatActivity { webview = (WebView) findViewById(R.id.webvAbout); webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) { - if (Build.VERSION.SDK_INT >= 11 - && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } webview.setBackgroundColor(Color.TRANSPARENT); -- cgit v1.2.3 From 0499ef60ac7122dfad8c1579327c72eaca37cde9 Mon Sep 17 00:00:00 2001 From: heckler01 Date: Wed, 11 Apr 2018 21:04:52 -0400 Subject: Fix typos --- .../danoeh/antennapod/activity/AboutActivity.java | 28 +++++++++++----------- app/src/main/res/layout/about.xml | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index c0bdc7722..eed4de86f 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -34,8 +34,8 @@ public class AboutActivity extends AppCompatActivity { private static final String TAG = AboutActivity.class.getSimpleName(); - private WebView webview; - private LinearLayout webviewContainer; + private WebView webView; + private LinearLayout webViewContainer; private Subscription subscription; @Override @@ -44,16 +44,16 @@ public class AboutActivity extends AppCompatActivity { super.onCreate(savedInstanceState); getSupportActionBar().setDisplayShowHomeEnabled(true); setContentView(R.layout.about); - webviewContainer = (LinearLayout) findViewById(R.id.webvContainer); - webview = (WebView) findViewById(R.id.webvAbout); - webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); + webViewContainer = (LinearLayout) findViewById(R.id.webViewContainer); + webView = (WebView) findViewById(R.id.webViewAbout); + webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { - webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } - webview.setBackgroundColor(Color.TRANSPARENT); + webView.setBackgroundColor(Color.TRANSPARENT); } - webview.setWebViewClient(new WebViewClient() { + webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { @@ -114,15 +114,15 @@ public class AboutActivity extends AppCompatActivity { .observeOn(AndroidSchedulers.mainThread()) .subscribe( webviewData -> - webview.loadDataWithBaseURL("file:///android_asset/", webviewData, "text/html", "utf-8", "about:blank"), + webView.loadDataWithBaseURL("file:///android_asset/", webviewData, "text/html", "utf-8", "about:blank"), error -> Log.e(TAG, Log.getStackTraceString(error)) ); } @Override public void onBackPressed() { - if (webview.canGoBack()) { - webview.goBack(); + if (webView.canGoBack()) { + webView.goBack(); } else { super.onBackPressed(); } @@ -144,9 +144,9 @@ public class AboutActivity extends AppCompatActivity { if(subscription != null) { subscription.unsubscribe(); } - if (webviewContainer != null && webview != null) { - webviewContainer.removeAllViews(); - webview.destroy(); + if (webViewContainer != null && webView != null) { + webViewContainer.removeAllViews(); + webView.destroy(); } } } diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml index 02e232d9a..42f5e1245 100644 --- a/app/src/main/res/layout/about.xml +++ b/app/src/main/res/layout/about.xml @@ -1,12 +1,12 @@ -- cgit v1.2.3 From 3e10e50741ab1bd82b8bc337f1a21b45fafe1772 Mon Sep 17 00:00:00 2001 From: heckler01 Date: Wed, 11 Apr 2018 21:05:36 -0400 Subject: Remove unncessary inport --- app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index eed4de86f..d39c882f8 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -22,7 +22,6 @@ import java.nio.charset.Charset; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import rx.Observable; -import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; -- cgit v1.2.3 From fd13603be6f4f2092f4bacfab6a59fc8471fc0bb Mon Sep 17 00:00:00 2001 From: ydinath Date: Fri, 13 Apr 2018 14:23:11 -0400 Subject: Use single instead of fromCallable --- .../java/de/danoeh/antennapod/activity/AboutActivity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index d39c882f8..fed22d896 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -21,7 +21,7 @@ import java.nio.charset.Charset; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; -import rx.Observable; +import rx.Single; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -69,7 +69,7 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.fromCallable(()-> { + subscription = Single.create(subscriber -> { InputStream input = null; try { TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( @@ -101,10 +101,10 @@ public class AboutActivity extends AppCompatActivity { webViewData = webViewData.replace("\n", "
"); } webViewData = String.format(webViewData, colorString); - return webViewData; + subscriber.onSuccess(webViewData); } catch (IOException e) { Log.e(TAG, Log.getStackTraceString(e)); - throw e; + subscriber.onError(e); } finally { IOUtils.closeQuietly(input); } @@ -112,8 +112,8 @@ public class AboutActivity extends AppCompatActivity { .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( - webviewData -> - webView.loadDataWithBaseURL("file:///android_asset/", webviewData, "text/html", "utf-8", "about:blank"), + webViewData -> + webView.loadDataWithBaseURL("file:///android_asset/", webViewData.toString(), "text/html", "utf-8", "about:blank"), error -> Log.e(TAG, Log.getStackTraceString(error)) ); } -- cgit v1.2.3 From 921665167f50f85683cdd7154e62fc48841687c1 Mon Sep 17 00:00:00 2001 From: ydinath Date: Mon, 23 Apr 2018 20:23:39 -0400 Subject: canGoBack doesn't work consistently when using loadDataWithBaseURL. Update old logic to allow depth > 1. https://stackoverflow.com/questions/2686933/android-webview-can-render-html-going-forward-but-not-backward https://stackoverflow.com/questions/14948652/webview-cangoback-not-working-when-using-loaddatawithbaseurl/15074071#15074071 --- .../main/java/de/danoeh/antennapod/activity/AboutActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index fed22d896..443f4257f 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -36,6 +36,7 @@ public class AboutActivity extends AppCompatActivity { private WebView webView; private LinearLayout webViewContainer; private Subscription subscription; + private int depth = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,6 +57,7 @@ public class AboutActivity extends AppCompatActivity { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + depth++; if (!url.startsWith("http")) { url = url.replace("file:///android_asset/", ""); loadAsset(url); @@ -100,6 +102,10 @@ public class AboutActivity extends AppCompatActivity { "

" + webViewData + "

"; webViewData = webViewData.replace("\n", "
"); } + else + { + depth = 0; + } webViewData = String.format(webViewData, colorString); subscriber.onSuccess(webViewData); } catch (IOException e) { @@ -120,8 +126,9 @@ public class AboutActivity extends AppCompatActivity { @Override public void onBackPressed() { - if (webView.canGoBack()) { + if (depth != 0) { webView.goBack(); + depth--; } else { super.onBackPressed(); } -- cgit v1.2.3 From bb5f4597442d061719b934ee31510aea8c1b5d9a Mon Sep 17 00:00:00 2001 From: ydinath Date: Tue, 24 Apr 2018 04:48:44 -0400 Subject: Respect coding standard --- app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 443f4257f..6715ecf97 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -101,9 +101,7 @@ public class AboutActivity extends AppCompatActivity { " " + "

" + webViewData + "

"; webViewData = webViewData.replace("\n", "
"); - } - else - { + } else { depth = 0; } webViewData = String.format(webViewData, colorString); -- cgit v1.2.3 From ce1f0620fec7edb96cb08b46a3713a12263e5c48 Mon Sep 17 00:00:00 2001 From: ydinath Date: Sat, 5 May 2018 17:35:43 -0400 Subject: Fix back press issue --- .../main/java/de/danoeh/antennapod/activity/AboutActivity.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 6715ecf97..b3418e7b2 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -36,7 +36,6 @@ public class AboutActivity extends AppCompatActivity { private WebView webView; private LinearLayout webViewContainer; private Subscription subscription; - private int depth = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -57,7 +56,6 @@ public class AboutActivity extends AppCompatActivity { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - depth++; if (!url.startsWith("http")) { url = url.replace("file:///android_asset/", ""); loadAsset(url); @@ -101,8 +99,6 @@ public class AboutActivity extends AppCompatActivity { " " + "

" + webViewData + "

"; webViewData = webViewData.replace("\n", "
"); - } else { - depth = 0; } webViewData = String.format(webViewData, colorString); subscriber.onSuccess(webViewData); @@ -117,16 +113,15 @@ public class AboutActivity extends AppCompatActivity { .observeOn(AndroidSchedulers.mainThread()) .subscribe( webViewData -> - webView.loadDataWithBaseURL("file:///android_asset/", webViewData.toString(), "text/html", "utf-8", "about:blank"), + webView.loadDataWithBaseURL("file:///android_asset/", webViewData.toString(), "text/html", "utf-8", "file:///android_asset/" + webViewData.toString()), error -> Log.e(TAG, Log.getStackTraceString(error)) ); } @Override public void onBackPressed() { - if (depth != 0) { + if (webView.canGoBack()) { webView.goBack(); - depth--; } else { super.onBackPressed(); } -- cgit v1.2.3 From 274230ad25cccb9f55305870a82f3ab4e02e7d63 Mon Sep 17 00:00:00 2001 From: ydinath Date: Sat, 5 May 2018 18:07:51 -0400 Subject: Use filename instead --- app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index b3418e7b2..4d9b50073 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -113,7 +113,7 @@ public class AboutActivity extends AppCompatActivity { .observeOn(AndroidSchedulers.mainThread()) .subscribe( webViewData -> - webView.loadDataWithBaseURL("file:///android_asset/", webViewData.toString(), "text/html", "utf-8", "file:///android_asset/" + webViewData.toString()), + webView.loadDataWithBaseURL("file:///android_asset/", webViewData.toString(), "text/html", "utf-8", "file:///android_asset/" + filename.toString()), error -> Log.e(TAG, Log.getStackTraceString(error)) ); } -- cgit v1.2.3