Skip to content

Commit

Permalink
add mimeType-decoding for types not already recognized by rclone
Browse files Browse the repository at this point in the history
Signed-off-by: x0b <x0b@users.noreply.github.com>
  • Loading branch information
x0b committed Aug 25, 2019
1 parent 04bff90 commit be74d75
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/src/main/java/ca/pkay/rcloneexplorer/Items/FileItem.java
Expand Up @@ -3,6 +3,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateUtils;
import android.webkit.MimeTypeMap;

import java.text.DateFormat;
import java.text.ParseException;
Expand Down Expand Up @@ -32,7 +33,7 @@ public FileItem(RemoteItem remote, String path, String name, long size, String m
this.modTime = modTimeToMilis(modTime);
this.humanReadableModTime = modTimeToHumanReadable(modTime);
this.formattedModTime = modTimeToFormattedTime(modTime);
this.mimeType = mimeType;
this.mimeType = getMimeType(mimeType, path);
this.isDir = isDir;
}

Expand Down Expand Up @@ -98,6 +99,22 @@ public boolean isDir() {
return isDir;
}

private String getMimeType(String mimeType, String path) {
if ("application/octet-stream".equals(mimeType)) {
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
if ((extension == null || "".equals(extension)) && path.lastIndexOf('.') < path.length() + 1) {
extension = path.substring(path.lastIndexOf('.') + 1);
}
if (extension != null) {
String mimeQueryResult = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (null != mimeQueryResult) {
mimeType = mimeQueryResult;
}
}
}
return mimeType;
}

private String sizeToHumanReadable(long size) {
int unit = 1000;
if (size < unit) return size + " B";
Expand Down

0 comments on commit be74d75

Please sign in to comment.