|
@@ -72,77 +72,74 @@ public class FilesSyncJob extends Job {
|
|
|
|
|
|
PersistableBundleCompat bundle = params.getExtras();
|
|
|
final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
|
|
|
-
|
|
|
- if (JobManager.instance().getAllJobsForTag(FilesSyncJob.TAG).size() == 1) {
|
|
|
-
|
|
|
- FilesSyncHelper.restartJobsIfNeeded();
|
|
|
- FilesSyncHelper.insertAllDBEntries(skipCustom);
|
|
|
-
|
|
|
- // Create all the providers we'll need
|
|
|
- final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
|
|
- SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
|
|
-
|
|
|
- for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
|
|
- if (syncedFolder.isEnabled()) {
|
|
|
- if (!skipCustom || MediaFolder.CUSTOM != syncedFolder.getType()) {
|
|
|
- for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
|
|
|
- Long.toString(syncedFolder.getId()))) {
|
|
|
- if (JobManager.instance().getAllJobRequests().size() < 80) {
|
|
|
- File file = new File(path);
|
|
|
-
|
|
|
- Long lastModificationTime = file.lastModified();
|
|
|
- final Locale currentLocale = context.getResources().getConfiguration().locale;
|
|
|
-
|
|
|
- if (MediaFolder.IMAGE == syncedFolder.getType()) {
|
|
|
- String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
|
|
|
- if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
|
|
|
- equalsIgnoreCase(mimetypeString)) {
|
|
|
- try {
|
|
|
- ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
|
|
|
- String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
|
|
|
- if (!TextUtils.isEmpty(exifDate)) {
|
|
|
- ParsePosition pos = new ParsePosition(0);
|
|
|
- SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
|
|
|
- currentLocale);
|
|
|
- sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
|
|
|
- Date dateTime = sFormatter.parse(exifDate, pos);
|
|
|
- lastModificationTime = dateTime.getTime();
|
|
|
- }
|
|
|
-
|
|
|
- } catch (IOException e) {
|
|
|
- Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
|
|
|
+
|
|
|
+ FilesSyncHelper.restartJobsIfNeeded();
|
|
|
+ FilesSyncHelper.insertAllDBEntries(skipCustom);
|
|
|
+
|
|
|
+ // Create all the providers we'll need
|
|
|
+ final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
|
|
+ SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
|
|
+
|
|
|
+ for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
|
|
+ if (syncedFolder.isEnabled()) {
|
|
|
+ if (!skipCustom || MediaFolder.CUSTOM != syncedFolder.getType()) {
|
|
|
+ for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
|
|
|
+ Long.toString(syncedFolder.getId()))) {
|
|
|
+ if (JobManager.instance().getAllJobRequests().size() < 80) {
|
|
|
+ File file = new File(path);
|
|
|
+
|
|
|
+ Long lastModificationTime = file.lastModified();
|
|
|
+ final Locale currentLocale = context.getResources().getConfiguration().locale;
|
|
|
+
|
|
|
+ if (MediaFolder.IMAGE == syncedFolder.getType()) {
|
|
|
+ String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
|
|
|
+ if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
|
|
|
+ equalsIgnoreCase(mimetypeString)) {
|
|
|
+ try {
|
|
|
+ ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
|
|
|
+ String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
|
|
|
+ if (!TextUtils.isEmpty(exifDate)) {
|
|
|
+ ParsePosition pos = new ParsePosition(0);
|
|
|
+ SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
|
|
|
+ currentLocale);
|
|
|
+ sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
|
|
|
+ Date dateTime = sFormatter.parse(exifDate, pos);
|
|
|
+ lastModificationTime = dateTime.getTime();
|
|
|
}
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- boolean needsCharging = syncedFolder.getChargingOnly();
|
|
|
- boolean needsWifi = syncedFolder.getWifiOnly();
|
|
|
-
|
|
|
- String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
|
|
|
-
|
|
|
- Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
|
|
|
-
|
|
|
- requester.uploadFileWithOverwrite(
|
|
|
- context,
|
|
|
- account,
|
|
|
- file.getAbsolutePath(),
|
|
|
- FileStorageUtils.getInstantUploadFilePath(
|
|
|
- currentLocale,
|
|
|
- syncedFolder.getRemotePath(), file.getName(),
|
|
|
- lastModificationTime,
|
|
|
- syncedFolder.getSubfolderByDate()),
|
|
|
- syncedFolder.getUploadAction(),
|
|
|
- mimeType,
|
|
|
- true, // create parent folder if not existent
|
|
|
- UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
|
|
|
- needsWifi,
|
|
|
- needsCharging,
|
|
|
- true
|
|
|
- );
|
|
|
-
|
|
|
- filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
|
|
|
- Long.toString(syncedFolder.getId()));
|
|
|
}
|
|
|
+
|
|
|
+ boolean needsCharging = syncedFolder.getChargingOnly();
|
|
|
+ boolean needsWifi = syncedFolder.getWifiOnly();
|
|
|
+
|
|
|
+ String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
|
|
|
+
|
|
|
+ Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
|
|
|
+
|
|
|
+ requester.uploadFileWithOverwrite(
|
|
|
+ context,
|
|
|
+ account,
|
|
|
+ file.getAbsolutePath(),
|
|
|
+ FileStorageUtils.getInstantUploadFilePath(
|
|
|
+ currentLocale,
|
|
|
+ syncedFolder.getRemotePath(), file.getName(),
|
|
|
+ lastModificationTime,
|
|
|
+ syncedFolder.getSubfolderByDate()),
|
|
|
+ syncedFolder.getUploadAction(),
|
|
|
+ mimeType,
|
|
|
+ true, // create parent folder if not existent
|
|
|
+ UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
|
|
|
+ needsWifi,
|
|
|
+ needsCharging,
|
|
|
+ true
|
|
|
+ );
|
|
|
+
|
|
|
+ filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
|
|
|
+ Long.toString(syncedFolder.getId()));
|
|
|
}
|
|
|
}
|
|
|
}
|