diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2018-05-26 23:40:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-26 23:40:36 +0200 |
commit | cd0d23d2606c35d783457f2a945f539382018285 (patch) | |
tree | 698425901398b05c03906eaaa7ce0d6d4530c851 | |
parent | 39a462431fb291fe597f0edf93ce3548ec0a9ff2 (diff) | |
parent | 274230ad25cccb9f55305870a82f3ab4e02e7d63 (diff) | |
download | AntennaPod-cd0d23d2606c35d783457f2a945f539382018285.zip |
Merge pull request #2638 from ydinath/AboutActivityCleanup
About activity cleanup
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java | 59 | ||||
-rw-r--r-- | app/src/main/res/layout/about.xml | 4 |
2 files changed, 25 insertions, 38 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..4d9b50073 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -21,8 +21,7 @@ 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.Single; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -34,10 +33,8 @@ public class AboutActivity extends AppCompatActivity { private static final String TAG = AboutActivity.class.getSimpleName(); - private WebView webview; - private LinearLayout webviewContainer; - private int depth = 0; - + private WebView webView; + private LinearLayout webViewContainer; private Subscription subscription; @Override @@ -46,28 +43,25 @@ 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 >= 11 - && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { - webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + 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) { - if(url.startsWith("http")) { - depth++; - return false; - } else { + if (!url.startsWith("http")) { url = url.replace("file:///android_asset/", ""); loadAsset(url); return true; } + return false; } }); @@ -75,7 +69,7 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> { + subscription = Single.create(subscriber -> { InputStream input = null; try { TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( @@ -85,8 +79,7 @@ public class AboutActivity extends AppCompatActivity { res.recycle(); input = getAssets().open(filename); String webViewData = IOUtils.toString(input, Charset.defaultCharset()); - if(!webViewData.startsWith("<!DOCTYPE html>")) { - //webViewData = webViewData.replace("\n\n", "</p><p>"); + if (!webViewData.startsWith("<!DOCTYPE html>")) { webViewData = webViewData.replace("%", "%"); webViewData = "<!DOCTYPE html>" + @@ -106,35 +99,29 @@ public class AboutActivity extends AppCompatActivity { " </style>" + "</head><body><p>" + webViewData + "</p></body></html>"; webViewData = webViewData.replace("\n", "<br/>"); - depth++; - } else { - depth = 0; } webViewData = String.format(webViewData, colorString); - subscriber.onNext(webViewData); + subscriber.onSuccess(webViewData); } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); subscriber.onError(e); } finally { IOUtils.closeQuietly(input); } - subscriber.onCompleted(); }) .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", "file:///android_asset/" + filename.toString()), error -> Log.e(TAG, Log.getStackTraceString(error)) ); } @Override public void onBackPressed() { - Log.d(TAG, "depth: " + depth); - if(depth == 1) { - loadAsset("about.html"); - } else if(depth > 1) { - webview.goBack(); + if (webView.canGoBack()) { + webView.goBack(); } else { super.onBackPressed(); } @@ -156,9 +143,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 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/webvContainer" + android:id="@+id/webViewContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <WebView - android:id="@+id/webvAbout" + android:id="@+id/webViewAbout" android:layout_width="match_parent" android:layout_height="match_parent" /> |