Skip to content

Commit

Permalink
fix: crash on share photo
Browse files Browse the repository at this point in the history
Signed-off-by: Next Alone <[email protected]>
  • Loading branch information
NextAlone committed Feb 1, 2024
1 parent 9d87bd4 commit 02cb969
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ public void run() {
private final static int OPTION_EDIT_SCHEDULE_TIME = 102;
private final static int OPTION_SPEED_PROMO = 103;
private final static int OPTION_OPEN_PROFILE = 104;
private final static int OPTION_SHARE_PHOTO = 105;

private final static int[] allowedNotificationsDuringChatListAnimations = new int[]{
NotificationCenter.messagesRead,
Expand Down Expand Up @@ -25815,7 +25816,7 @@ public void setAutoDeleteHistory(int time, int action) {
options.add(OPTION_SAVE_TO_GALLERY);
icons.add(R.drawable.msg_gallery);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(OPTION_SHARE);
options.add(OPTION_SHARE_PHOTO);
icons.add(R.drawable.msg_shareout);
if (ConfigManager.getBooleanOrFalse(Defines.showCopyPhoto)) {
items.add(LocaleController.getString("CopyPhoto", R.string.CopyPhoto));
Expand Down Expand Up @@ -26140,6 +26141,9 @@ public void setAutoDeleteHistory(int time, int action) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(OPTION_SAVE_TO_GALLERY);
icons.add(R.drawable.msg_gallery);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(OPTION_SHARE_PHOTO);
icons.add(R.drawable.msg_shareout);
}
} else if (type == 5) {
items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
Expand Down Expand Up @@ -28046,6 +28050,37 @@ private void processSelectedOption(int option) {
}
break;
}
case OPTION_SHARE_PHOTO: {
String path = selectedObject.messageOwner.attachPath;
if (path != null && path.length() > 0) {
File temp = new File(path);
if (!temp.exists()) {
path = null;
}
}
if (path == null || path.length() == 0) {
path = getFileLoader().getPathToMessage(selectedObject.messageOwner).toString();
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(selectedObject.isVideo() ? "video/mp4" : "image/jpeg");
File f = new File(path);
if (Build.VERSION.SDK_INT >= 24) {
try {
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getParentActivity(), ApplicationLoader.getApplicationId() + ".provider", f));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} catch (Exception ignore) {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
}
} else {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
}
try {
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
} catch (Throwable ignore) {

}
break;
}
case OPTION_SAVE_TO_GALLERY2: {
String path = selectedObject.messageOwner.attachPath;
if (path != null && path.length() > 0) {
Expand Down

0 comments on commit 02cb969

Please sign in to comment.