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

Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2

This commit is contained in:
vanitasvitae 2016-09-22 23:20:13 +02:00
parent a1ca8596b8
commit 5c41c62c85
4 changed files with 46 additions and 21 deletions

View file

@ -53,7 +53,7 @@
<activity <activity
android:name=".activity.MainActivity" android:name=".activity.MainActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustResize"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar" android:theme="@style/AppTheme.NoActionBar"
android:label="@string/diaspora"> android:label="@string/diaspora">

View file

@ -134,6 +134,8 @@ public class MainActivity extends AppCompatActivity
private TextView navheaderDescription; private TextView navheaderDescription;
private ImageView navheaderImage; private ImageView navheaderImage;
private String textToBeShared;
/** /**
* END UI Bindings * END UI Bindings
@ -234,6 +236,7 @@ public class MainActivity extends AppCompatActivity
if(streamFragment == null) { if(streamFragment == null) {
AppLog.d(this, "StreamFragment was null"); AppLog.d(this, "StreamFragment was null");
streamFragment = new StreamFragment(); streamFragment = new StreamFragment();
fm.beginTransaction().add(streamFragment, StreamFragment.TAG).commit();
} }
return streamFragment; return streamFragment;
} }
@ -601,11 +604,10 @@ public class MainActivity extends AppCompatActivity
AppLog.v(this, "handleSendText()"); AppLog.v(this, "handleSendText()");
try { try {
setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT)); setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT));
openDiasporaUrl(urls.getNewPostUrl());
} catch (Exception e) { } catch (Exception e) {
AppLog.e(this, e.toString()); AppLog.e(this, e.toString());
} }
openDiasporaUrl(urls.getBlankUrl());
openDiasporaUrl(urls.getNewPostUrl());
} }
/** /**
@ -617,11 +619,10 @@ public class MainActivity extends AppCompatActivity
AppLog.v(this, "handleSendSubject()"); AppLog.v(this, "handleSendSubject()");
try { try {
setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT)); setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT));
openDiasporaUrl(urls.getNewPostUrl());
} catch (Exception e) { } catch (Exception e) {
AppLog.e(this, e.toString()); 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) { if (sharedSubject != null) {
AppLog.v(this, "Append subject to shared text"); AppLog.v(this, "Append subject to shared text");
String escapedSubject = WebHelper.escapeHtmlText(WebHelper.replaceUrlWithMarkdown(sharedSubject)); 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 { } else {
AppLog.v(this, "Set shared text; Subject: \"" + sharedSubject + "\" Body: \"" + sharedBody + "\""); 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); grantResults);
} }
} }
public String getTextToBeShared() {
return textToBeShared;
}
public void setTextToBeShared(String textToBeShared) {
this.textToBeShared = textToBeShared;
}
} }

View file

@ -52,7 +52,6 @@ public class StreamFragment extends WebViewFragment {
private ValueCallback<Uri[]> imageUploadFilePathCallbackNew; private ValueCallback<Uri[]> imageUploadFilePathCallbackNew;
private ValueCallback<Uri> imageUploadFilePathCallbackOld; private ValueCallback<Uri> imageUploadFilePathCallbackOld;
private String mCameraPhotoPath; private String mCameraPhotoPath;
protected String textToBeShared;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -76,11 +75,19 @@ public class StreamFragment extends WebViewFragment {
// Setup WebView // Setup WebView
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge"); 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()); loadUrl(urls.getPodUrl());
} }
this.setRetainInstance(true);
}
private void setWebChromeClient() {
//Set WebChromeClient //Set WebChromeClient
webView.setWebChromeClient(new WebChromeClient() { webView.setWebChromeClient(new WebChromeClient() {
final ProgressBar pb = progressBar; final ProgressBar pb = progressBar;
@ -96,6 +103,7 @@ public class StreamFragment extends WebViewFragment {
if (progress > 60) { if (progress > 60) {
WebHelper.optimizeMobileSiteLayout(wv); WebHelper.optimizeMobileSiteLayout(wv);
String textToBeShared = ((MainActivity)getActivity()).getTextToBeShared();
if (textToBeShared != null) { if (textToBeShared != null) {
AppLog.d(this, "Share text into webView"); AppLog.d(this, "Share text into webView");
WebHelper.shareTextIntoWebView(wv, textToBeShared); WebHelper.shareTextIntoWebView(wv, textToBeShared);
@ -110,7 +118,7 @@ public class StreamFragment extends WebViewFragment {
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
{ {
AppLog.v(this, "openFileChooser(ValCallback<Uri>, String, String"); AppLog.v(this, "openFileChooser(ValCallback<Uri>, String, String");
//imageUploadFilePathCallbackOld = uploadMsg; imageUploadFilePathCallbackOld = uploadMsg;
Intent intent = new Intent(); Intent intent = new Intent();
intent.setType("image/*"); intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT); intent.setAction(Intent.ACTION_GET_CONTENT);
@ -188,8 +196,6 @@ public class StreamFragment extends WebViewFragment {
return true; return true;
} }
}); });
this.setRetainInstance(true);
} }
@Override @Override
@ -273,10 +279,6 @@ public class StreamFragment extends WebViewFragment {
return this.webView; return this.webView;
} }
public void setTextToBeShared(String text) {
this.textToBeShared = text;
}
public void onImageUploadResult(int requestCode, int resultCode, Intent data) { public void onImageUploadResult(int requestCode, int resultCode, Intent data) {
AppLog.d(this, "onImageUploadResult"); AppLog.d(this, "onImageUploadResult");
switch (requestCode) { switch (requestCode) {
@ -359,7 +361,7 @@ public class StreamFragment extends WebViewFragment {
@JavascriptInterface @JavascriptInterface
public void contentHasBeenShared() { public void contentHasBeenShared() {
textToBeShared = null; ((MainActivity)getActivity()).setTextToBeShared(null);
} }
} }
} }

View file

@ -54,6 +54,8 @@ public abstract class WebViewFragment extends CustomFragment {
protected ProgressBar progressBar; protected ProgressBar progressBar;
protected AppSettings appSettings; protected AppSettings appSettings;
protected String pendingUrl;
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
} }
@ -279,18 +281,29 @@ public abstract class WebViewFragment extends CustomFragment {
} }
public void loadUrl(String url) { public void loadUrl(String url) {
AppLog.v(this, "loadUrl("+url+")"); if(getWebView() != null) {
AppLog.v(this, "loadUrl(): load "+url);
getWebView().loadUrlNew(url); getWebView().loadUrlNew(url);
} else {
AppLog.v(this, "loadUrl(): WebView null: Set pending url to "+url);
pendingUrl = url;
}
} }
public String getUrl() { public String getUrl() {
if(getWebView() != null) {
return getWebView().getUrl(); return getWebView().getUrl();
} else {
return pendingUrl;
}
} }
public void reloadUrl() { public void reloadUrl() {
AppLog.v(this, "reloadUrl()"); AppLog.v(this, "reloadUrl()");
if(getWebView() != null) {
getWebView().reload(); getWebView().reload();
} }
}
public ContextMenuWebView getWebView() { public ContextMenuWebView getWebView() {
return this.webView; return this.webView;