Comment issue #276 - Fix crashes when sharing only text

This commit is contained in:
Thomas 2022-07-25 15:50:17 +02:00
parent d7bd889d35
commit 7f48b03781
3 changed files with 120 additions and 102 deletions

View file

@ -308,6 +308,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (matchStart < matchEnd && sharedText.length() >= matchEnd)
url[0] = sharedText.substring(matchStart, matchEnd);
}
if (url[0] != null) {
new Thread(() -> {
if (url[0].startsWith("www."))
url[0] = "http://" + url[0];
@ -400,6 +401,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}
}).start();
} else {
Bundle b = new Bundle();
b.putString(Helper.ARG_SHARE_TITLE, sharedSubject);
b.putString(Helper.ARG_SHARE_DESCRIPTION, sharedText);
CrossActionHelper.doCrossShare(BaseMainActivity.this, b);
}
}
} else if (type.startsWith("image/") || type.startsWith("video/")) {

View file

@ -385,6 +385,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
}
});
} else {
composeAdapter.addSharing(null, null, sharedDescription, null, sharedContent, null);
}
}

View file

@ -411,11 +411,18 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
*/
public void addSharing(String url, String title, String description, String subject, String content, String saveFilePath) {
int position = statusList.size() - 1;
if (title != null || subject != null) {
statusList.get(position).text = title != null ? title : subject;
statusList.get(position).text += "\n\n";
} else {
statusList.get(position).text = "";
}
statusList.get(position).text += description != null ? description : content;
statusList.get(position).text += "\n\n";
if (url != null) {
statusList.get(position).text += url;
}
if (saveFilePath != null) {
Attachment attachment = new Attachment();
attachment.mimeType = "image/*";
String extension = "jpg";
@ -427,6 +434,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
statusList.get(position).media_attachments = new ArrayList<>();
}
statusList.get(position).media_attachments.add(attachment);
}
notifyItemChanged(position);
}