Used pasted mime type

pull/212/head
M66B 2 years ago
parent ff7ebfaf37
commit 12aac56d81

@ -657,7 +657,11 @@ public class EditTextCompose extends FixedEditText {
(flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0)
info.requestPermission(); info.requestPermission();
inputContentListener.onInputContent(info.getContentUri()); String type = null;
if (info.getDescription().getMimeTypeCount() > 0)
type = info.getDescription().getMimeType(0);
inputContentListener.onInputContent(info.getContentUri(), type);
return true; return true;
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
@ -672,7 +676,7 @@ public class EditTextCompose extends FixedEditText {
} }
interface IInputContentListener { interface IInputContentListener {
void onInputContent(Uri uri); void onInputContent(Uri uri, String type);
} }
void setSelectionListener(ISelection listener) { void setSelectionListener(ISelection listener) {

@ -611,9 +611,9 @@ public class FragmentCompose extends FragmentBase {
etBody.setInputContentListener(new EditTextCompose.IInputContentListener() { etBody.setInputContentListener(new EditTextCompose.IInputContentListener() {
@Override @Override
public void onInputContent(Uri uri) { public void onInputContent(Uri uri, String type) {
Log.i("Received input uri=" + uri); Log.i("Received input uri=" + uri);
onAddAttachment(Arrays.asList(uri), true, 0, false, false); onAddAttachment(Arrays.asList(uri), type == null ? null : new String[]{type}, true, 0, false, false);
} }
}); });
@ -2828,7 +2828,7 @@ public class FragmentCompose extends FragmentBase {
case REQUEST_ATTACHMENT: case REQUEST_ATTACHMENT:
case REQUEST_RECORD_AUDIO: case REQUEST_RECORD_AUDIO:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
onAddAttachment(getUris(data), false, 0, false, false); onAddAttachment(getUris(data), null, false, 0, false, false);
break; break;
case REQUEST_OPENPGP: case REQUEST_OPENPGP:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
@ -3086,15 +3086,16 @@ public class FragmentCompose extends FragmentBase {
boolean resize_images = prefs.getBoolean("resize_images", true); boolean resize_images = prefs.getBoolean("resize_images", true);
boolean privacy_images = prefs.getBoolean("privacy_images", false); boolean privacy_images = prefs.getBoolean("privacy_images", false);
int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE);
onAddAttachment(uri, add_inline, resize_images ? resize : 0, privacy_images, focus); onAddAttachment(uri, null, add_inline, resize_images ? resize : 0, privacy_images, focus);
} }
private void onAddAttachment(List<Uri> uris, boolean image, int resize, boolean privacy, boolean focus) { private void onAddAttachment(List<Uri> uris, String[] types, boolean image, int resize, boolean privacy, boolean focus) {
etBody.clearComposingText(); etBody.clearComposingText();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", working); args.putLong("id", working);
args.putParcelableArrayList("uris", new ArrayList<>(uris)); args.putParcelableArrayList("uris", new ArrayList<>(uris));
args.putStringArray("types", types);
args.putBoolean("image", image); args.putBoolean("image", image);
args.putInt("resize", resize); args.putInt("resize", resize);
args.putInt("zoom", zoom); args.putInt("zoom", zoom);
@ -3108,6 +3109,7 @@ public class FragmentCompose extends FragmentBase {
protected Spanned onExecute(Context context, Bundle args) throws IOException { protected Spanned onExecute(Context context, Bundle args) throws IOException {
final long id = args.getLong("id"); final long id = args.getLong("id");
List<Uri> uris = args.getParcelableArrayList("uris"); List<Uri> uris = args.getParcelableArrayList("uris");
String[] types = args.getStringArray("types");
boolean image = args.getBoolean("image"); boolean image = args.getBoolean("image");
int resize = args.getInt("resize"); int resize = args.getInt("resize");
int zoom = args.getInt("zoom"); int zoom = args.getInt("zoom");
@ -3121,8 +3123,11 @@ public class FragmentCompose extends FragmentBase {
if (start > s.length()) if (start > s.length())
start = s.length(); start = s.length();
for (Uri uri : uris) { for (int i = 0; i < uris.size(); i++) {
EntityAttachment attachment = addAttachment(context, id, uri, image, resize, privacy); Uri uri = uris.get(i);
String type = (types != null && i < types.length ? types[i] : null);
EntityAttachment attachment = addAttachment(context, id, uri, type, image, resize, privacy);
if (attachment == null) if (attachment == null)
continue; continue;
if (!image) if (!image)
@ -3240,7 +3245,7 @@ public class FragmentCompose extends FragmentBase {
if (info.isImage()) if (info.isImage())
images.add(uri); images.add(uri);
else else
addAttachment(context, id, uri, false, 0, false); addAttachment(context, id, uri, null, false, 0, false);
} catch (IOException ex) { } catch (IOException ex) {
Log.e(ex); Log.e(ex);
} }
@ -4361,7 +4366,7 @@ public class FragmentCompose extends FragmentBase {
} }
private static EntityAttachment addAttachment( private static EntityAttachment addAttachment(
Context context, long id, Uri uri, boolean image, int resize, boolean privacy) throws IOException { Context context, long id, Uri uri, String type, boolean image, int resize, boolean privacy) throws IOException {
Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize + " privacy=" + privacy); Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize + " privacy=" + privacy);
NoStreamException.check(uri, context); NoStreamException.check(uri, context);
@ -4370,13 +4375,16 @@ public class FragmentCompose extends FragmentBase {
UriInfo info = getInfo(uri, context); UriInfo info = getInfo(uri, context);
EntityLog.log(context, "Add attachment" + EntityLog.log(context, "Add attachment" +
" uri=" + uri + " image=" + image + " resize=" + resize + " privacy=" + privacy + " uri=" + uri + " type=" + type + " image=" + image + " resize=" + resize + " privacy=" + privacy +
" name=" + info.name + " type=" + info.type + " size=" + info.size); " name=" + info.name + " type=" + info.type + " size=" + info.size);
if (type == null)
type = info.type;
String ext = Helper.getExtension(info.name); String ext = Helper.getExtension(info.name);
if (info.name != null && ext == null && info.type != null) { if (info.name != null && ext == null && type != null) {
String guessed = MimeTypeMap.getSingleton() String guessed = MimeTypeMap.getSingleton()
.getExtensionFromMimeType(info.type.toLowerCase(Locale.ROOT)); .getExtensionFromMimeType(type.toLowerCase(Locale.ROOT));
if (!TextUtils.isEmpty(guessed)) { if (!TextUtils.isEmpty(guessed)) {
ext = guessed; ext = guessed;
info.name += '.' + ext; info.name += '.' + ext;
@ -4399,7 +4407,7 @@ public class FragmentCompose extends FragmentBase {
attachment.name = "img" + attachment.sequence + (ext == null ? "" : "." + ext); attachment.name = "img" + attachment.sequence + (ext == null ? "" : "." + ext);
else else
attachment.name = info.name; attachment.name = info.name;
attachment.type = info.type; attachment.type = type;
attachment.disposition = (image ? Part.INLINE : Part.ATTACHMENT); attachment.disposition = (image ? Part.INLINE : Part.ATTACHMENT);
attachment.size = info.size; attachment.size = info.size;
attachment.progress = 0; attachment.progress = 0;
@ -5346,7 +5354,7 @@ public class FragmentCompose extends FragmentBase {
if (info.isImage()) if (info.isImage())
images.add(uri); images.add(uri);
else else
addAttachment(context, data.draft.id, uri, false, 0, false); addAttachment(context, data.draft.id, uri, null, false, 0, false);
} catch (IOException ex) { } catch (IOException ex) {
Log.e(ex); Log.e(ex);
} }

Loading…
Cancel
Save