From ebb6d36b7df53e3d38bd143da181347dbed57a5d Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Mon, 8 Aug 2016 08:24:58 +0200 Subject: [PATCH] Improve sharing to activity (Kepp one webview) #32 --- .../activity/MainActivity.java | 34 +++++-------------- .../dfa/diaspora_android/util/WebHelper.java | 22 +++++------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index 0f5408a7..242e6fbc 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -853,7 +853,9 @@ public class MainActivity extends AppCompatActivity if (sharedText != null) { textToBeShared = sharedText; } + webView.stopLoading(); + webView.loadUrl("about:blank"); webView.loadUrl("https://"+podDomain+"/status_messages/new"); } @@ -873,34 +875,11 @@ public class MainActivity extends AppCompatActivity final String sharedSubject = WebHelper.escapeHtmlText(subject); final String sharedContent = WebHelper.escapeHtmlText(content); - final String sharedText = "**" + sharedSubject + "** " + sharedContent; + textToBeShared = "**" + sharedSubject + "** " + sharedContent; - if (sharedText != null) { - textToBeShared = sharedText; - } webView.stopLoading(); + webView.loadUrl("about:blank"); webView.loadUrl("https://"+podDomain+"/status_messages/new"); - -/* - if (subject != null) { - webView.setWebViewClient(new WebViewClient() { - - public void onPageFinished(WebView view, String url) { - webView.loadUrl("javascript:(function() { " + - "document.getElementsByTagName('textarea')[0].style.height='110px'; " + - "document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedContent + "'; " + - " if(document.getElementById(\"main_nav\")) {" + - " document.getElementById(\"main_nav\").parentNode.removeChild(" + - " document.getElementById(\"main_nav\"));" + - " } else if (document.getElementById(\"main-nav\")) {" + - " document.getElementById(\"main-nav\").parentNode.removeChild(" + - " document.getElementById(\"main-nav\"));" + - " }" + - "})();"); - webView.setWebViewClient(webViewClient); - } - }); - }*/ } //TODO: Implement? @@ -948,6 +927,11 @@ public class MainActivity extends AppCompatActivity public void contentHasBeenShared(){ textToBeShared = null; } + + @JavascriptInterface + public void log(final String log){ + //Log.d(App.TAG, "[wv] " + log); + } } @SuppressWarnings("StatementWithEmptyBody") diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java index 1fd8ec2c..fb1d0c2b 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/WebHelper.java @@ -103,19 +103,15 @@ public class WebHelper { public static void shareTextIntoWebView(final WebView webView, String sharedText){ sharedText = sharedText.replace("'", "'").replace("\"", """); webView.loadUrl("javascript:(function() { " + - "if (typeof window.hasBeenSharedTo !== 'undefined') { AndroidBridge.contentHasBeenShared(); return; }" + - "var textbox = document.getElementsByTagName('textarea')[0];" + - "if (textbox) { " + - "document.getElementsByTagName('textarea')[0].style.height='110px'; " + - "document.getElementsByTagName('textarea')[0].innerHTML = '" + sharedText + "'; " + - "window.hasBeenSharedTo = true;" + - "}" + - " if(document.getElementById(\"main_nav\")) {" + - " document.getElementById(\"main_nav\").parentNode.removeChild(" + - " document.getElementById(\"main_nav\"));" + - " } else if (document.getElementById(\"main-nav\")) {" + - " document.getElementById(\"main-nav\").parentNode.removeChild(" + - " document.getElementById(\"main-nav\"));" + + " document.documentElement.style.paddingBottom = '500px';" + + " if (typeof window.hasBeenSharedTo !== 'undefined') { AndroidBridge.contentHasBeenShared(); return; }" + + " var textbox = document.getElementsByTagName('textarea')[0];" + + " var textToBeShared = '" + sharedText + "';" + + " if (textbox) { " + + " textbox.style.height='210px'; " + + " textbox.innerHTML = textToBeShared; " + + " window.hasBeenSharedTo = true;" + + " window.lastShared = textToBeShared;" + " }" + "})();"); }