Browse Source

shorten method

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 5 years ago
parent
commit
a6fdec8656
1 changed files with 35 additions and 29 deletions
  1. 35 29
      src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java

+ 35 - 29
src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java

@@ -93,7 +93,6 @@ public class ExternalSiteWebView extends FileActivity {
         webview.setFocusableInTouchMode(true);
         webview.setClickable(true);
 
-
         // allow debugging (when building the debug version); see details in
         // https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
@@ -114,17 +113,34 @@ public class ExternalSiteWebView extends FileActivity {
             setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
         }
 
-        ActionBar actionBar = getSupportActionBar();
-        if (actionBar != null) {
-            ThemeUtils.setColoredTitle(actionBar, title, this);
+        setupActionBar(title);
+        setupWebSettings(webSettings);
 
-            if (showSidebar) {
-                actionBar.setDisplayHomeAsUpEnabled(true);
-            } else {
-                setDrawerIndicatorEnabled(false);
-            }
+        final ProgressBar progressBar = findViewById(R.id.progressBar);
+
+        if (progressBar != null) {
+            webview.setWebChromeClient(new WebChromeClient() {
+                public void onProgressChanged(WebView view, int progress) {
+                    progressBar.setProgress(progress * 1000);
+                }
+            });
         }
 
+        webview.setWebViewClient(new WebViewClient() {
+            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
+                InputStream resources = getResources().openRawResource(R.raw.custom_error);
+                String customError = DisplayUtils.getData(resources);
+
+                if (!customError.isEmpty()) {
+                    webview.loadData(customError, "text/html; charset=UTF-8", null);
+                }
+            }
+        });
+
+        webview.loadUrl(url);
+    }
+
+    private void setupWebSettings(WebSettings webSettings) {
         // enable zoom
         webSettings.setSupportZoom(true);
         webSettings.setBuiltInZoomControls(true);
@@ -147,29 +163,19 @@ public class ExternalSiteWebView extends FileActivity {
         // enable javascript
         webSettings.setJavaScriptEnabled(true);
         webSettings.setDomStorageEnabled(true);
+    }
 
-        final ProgressBar progressBar = findViewById(R.id.progressBar);
-
-        if (progressBar != null) {
-            webview.setWebChromeClient(new WebChromeClient() {
-                public void onProgressChanged(WebView view, int progress) {
-                    progressBar.setProgress(progress * 1000);
-                }
-            });
-        }
-
-        webview.setWebViewClient(new WebViewClient() {
-            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
-                InputStream resources = getResources().openRawResource(R.raw.custom_error);
-                String customError = DisplayUtils.getData(resources);
+    private void setupActionBar(String title) {
+        ActionBar actionBar = getSupportActionBar();
+        if (actionBar != null) {
+            ThemeUtils.setColoredTitle(actionBar, title, this);
 
-                if (!customError.isEmpty()) {
-                    webview.loadData(customError, "text/html; charset=UTF-8", null);
-                }
+            if (showSidebar) {
+                actionBar.setDisplayHomeAsUpEnabled(true);
+            } else {
+                setDrawerIndicatorEnabled(false);
             }
-        });
-
-        webview.loadUrl(url);
+        }
     }
 
     @Override