diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2ef6cc59..7b75d8d3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,7 +53,7 @@ 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 32e9c33e..c7e39fc1 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 @@ -134,6 +134,8 @@ public class MainActivity extends AppCompatActivity private TextView navheaderDescription; private ImageView navheaderImage; + private String textToBeShared; + /** * END UI Bindings @@ -234,6 +236,7 @@ public class MainActivity extends AppCompatActivity if(streamFragment == null) { AppLog.d(this, "StreamFragment was null"); streamFragment = new StreamFragment(); + fm.beginTransaction().add(streamFragment, StreamFragment.TAG).commit(); } return streamFragment; } @@ -601,11 +604,10 @@ public class MainActivity extends AppCompatActivity AppLog.v(this, "handleSendText()"); try { setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT)); + openDiasporaUrl(urls.getNewPostUrl()); } catch (Exception e) { AppLog.e(this, e.toString()); } - openDiasporaUrl(urls.getBlankUrl()); - openDiasporaUrl(urls.getNewPostUrl()); } /** @@ -617,11 +619,10 @@ public class MainActivity extends AppCompatActivity AppLog.v(this, "handleSendSubject()"); try { setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT)); + openDiasporaUrl(urls.getNewPostUrl()); } catch (Exception e) { AppLog.e(this, e.toString()); } - openDiasporaUrl(urls.getBlankUrl()); //TODO: Necessary? - openDiasporaUrl(urls.getNewPostUrl()); } /** @@ -645,10 +646,11 @@ public class MainActivity extends AppCompatActivity if (sharedSubject != null) { AppLog.v(this, "Append subject to shared text"); String escapedSubject = WebHelper.escapeHtmlText(WebHelper.replaceUrlWithMarkdown(sharedSubject)); - getStreamFragment().setTextToBeShared("**" + escapedSubject + "** " + escapedBody); + AppLog.v(this, "Set shared text; Subject: \"" + escapedSubject + "\" Body: \"" + escapedBody + "\""); + textToBeShared = "**" + escapedSubject + "** " + escapedBody; } else { AppLog.v(this, "Set shared text; Subject: \"" + sharedSubject + "\" Body: \"" + sharedBody + "\""); - getStreamFragment().setTextToBeShared(escapedBody); + textToBeShared = escapedBody; } } @@ -824,4 +826,12 @@ public class MainActivity extends AppCompatActivity grantResults); } } + + public String getTextToBeShared() { + return textToBeShared; + } + + public void setTextToBeShared(String textToBeShared) { + this.textToBeShared = textToBeShared; + } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/fragment/StreamFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/fragment/StreamFragment.java index 4f735b5c..90dba5f8 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/fragment/StreamFragment.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/fragment/StreamFragment.java @@ -52,7 +52,6 @@ public class StreamFragment extends WebViewFragment { private ValueCallback imageUploadFilePathCallbackNew; private ValueCallback imageUploadFilePathCallbackOld; private String mCameraPhotoPath; - protected String textToBeShared; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -76,11 +75,19 @@ public class StreamFragment extends WebViewFragment { // Setup WebView webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge"); + setWebChromeClient(); - if(webView.getUrl() == null) { + if(pendingUrl != null) { + loadUrl(pendingUrl); + pendingUrl = null; + } else if (webView.getUrl() == null) { loadUrl(urls.getPodUrl()); } + this.setRetainInstance(true); + } + + private void setWebChromeClient() { //Set WebChromeClient webView.setWebChromeClient(new WebChromeClient() { final ProgressBar pb = progressBar; @@ -96,6 +103,7 @@ public class StreamFragment extends WebViewFragment { if (progress > 60) { WebHelper.optimizeMobileSiteLayout(wv); + String textToBeShared = ((MainActivity)getActivity()).getTextToBeShared(); if (textToBeShared != null) { AppLog.d(this, "Share text into webView"); WebHelper.shareTextIntoWebView(wv, textToBeShared); @@ -110,7 +118,7 @@ public class StreamFragment extends WebViewFragment { protected void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { AppLog.v(this, "openFileChooser(ValCallback, String, String"); - //imageUploadFilePathCallbackOld = uploadMsg; + imageUploadFilePathCallbackOld = uploadMsg; Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); @@ -188,8 +196,6 @@ public class StreamFragment extends WebViewFragment { return true; } }); - - this.setRetainInstance(true); } @Override @@ -273,10 +279,6 @@ public class StreamFragment extends WebViewFragment { return this.webView; } - public void setTextToBeShared(String text) { - this.textToBeShared = text; - } - public void onImageUploadResult(int requestCode, int resultCode, Intent data) { AppLog.d(this, "onImageUploadResult"); switch (requestCode) { @@ -359,7 +361,7 @@ public class StreamFragment extends WebViewFragment { @JavascriptInterface public void contentHasBeenShared() { - textToBeShared = null; + ((MainActivity)getActivity()).setTextToBeShared(null); } } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/fragment/WebViewFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/fragment/WebViewFragment.java index 4f6b9bfb..7127e427 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/fragment/WebViewFragment.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/fragment/WebViewFragment.java @@ -54,6 +54,8 @@ public abstract class WebViewFragment extends CustomFragment { protected ProgressBar progressBar; protected AppSettings appSettings; + protected String pendingUrl; + public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @@ -279,17 +281,28 @@ public abstract class WebViewFragment extends CustomFragment { } public void loadUrl(String url) { - AppLog.v(this, "loadUrl("+url+")"); - getWebView().loadUrlNew(url); + if(getWebView() != null) { + AppLog.v(this, "loadUrl(): load "+url); + getWebView().loadUrlNew(url); + } else { + AppLog.v(this, "loadUrl(): WebView null: Set pending url to "+url); + pendingUrl = url; + } } public String getUrl() { - return getWebView().getUrl(); + if(getWebView() != null) { + return getWebView().getUrl(); + } else { + return pendingUrl; + } } public void reloadUrl() { AppLog.v(this, "reloadUrl()"); - getWebView().reload(); + if(getWebView() != null) { + getWebView().reload(); + } } public ContextMenuWebView getWebView() {