Fix issue #351 - Issues when sharing

This commit is contained in:
Thomas 2022-10-17 15:46:05 +02:00
parent 9ceb991758
commit 2ebcdaf330
3 changed files with 29 additions and 21 deletions

View File

@ -383,9 +383,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} }
// If we actually have a URL then make use of it. // If we actually have a URL then make use of it.
if (potentialUrl != null && potentialUrl.length() > 0) { if (potentialUrl != null && potentialUrl.length() > 0) {
Pattern titlePattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:title[\"']\\s+content=[\"']([^>]*)[\"']"); Pattern titlePattern = Pattern.compile("<meta [^>]*property=[\"']og:title[\"'] [^>]*content=[\"']([^'^\"]+?)[\"'][^>]*>");
Pattern descriptionPattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:description[\"']\\s+content=[\"']([^>]*)[\"']"); Pattern descriptionPattern = Pattern.compile("<meta [^>]*property=[\"']og:description[\"'] [^>]*content=[\"']([^'^\"]+?)[\"'][^>]*>");
Pattern imagePattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:image[\"']\\s+content=[\"']([^>]*)[\"']"); Pattern imagePattern = Pattern.compile("<meta [^>]*property=[\"']og:image[\"'] [^>]*content=[\"']([^'^\"]+?)[\"'][^>]*>");
try { try {
OkHttpClient client = new OkHttpClient.Builder() OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS) .connectTimeout(10, TimeUnit.SECONDS)
@ -440,6 +441,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
String finalImage = image; String finalImage = image;
String finalTitle = title; String finalTitle = title;
String finalDescription = description; String finalDescription = description;
runOnUiThread(() -> { runOnUiThread(() -> {
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString(Helper.ARG_SHARE_URL, url[0]); b.putString(Helper.ARG_SHARE_URL, url[0]);

View File

@ -508,7 +508,12 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
shareURL = b.getString(Helper.ARG_SHARE_URL, null); shareURL = b.getString(Helper.ARG_SHARE_URL, null);
} }
if (sharedContent != null && shareURL != null && sharedContent.compareTo(shareURL) == 0) {
sharedContent = "";
}
if (sharedTitle != null && sharedSubject != null && sharedSubject.length() > sharedTitle.length()) {
sharedTitle = sharedSubject;
}
binding.toolbar.setPopupTheme(Helper.popupStyle()); binding.toolbar.setPopupTheme(Helper.popupStyle());
//Edit a scheduled status from server //Edit a scheduled status from server
if (scheduledStatus != null) { if (scheduledStatus != null) {
@ -698,6 +703,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() { Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() {
@Override @Override
public void onDownloaded(String saveFilePath, String downloadUrl, Error error) { public void onDownloaded(String saveFilePath, String downloadUrl, Error error) {
composeAdapter.addSharing(shareURL, sharedTitle, sharedDescription, sharedSubject, sharedContent, saveFilePath); composeAdapter.addSharing(shareURL, sharedTitle, sharedDescription, sharedSubject, sharedContent, saveFilePath);
} }

View File

@ -419,26 +419,25 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
* @param content - String content (description) coming from the shared elements * @param content - String content (description) coming from the shared elements
*/ */
public void addSharing(String url, String title, String description, String subject, String content, String saveFilePath) { public void addSharing(String url, String title, String description, String subject, String content, String saveFilePath) {
int position = statusList.size() - 1; int position = statusList.size() - 1;
if (description == null && content == null) { statusList.get(position).text = "";
return; if (title != null && title.trim().length() > 0) {
statusList.get(position).text += title + "\n\n";
} else if (subject != null && subject.trim().length() > 0) {
statusList.get(position).text += subject + "\n\n";
} }
boolean addUrl = true; if (description != null && description.trim().length() > 0) {
if (url != null && content != null && content.trim().length() > url.trim().length()) { statusList.get(position).text += description + "\n\n";
statusList.get(position).text = content; if (!description.contains(url)) {
statusList.get(position).text += "\n\n"; statusList.get(position).text += url;
addUrl = false;
} else {
if (title != null || subject != null) {
statusList.get(position).text = title != null ? title : subject;
statusList.get(position).text += "\n\n";
} else {
statusList.get(position).text = "";
} }
} } else if (content != null && content.trim().length() > 0) {
statusList.get(position).text += description != null ? description : content; statusList.get(position).text += content + "\n\n";
if (url != null && addUrl) { if (!content.contains(url)) {
statusList.get(position).text += "\n\n"; statusList.get(position).text += url;
}
} else {
statusList.get(position).text += url; statusList.get(position).text += url;
} }
if (saveFilePath != null) { if (saveFilePath != null) {