mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Add full send attachments.
This commit is contained in:
committed by
Cody Henthorne
parent
3879a8ffdb
commit
a966812bfc
@@ -51,6 +51,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MediaUtil {
|
||||
@@ -137,6 +138,35 @@ public class MediaUtil {
|
||||
return getCorrectedMimeType(type);
|
||||
}
|
||||
|
||||
public static @NonNull Optional<String> getFileType(@NonNull Context context, Optional<String> fileName, Uri uri) {
|
||||
if (fileName.isPresent()) {
|
||||
String fileType = getFileType(fileName);
|
||||
if (!fileType.isEmpty()) {
|
||||
return Optional.of(fileType);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.ofNullable(MediaUtil.getExtension(context, uri));
|
||||
}
|
||||
|
||||
private static @NonNull String getFileType(Optional<String> fileName) {
|
||||
if (!fileName.isPresent()) return "";
|
||||
|
||||
String[] parts = fileName.get().split("\\.");
|
||||
|
||||
if (parts.length < 2) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String suffix = parts[parts.length - 1];
|
||||
|
||||
if (suffix.length() <= 3) {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static @Nullable String getExtension(@NonNull Context context, @Nullable Uri uri) {
|
||||
return MimeTypeMap.getSingleton()
|
||||
.getExtensionFromMimeType(getMimeType(context, uri));
|
||||
@@ -384,6 +414,10 @@ public class MediaUtil {
|
||||
return OCTET.equals(contentType);
|
||||
}
|
||||
|
||||
public static boolean isDocumentType(String contentType) {
|
||||
return !isImageOrVideoType(contentType) && !isGif(contentType) && !isLongTextType(contentType) && !isViewOnceType(contentType);
|
||||
}
|
||||
|
||||
public static boolean hasVideoThumbnail(@NonNull Context context, @Nullable Uri uri) {
|
||||
if (uri == null) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user