Skip to content

Commit

Permalink
NativeGallery tries to preserve the file extension while picking mult…
Browse files Browse the repository at this point in the history
…iple images on Android
  • Loading branch information
yasirkula committed Apr 6, 2020
1 parent 8c8139a commit cd61316
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions JAR Source/NativeGalleryMediaPickerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class NativeGalleryMediaPickerFragment extends Fragment
public static final String TITLE_ID = "NGMP_TITLE";

public static boolean preferGetContent = false;
public static boolean tryPreserveFilenames = false;
public static boolean tryPreserveFilenames = false; // When enabled, app's cache will fill more quickly since most of the images will have a unique filename (less chance of overwriting old files)

private final NativeGalleryMediaReceiver mediaReceiver;
private boolean selectMultiple;
Expand Down Expand Up @@ -325,14 +325,27 @@ private String copyToTempFile( Uri uri )
if( filename == null || filename.length() < 3 )
filename = "temp";

String extension;
String extension = null;
String mime = resolver.getType( uri );
if( mime != null )
extension = "." + MimeTypeMap.getSingleton().getExtensionFromMimeType( mime );
else
extension = ".tmp";
{
String mimeExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType( mime );
if( mimeExtension != null && mimeExtension.length() > 0 )
extension = "." + mimeExtension;
}

if( extension == null )
{
int filenameExtensionIndex = filename.lastIndexOf( '.' );
if( filenameExtensionIndex > 0 && filenameExtensionIndex < filename.length() - 1 )
extension = filename.substring( filenameExtensionIndex );
else
extension = ".tmp";
}

if( filename.endsWith( extension ) )
if( !tryPreserveFilenames )
filename = savePathFilename;
else if( filename.endsWith( extension ) )
filename = filename.substring( 0, filename.length() - extension.length() );

try
Expand All @@ -341,7 +354,7 @@ private String copyToTempFile( Uri uri )
if( input == null )
return null;

String fullName = tryPreserveFilenames ? filename : savePathFilename + extension;
String fullName = filename + extension;
if( savedFiles != null )
{
int n = 1;
Expand Down
Binary file modified Plugins/NativeGallery/Android/NativeGallery.jar
Binary file not shown.

0 comments on commit cd61316

Please sign in to comment.