Skip to content

Commit

Permalink
#2 #3: bugfix created illegal local file name for send/get_content
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Jun 4, 2019
1 parent 4d8c1bf commit ec1ac77
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ android {
applicationId "de.k3b.android.lossless_jpg_crop"

// SAF ACTION_CREATE_DOCUMENT requires api-19 and later
minSdkVersion 19
minSdkVersion 19 // Android 4.4 KitKat (API 19); Android 5.0 Lollipop (API 21); Android 6.0 Marshmallow (API 23); Android 7.0 Nougat (API 24)
targetSdkVersion 28

// 1.0.0.190425 (1) initial version
// 1.0.1.190507 (2) Bugfix: missing read permission; port to android-x
// 1.0.2.190515 (3) Bugfix: rotation; illegal filename
// 1.1.0.190518 (4) Implemented Workflow: GET_CONTENT/PICK/share/SEND/SENDTO to pick/re-send a cropped photo
// 1.1.1.190522 (5) Errorhandling/display errormessage; delete temp files; action com.android.camera.action.CROP

versionCode 5
versionName "1.1.1.190522"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ protected File getSharedDir() {
protected String createCropFileName() {
Uri inUri = getSourceImageUri(getIntent());
String originalFileName = (inUri == null) ? "" : inUri.getLastPathSegment();
originalFileName = TempFileUtil.getLastPath(originalFileName);
return replaceExtension(originalFileName, TempFileUtil.TEMP_FILE_SUFFIX);
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/de/k3b/util/TempFileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ static boolean shouldDeleteTempFile(String fileName, long lastModifiedInMilliSec
&& fileName.endsWith(TEMP_FILE_SUFFIX);
}

public static String getLastPath(String originalFileName) {
if (originalFileName != null) {
int splitPos = originalFileName.lastIndexOf(File.separatorChar);
if (splitPos == -1) splitPos = originalFileName.lastIndexOf('/');
if (splitPos >= 0) originalFileName = originalFileName.substring(splitPos + 1);
}
return originalFileName;
}


}
10 changes: 10 additions & 0 deletions app/src/test/java/de/k3b/util/TempFileUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
public class TempFileUnitTest {
private static final String FILE_NAME = "hello" + TempFileUtil.TEMP_FILE_SUFFIX;

//
@Test
public void shouldGetPath() {
final String expected = "190020_llcrop_llcrop.jpg";
String in = "primary:DCIM/test/" + expected;
assertEquals(expected, TempFileUtil.getLastPath(in));
assertEquals(expected, TempFileUtil.getLastPath(expected));
assertEquals(null, TempFileUtil.getLastPath(null));
}

@Test
public void shouldDeleteOldTempFile() {
long fileDate = getTime(13, 1);
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#2 #3: bugfix created illegal local file name for send/get_content

0 comments on commit ec1ac77

Please sign in to comment.