Skip to content

Commit

Permalink
feat: Support Drag Event in ChatActivityEnterView
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jul 29, 2024
1 parent 1bd254e commit cc69079
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import android.util.Property;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
Expand Down Expand Up @@ -5337,7 +5338,23 @@ public boolean onTextContextMenuItem(int id) {
return super.onTextContextMenuItem(id);
}

@Override
public boolean onDragEvent(DragEvent event) {
if (event.getAction() == DragEvent.ACTION_DROP) {
ClipData clipData = event.getClipData();
if (clipData != null && LaunchActivity.instance != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LaunchActivity.instance.requestDragAndDropPermissions(event);
if (clipData.getItemCount() == 1 && (clipData.getDescription().hasMimeType("image/*") || clipData.getDescription().hasMimeType("video/mp4")) && !isEditingBusinessLink()) {
editPhoto(clipData.getItemAt(0).getUri(), clipData.getDescription().getMimeType(0));
return true;
}
}
}
return super.onDragEvent(event);
}

private void editPhoto(Uri uri, String mime) {
boolean isVideo = mime.contains("video");
final File file = AndroidUtilities.generatePicturePath(parentFragment != null && parentFragment.isSecretChat(), MimeTypeMap.getSingleton().getExtensionFromMimeType(mime));
Utilities.globalQueue.postRunnable(() -> {
try {
Expand All @@ -5351,7 +5368,7 @@ private void editPhoto(Uri uri, String mime) {
}
in.close();
fos.close();
MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, -1, 0, file.getAbsolutePath(), 0, false, 0, 0, 0);
MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, -1, 0, file.getAbsolutePath(), 0, isVideo, 0, 0, 0);
ArrayList<Object> entries = new ArrayList<>();
entries.add(photoEntry);
AndroidUtilities.runOnUIThread(() -> {
Expand Down

0 comments on commit cc69079

Please sign in to comment.