mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
ignore thumbnauil folders for detection/display - related to #7085
ignore thumbdata files for detection - related to #3177 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
2fe3369210
commit
608dbd998f
2 changed files with 99 additions and 13 deletions
|
@ -24,10 +24,12 @@ import com.owncloud.android.AbstractIT
|
||||||
import com.owncloud.android.datamodel.MediaFolder
|
import com.owncloud.android.datamodel.MediaFolder
|
||||||
import com.owncloud.android.datamodel.MediaFolderType
|
import com.owncloud.android.datamodel.MediaFolderType
|
||||||
import com.owncloud.android.datamodel.SyncedFolder
|
import com.owncloud.android.datamodel.SyncedFolder
|
||||||
|
import org.apache.commons.io.FileUtils
|
||||||
import org.junit.AfterClass
|
import org.junit.AfterClass
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.BeforeClass
|
import org.junit.BeforeClass
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
|
|
||||||
class SyncedFolderUtilsTest : AbstractIT() {
|
class SyncedFolderUtilsTest : AbstractIT() {
|
||||||
|
@ -41,6 +43,7 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
||||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(FOLDER))
|
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(FOLDER))
|
||||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("Folder.jpeg"))
|
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("Folder.jpeg"))
|
||||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("FOLDER.jpg"))
|
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("FOLDER.jpg"))
|
||||||
|
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(".thumbdata4--1967290299"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -150,6 +153,50 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
||||||
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun assertUnqualifiedSyncedFolder() {
|
||||||
|
val tempPath = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + ".thumbnail")
|
||||||
|
if (!tempPath.exists()) {
|
||||||
|
Assert.assertTrue(tempPath.mkdirs())
|
||||||
|
}
|
||||||
|
getDummyFile(".thumbnail/image.jpg")
|
||||||
|
val folder = SyncedFolder(
|
||||||
|
tempPath.absolutePath,
|
||||||
|
"",
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
account.name,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
0L,
|
||||||
|
MediaFolderType.IMAGE,
|
||||||
|
false)
|
||||||
|
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun assertUnqualifiedContentSyncedFolder() {
|
||||||
|
val image = getDummyFile(THUMBDATA_FOLDER + File.pathSeparator + IMAGE_JPEG)
|
||||||
|
val folder = SyncedFolder(
|
||||||
|
FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + THUMBDATA_FOLDER,
|
||||||
|
"",
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
account.name,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
0L,
|
||||||
|
MediaFolderType.IMAGE,
|
||||||
|
false)
|
||||||
|
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SELFIE = "selfie.png"
|
private const val SELFIE = "selfie.png"
|
||||||
private const val SCREENSHOT = "screenshot.JPG"
|
private const val SCREENSHOT = "screenshot.JPG"
|
||||||
|
@ -160,10 +207,17 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
||||||
private const val SONG_TWO = "song2.mp3"
|
private const val SONG_TWO = "song2.mp3"
|
||||||
private const val FOLDER = "folder.JPG"
|
private const val FOLDER = "folder.JPG"
|
||||||
private const val COVER = "cover.jpg"
|
private const val COVER = "cover.jpg"
|
||||||
|
private const val THUMBDATA_FOLDER = "thumbdata_test";
|
||||||
|
private const val THUMBDATA_FILE = "thumbdata_test";
|
||||||
private const val ITERATION = 100
|
private const val ITERATION = 100
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
val tempPath = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + THUMBDATA_FOLDER)
|
||||||
|
if (!tempPath.exists()) {
|
||||||
|
tempPath.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
createFile(SELFIE, ITERATION)
|
createFile(SELFIE, ITERATION)
|
||||||
createFile(SCREENSHOT, ITERATION)
|
createFile(SCREENSHOT, ITERATION)
|
||||||
createFile(IMAGE_JPEG, ITERATION)
|
createFile(IMAGE_JPEG, ITERATION)
|
||||||
|
@ -173,19 +227,13 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
||||||
createFile(SONG_TWO, ITERATION)
|
createFile(SONG_TWO, ITERATION)
|
||||||
createFile(FOLDER, ITERATION)
|
createFile(FOLDER, ITERATION)
|
||||||
createFile(COVER, ITERATION)
|
createFile(COVER, ITERATION)
|
||||||
|
|
||||||
|
createFile(THUMBDATA_FOLDER + File.pathSeparator + THUMBDATA_FILE, ITERATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
getDummyFile(SELFIE).delete()
|
FileUtils.deleteDirectory(File(FileStorageUtils.getTemporalPath(account.name)))
|
||||||
getDummyFile(SCREENSHOT).delete()
|
|
||||||
getDummyFile(IMAGE_JPEG).delete()
|
|
||||||
getDummyFile(IMAGE_BITMAP).delete()
|
|
||||||
getDummyFile(SONG_ZERO).delete()
|
|
||||||
getDummyFile(SONG_ONE).delete()
|
|
||||||
getDummyFile(SONG_TWO).delete()
|
|
||||||
getDummyFile(FOLDER).delete()
|
|
||||||
getDummyFile(COVER).delete()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.owncloud.android.datamodel.SyncedFolder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -40,8 +41,12 @@ public final class SyncedFolderUtils {
|
||||||
"cover.jpg", "cover.jpeg",
|
"cover.jpg", "cover.jpeg",
|
||||||
"folder.jpg", "folder.jpeg"
|
"folder.jpg", "folder.jpeg"
|
||||||
};
|
};
|
||||||
private static final Set<String> DISQUALIFIED_MEDIA_DETECTION_SET =
|
private static final Set<String> DISQUALIFIED_MEDIA_DETECTION_FILE_SET =
|
||||||
new HashSet<>(Arrays.asList(DISQUALIFIED_MEDIA_DETECTION_SOURCE));
|
new HashSet<>(Arrays.asList(DISQUALIFIED_MEDIA_DETECTION_SOURCE));
|
||||||
|
private static final Set<MediaFolderType> AUTO_QUALIFYING_FOLDER_TYPE_SET =
|
||||||
|
new HashSet<>(Collections.singletonList(MediaFolderType.CUSTOM));
|
||||||
|
private static final String THUMBNAIL_FOLDER_PREFIX = ".thumbnail";
|
||||||
|
private static final String THUMBNAIL_DATA_FILE_PREFIX = ".thumbdata";
|
||||||
private static final int SINGLE_FILE = 1;
|
private static final int SINGLE_FILE = 1;
|
||||||
|
|
||||||
private SyncedFolderUtils() {
|
private SyncedFolderUtils() {
|
||||||
|
@ -60,10 +65,15 @@ public final class SyncedFolderUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom folders are always fine
|
// custom folders are always fine
|
||||||
if (MediaFolderType.CUSTOM == mediaFolder.type) {
|
if (AUTO_QUALIFYING_FOLDER_TYPE_SET.contains(mediaFolder.type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// thumbnail folder
|
||||||
|
if (isQualifiedFolder(mediaFolder.absolutePath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// filter media folders
|
// filter media folders
|
||||||
|
|
||||||
// no files
|
// no files
|
||||||
|
@ -89,10 +99,15 @@ public final class SyncedFolderUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom folders are always fine
|
// custom folders are always fine
|
||||||
if (MediaFolderType.CUSTOM == syncedFolder.getType()) {
|
if (AUTO_QUALIFYING_FOLDER_TYPE_SET.contains(syncedFolder.getType())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// thumbnail folder
|
||||||
|
if (isQualifiedFolder(syncedFolder.getLocalPath())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// filter media folders
|
// filter media folders
|
||||||
File[] files = getFileList(new File(syncedFolder.getLocalPath()));
|
File[] files = getFileList(new File(syncedFolder.getLocalPath()));
|
||||||
|
|
||||||
|
@ -121,6 +136,16 @@ public final class SyncedFolderUtils {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// custom folders are always fine
|
||||||
|
if (AUTO_QUALIFYING_FOLDER_TYPE_SET.contains(folderType)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// thumbnail folder
|
||||||
|
if (isQualifiedFolder(folderPath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// filter media folders
|
// filter media folders
|
||||||
File[] files = getFileList(new File(folderPath));
|
File[] files = getFileList(new File(folderPath));
|
||||||
|
|
||||||
|
@ -135,6 +160,18 @@ public final class SyncedFolderUtils {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if folder is qualified for auto upload.
|
||||||
|
*
|
||||||
|
* @param folderPath the folder's path string
|
||||||
|
* @return code>true</code> if folder qualifies for auto upload else <code>false</code>
|
||||||
|
*/
|
||||||
|
private static boolean isQualifiedFolder(String folderPath) {
|
||||||
|
File folder = new File(folderPath);
|
||||||
|
// check if folder starts with thumbnail praefix
|
||||||
|
return !folder.isDirectory() || folder.getName() == null || !folder.getName().startsWith(THUMBNAIL_FOLDER_PREFIX);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if given list contains images that qualify as auto upload relevant files.
|
* check if given list contains images that qualify as auto upload relevant files.
|
||||||
*
|
*
|
||||||
|
@ -176,7 +213,8 @@ public final class SyncedFolderUtils {
|
||||||
*/
|
*/
|
||||||
public static boolean isFileNameQualifiedForMediaDetection(String fileName) {
|
public static boolean isFileNameQualifiedForMediaDetection(String fileName) {
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
return !DISQUALIFIED_MEDIA_DETECTION_SET.contains(fileName.toLowerCase(Locale.ROOT));
|
return !DISQUALIFIED_MEDIA_DETECTION_FILE_SET.contains(fileName.toLowerCase(Locale.ROOT))
|
||||||
|
&& !fileName.startsWith(THUMBNAIL_DATA_FILE_PREFIX);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue