mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +02:00
Fix issue #351 - Issues when sharing
This commit is contained in:
parent
9ceb991758
commit
2ebcdaf330
3 changed files with 29 additions and 21 deletions
|
@ -383,9 +383,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
}
|
||||
// If we actually have a URL then make use of it.
|
||||
if (potentialUrl != null && potentialUrl.length() > 0) {
|
||||
Pattern titlePattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:title[\"']\\s+content=[\"']([^>]*)[\"']");
|
||||
Pattern descriptionPattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:description[\"']\\s+content=[\"']([^>]*)[\"']");
|
||||
Pattern imagePattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:image[\"']\\s+content=[\"']([^>]*)[\"']");
|
||||
Pattern titlePattern = Pattern.compile("<meta [^>]*property=[\"']og:title[\"'] [^>]*content=[\"']([^'^\"]+?)[\"'][^>]*>");
|
||||
Pattern descriptionPattern = Pattern.compile("<meta [^>]*property=[\"']og:description[\"'] [^>]*content=[\"']([^'^\"]+?)[\"'][^>]*>");
|
||||
Pattern imagePattern = Pattern.compile("<meta [^>]*property=[\"']og:image[\"'] [^>]*content=[\"']([^'^\"]+?)[\"'][^>]*>");
|
||||
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
|
@ -440,6 +441,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
String finalImage = image;
|
||||
String finalTitle = title;
|
||||
String finalDescription = description;
|
||||
|
||||
|
||||
runOnUiThread(() -> {
|
||||
Bundle b = new Bundle();
|
||||
b.putString(Helper.ARG_SHARE_URL, url[0]);
|
||||
|
|
|
@ -508,7 +508,12 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
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());
|
||||
//Edit a scheduled status from server
|
||||
if (scheduledStatus != null) {
|
||||
|
@ -698,6 +703,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() {
|
||||
@Override
|
||||
public void onDownloaded(String saveFilePath, String downloadUrl, Error error) {
|
||||
|
||||
composeAdapter.addSharing(shareURL, sharedTitle, sharedDescription, sharedSubject, sharedContent, saveFilePath);
|
||||
}
|
||||
|
||||
|
|
|
@ -419,26 +419,25 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
* @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) {
|
||||
|
||||
int position = statusList.size() - 1;
|
||||
if (description == null && content == null) {
|
||||
return;
|
||||
statusList.get(position).text = "";
|
||||
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 (url != null && content != null && content.trim().length() > url.trim().length()) {
|
||||
statusList.get(position).text = content;
|
||||
statusList.get(position).text += "\n\n";
|
||||
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 = "";
|
||||
if (description != null && description.trim().length() > 0) {
|
||||
statusList.get(position).text += description + "\n\n";
|
||||
if (!description.contains(url)) {
|
||||
statusList.get(position).text += url;
|
||||
}
|
||||
}
|
||||
statusList.get(position).text += description != null ? description : content;
|
||||
if (url != null && addUrl) {
|
||||
statusList.get(position).text += "\n\n";
|
||||
} else if (content != null && content.trim().length() > 0) {
|
||||
statusList.get(position).text += content + "\n\n";
|
||||
if (!content.contains(url)) {
|
||||
statusList.get(position).text += url;
|
||||
}
|
||||
} else {
|
||||
statusList.get(position).text += url;
|
||||
}
|
||||
if (saveFilePath != null) {
|
||||
|
|
Loading…
Reference in a new issue