1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Improve sharing to activity (Kepp one webview) #32

This commit is contained in:
Gregor Santner 2016-08-08 08:24:58 +02:00
parent d64a79dcf8
commit ebb6d36b7d
2 changed files with 18 additions and 38 deletions

View file

@ -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")

View file

@ -103,19 +103,15 @@ public class WebHelper {
public static void shareTextIntoWebView(final WebView webView, String sharedText){
sharedText = sharedText.replace("'", "'").replace("\"", """);
webView.loadUrl("javascript:(function() { " +
" document.documentElement.style.paddingBottom = '500px';" +
" if (typeof window.hasBeenSharedTo !== 'undefined') { AndroidBridge.contentHasBeenShared(); return; }" +
" var textbox = document.getElementsByTagName('textarea')[0];" +
" var textToBeShared = '" + sharedText + "';" +
" if (textbox) { " +
"document.getElementsByTagName('textarea')[0].style.height='110px'; " +
"document.getElementsByTagName('textarea')[0].innerHTML = '" + sharedText + "'; " +
" textbox.style.height='210px'; " +
" textbox.innerHTML = textToBeShared; " +
" 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\"));" +
" window.lastShared = textToBeShared;" +
" }" +
"})();");
}