Search in sources :

Example 1 with MediaFolderType

use of com.owncloud.android.datamodel.MediaFolderType in project android by nextcloud.

the class FilesSyncHelper method insertAllDBEntriesForSyncedFolder.

private static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
    final Context context = MainApp.getAppContext();
    final ContentResolver contentResolver = context.getContentResolver();
    final long enabledTimestampMs = syncedFolder.getEnabledTimestampMs();
    if (syncedFolder.isEnabled() && (syncedFolder.isExisting() || enabledTimestampMs >= 0)) {
        MediaFolderType mediaType = syncedFolder.getType();
        if (mediaType == MediaFolderType.IMAGE) {
            FilesSyncHelper.insertContentIntoDB(MediaStore.Images.Media.INTERNAL_CONTENT_URI, syncedFolder);
            FilesSyncHelper.insertContentIntoDB(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, syncedFolder);
        } else if (mediaType == MediaFolderType.VIDEO) {
            FilesSyncHelper.insertContentIntoDB(MediaStore.Video.Media.INTERNAL_CONTENT_URI, syncedFolder);
            FilesSyncHelper.insertContentIntoDB(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, syncedFolder);
        } else {
            try {
                FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
                Path path = Paths.get(syncedFolder.getLocalPath());
                Files.walkFileTree(path, new SimpleFileVisitor<Path>() {

                    @Override
                    public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
                        File file = path.toFile();
                        if (syncedFolder.isExisting() || attrs.lastModifiedTime().toMillis() >= enabledTimestampMs) {
                            filesystemDataProvider.storeOrUpdateFileValue(path.toAbsolutePath().toString(), attrs.lastModifiedTime().toMillis(), file.isDirectory(), syncedFolder);
                        }
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFileFailed(Path file, IOException exc) {
                        return FileVisitResult.CONTINUE;
                    }
                });
            } catch (IOException e) {
                Log_OC.e(TAG, "Something went wrong while indexing files for auto upload", e);
            }
        }
    }
}
Also used : Context(android.content.Context) Path(org.lukhnos.nnio.file.Path) FilesystemDataProvider(com.owncloud.android.datamodel.FilesystemDataProvider) SimpleFileVisitor(org.lukhnos.nnio.file.SimpleFileVisitor) MediaFolderType(com.owncloud.android.datamodel.MediaFolderType) IOException(java.io.IOException) File(java.io.File) BasicFileAttributes(org.lukhnos.nnio.file.attribute.BasicFileAttributes) ContentResolver(android.content.ContentResolver)

Aggregations

ContentResolver (android.content.ContentResolver)1 Context (android.content.Context)1 FilesystemDataProvider (com.owncloud.android.datamodel.FilesystemDataProvider)1 MediaFolderType (com.owncloud.android.datamodel.MediaFolderType)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (org.lukhnos.nnio.file.Path)1 SimpleFileVisitor (org.lukhnos.nnio.file.SimpleFileVisitor)1 BasicFileAttributes (org.lukhnos.nnio.file.attribute.BasicFileAttributes)1