mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Updates
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
88a68b36c4
commit
9b50b0be89
4 changed files with 140 additions and 85 deletions
|
@ -63,70 +63,73 @@ public class FilesSyncJob extends Job {
|
|||
TAG);
|
||||
wakeLock.acquire();
|
||||
|
||||
FilesSyncHelper.restartJobsIfNeeded();
|
||||
FilesSyncHelper.insertAllDBEntries();
|
||||
if (JobManager.instance().getAllJobsForTag(FilesSyncJob.TAG).size() == 1) {
|
||||
|
||||
// Create all the providers we'll need
|
||||
final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
||||
FilesSyncHelper.restartJobsIfNeeded();
|
||||
FilesSyncHelper.insertAllDBEntries();
|
||||
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
if (syncedFolder.isEnabled()) {
|
||||
// ignore custom folders for now
|
||||
if (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);
|
||||
// Create all the providers we'll need
|
||||
final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
||||
|
||||
Long lastModificationTime = file.lastModified();
|
||||
final Locale currentLocale = context.getResources().getConfiguration().locale;
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
if (syncedFolder.isEnabled()) {
|
||||
// ignore custom folders for now
|
||||
if (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);
|
||||
|
||||
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();
|
||||
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());
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
PersistableBundleCompat bundle = new PersistableBundleCompat();
|
||||
bundle.putString(AutoUploadJob.LOCAL_PATH, file.getAbsolutePath());
|
||||
bundle.putString(AutoUploadJob.REMOTE_PATH, FileStorageUtils.getInstantUploadFilePath(
|
||||
currentLocale,
|
||||
syncedFolder.getRemotePath(), file.getName(),
|
||||
lastModificationTime,
|
||||
syncedFolder.getSubfolderByDate()));
|
||||
bundle.putString(AutoUploadJob.ACCOUNT, syncedFolder.getAccount());
|
||||
bundle.putInt(AutoUploadJob.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction());
|
||||
|
||||
new JobRequest.Builder(AutoUploadJob.TAG)
|
||||
.setExecutionWindow(30_000L, 80_000L)
|
||||
.setRequiresCharging(syncedFolder.getChargingOnly())
|
||||
.setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobRequest.NetworkType.UNMETERED :
|
||||
JobRequest.NetworkType.CONNECTED)
|
||||
.setExtras(bundle)
|
||||
.setRequirementsEnforced(true)
|
||||
.setUpdateCurrent(false)
|
||||
.build()
|
||||
.schedule();
|
||||
|
||||
filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
|
||||
Long.toString(syncedFolder.getId()));
|
||||
}
|
||||
|
||||
PersistableBundleCompat bundle = new PersistableBundleCompat();
|
||||
bundle.putString(AutoUploadJob.LOCAL_PATH, file.getAbsolutePath());
|
||||
bundle.putString(AutoUploadJob.REMOTE_PATH, FileStorageUtils.getInstantUploadFilePath(
|
||||
currentLocale,
|
||||
syncedFolder.getRemotePath(), file.getName(),
|
||||
lastModificationTime,
|
||||
syncedFolder.getSubfolderByDate()));
|
||||
bundle.putString(AutoUploadJob.ACCOUNT, syncedFolder.getAccount());
|
||||
bundle.putInt(AutoUploadJob.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction());
|
||||
|
||||
new JobRequest.Builder(AutoUploadJob.TAG)
|
||||
.setExecutionWindow(30_000L, 80_000L)
|
||||
.setRequiresCharging(syncedFolder.getChargingOnly())
|
||||
.setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobRequest.NetworkType.UNMETERED :
|
||||
JobRequest.NetworkType.CONNECTED)
|
||||
.setExtras(bundle)
|
||||
.setRequirementsEnforced(true)
|
||||
.setUpdateCurrent(false)
|
||||
.build()
|
||||
.schedule();
|
||||
|
||||
filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
|
||||
Long.toString(syncedFolder.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,12 +56,14 @@ import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
|
|||
import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable;
|
||||
import com.owncloud.android.ui.events.CustomFolderEvent;
|
||||
import com.owncloud.android.ui.events.InitiateSyncedFolder;
|
||||
import com.owncloud.android.utils.AnalyticsUtils;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.PermissionUtil;
|
||||
import com.owncloud.android.utils.FilesSyncHelper;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
|
@ -478,6 +480,7 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
|
|||
long storedId = mSyncedFolderProvider.storeFolderSync(syncedFolderDisplayItem);
|
||||
if (storedId != -1) {
|
||||
syncedFolderDisplayItem.setId(storedId);
|
||||
EventBus.getDefault().post(new InitiateSyncedFolder(syncedFolderDisplayItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -536,6 +539,7 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
|
|||
long storedId = mSyncedFolderProvider.storeFolderSync(item);
|
||||
if (storedId != -1) {
|
||||
item.setId(storedId);
|
||||
EventBus.getDefault().post(new InitiateSyncedFolder(item));
|
||||
}
|
||||
} else {
|
||||
// existing synced folder setup to be updated
|
||||
|
@ -626,4 +630,10 @@ public class FolderSyncActivity extends FileActivity implements FolderSyncAdapte
|
|||
onSyncFolderSettingsClick(0, emptyCustomFolder);
|
||||
};
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(InitiateSyncedFolder event) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(event.getSyncedFolder());
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.events;
|
||||
|
||||
import com.owncloud.android.datamodel.SyncedFolder;
|
||||
|
||||
public class InitiateSyncedFolder {
|
||||
private final SyncedFolder syncedFolder;
|
||||
|
||||
|
||||
public InitiateSyncedFolder(SyncedFolder syncedFolder) {
|
||||
this.syncedFolder = syncedFolder;
|
||||
}
|
||||
|
||||
public SyncedFolder getSyncedFolder() {
|
||||
return syncedFolder;
|
||||
}
|
||||
}
|
|
@ -42,44 +42,51 @@ import java.io.File;
|
|||
|
||||
public class FilesSyncHelper {
|
||||
|
||||
public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
|
||||
final Context context = MainApp.getAppContext();
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(contentResolver);
|
||||
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolder.getId();
|
||||
boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
|
||||
("global", syncedFolderInitiatedKey));
|
||||
|
||||
if (MediaFolder.IMAGE == syncedFolder.getType()) {
|
||||
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
|
||||
, dryRun, syncedFolder);
|
||||
FilesSyncHelper.insertContentIntoDB(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, dryRun,
|
||||
syncedFolder);
|
||||
|
||||
if (dryRun) {
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
||||
"1");
|
||||
}
|
||||
} else if (MediaFolder.VIDEO == syncedFolder.getType()) {
|
||||
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI,
|
||||
dryRun, syncedFolder);
|
||||
FilesSyncHelper.insertContentIntoDB(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, dryRun,
|
||||
syncedFolder);
|
||||
|
||||
if (dryRun) {
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
||||
"1");
|
||||
}
|
||||
|
||||
} else {
|
||||
// custom folder, do nothing
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertAllDBEntries() {
|
||||
boolean dryRun;
|
||||
|
||||
final Context context = MainApp.getAppContext();
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(contentResolver);
|
||||
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
if (syncedFolder.isEnabled()) {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolder.getId();
|
||||
dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
|
||||
("global", syncedFolderInitiatedKey));
|
||||
|
||||
if (MediaFolder.IMAGE == syncedFolder.getType()) {
|
||||
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
|
||||
, dryRun, syncedFolder);
|
||||
FilesSyncHelper.insertContentIntoDB(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, dryRun,
|
||||
syncedFolder);
|
||||
|
||||
if (dryRun) {
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
||||
"1");
|
||||
}
|
||||
} else if (MediaFolder.VIDEO == syncedFolder.getType()) {
|
||||
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI,
|
||||
dryRun, syncedFolder);
|
||||
FilesSyncHelper.insertContentIntoDB(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, dryRun,
|
||||
syncedFolder);
|
||||
|
||||
if (dryRun) {
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
|
||||
"1");
|
||||
}
|
||||
|
||||
} else {
|
||||
// custom folder, do nothing
|
||||
}
|
||||
insertAllDBEntriesForSyncedFolder(syncedFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue