Skip to content

Commit

Permalink
ADD: [instantupload] setting to also upload existing files
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koying Browet <cbro@semperpax.com>
  • Loading branch information
koying authored and tobiasKaminsky committed Feb 18, 2020
1 parent c243453 commit 1b7bd72
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ private static void initiateExistingAutoUploadEntries(Clock clock) {

for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
if (syncedFolder.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder);
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SyncedFolder implements Serializable, Cloneable {
@Getter @Setter private String remotePath;
@Getter @Setter private boolean wifiOnly;
@Getter @Setter private boolean chargingOnly;
@Getter @Setter private boolean existing;
@Getter @Setter private boolean subfolderByDate;
@Getter @Setter private String account;
@Getter @Setter private int uploadAction;
Expand All @@ -54,6 +55,7 @@ public class SyncedFolder implements Serializable, Cloneable {
* @param remotePath remote path
* @param wifiOnly upload on wifi only flag
* @param chargingOnly upload on charging only
* @param existing upload existing files
* @param subfolderByDate create sub-folders by date (month)
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
Expand All @@ -66,15 +68,16 @@ public SyncedFolder(String localPath,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account,
uploadAction, enabled, timestampMs, type, hidden);
}

/**
Expand All @@ -87,6 +90,7 @@ protected SyncedFolder(long id,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
Expand All @@ -99,6 +103,7 @@ protected SyncedFolder(long id,
this.remotePath = remotePath;
this.wifiOnly = wifiOnly;
this.chargingOnly = chargingOnly;
this.existing = existing;
this.subfolderByDate = subfolderByDate;
this.account = account;
this.uploadAction = uploadAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
* @param remotePath remote path
* @param wifiOnly upload on wifi only flag
* @param chargingOnly upload on charging only
* @param existing also upload existing
* @param subfolderByDate create sub-folders by date (month)
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
Expand All @@ -60,6 +61,7 @@ public SyncedFolderDisplayItem(long id,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
Expand All @@ -70,8 +72,8 @@ public SyncedFolderDisplayItem(long id,
long numberOfFiles,
MediaFolderType type,
boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type, hidden);
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
Expand All @@ -82,14 +84,15 @@ public SyncedFolderDisplayItem(long id,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
String folderName, MediaFolderType type, boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type, hidden);
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
this.folderName = folderName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY)) == 1;
boolean chargingOnly = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY)) == 1;
boolean existing = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING)) == 1;
boolean subfolderByDate = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE)) == 1;
String accountName = cursor.getString(cursor.getColumnIndex(
Expand All @@ -357,8 +359,9 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
boolean hidden = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;

syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
accountName, uploadAction, enabled, enabledTimestampMs, type, hidden);
syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, existing,
subfolderByDate, accountName, uploadAction, enabled, enabledTimestampMs,
type, hidden);
}
return syncedFolder;
}
Expand All @@ -376,6 +379,7 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH, syncedFolder.getRemotePath());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY, syncedFolder.isWifiOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY, syncedFolder.isChargingOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING, syncedFolder.isExisting());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED, syncedFolder.isEnabled());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS, syncedFolder.getEnabledTimestampMs());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.isSubfolderByDate());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 53;
public static final int DB_VERSION = 54;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -223,6 +223,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String SYNCED_FOLDER_REMOTE_PATH = "remote_path";
public static final String SYNCED_FOLDER_WIFI_ONLY = "wifi_only";
public static final String SYNCED_FOLDER_CHARGING_ONLY = "charging_only";
public static final String SYNCED_FOLDER_EXISTING = "existing";
public static final String SYNCED_FOLDER_ENABLED = "enabled";
public static final String SYNCED_FOLDER_ENABLED_TIMESTAMP_MS = "enabled_timestamp_ms";
public static final String SYNCED_FOLDER_TYPE = "type";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/owncloud/android/jobs/FilesSyncJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected Result onRunJob(@NonNull Params params) {
userAccountManager,
connectivityService,
powerManagementService);
FilesSyncHelper.insertAllDBEntries(preferences, clock, skipCustom);
FilesSyncHelper.insertAllDBEntries(preferences, clock, skipCustom, false);

// Create all the providers we'll need
final ContentResolver contentResolver = context.getContentResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ private void createSyncedFoldersTable(SQLiteDatabase db) {
+ ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH + " TEXT, " // remote path
+ ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, " // wifi_only
+ ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
+ ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER, " // existing
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
+ ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
Expand Down Expand Up @@ -2104,6 +2105,24 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}

if(oldVersion < 54 && newVersion >= 54) {
Log_OC.i(SQL, "Entering in the #54 add synced.existing");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_EXISTING + " INTEGER "); // boolean

upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}

if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ private SyncedFolderDisplayItem createSyncedFolderWithoutMediaFolder(@NonNull Sy
syncedFolder.getRemotePath(),
syncedFolder.isWifiOnly(),
syncedFolder.isChargingOnly(),
syncedFolder.isExisting(),
syncedFolder.isSubfolderByDate(),
syncedFolder.getAccount(),
syncedFolder.getUploadAction(),
Expand Down Expand Up @@ -443,6 +444,7 @@ private SyncedFolderDisplayItem createSyncedFolder(@NonNull SyncedFolder syncedF
syncedFolder.getRemotePath(),
syncedFolder.isWifiOnly(),
syncedFolder.isChargingOnly(),
syncedFolder.isExisting(),
syncedFolder.isSubfolderByDate(),
syncedFolder.getAccount(),
syncedFolder.getUploadAction(),
Expand Down Expand Up @@ -470,6 +472,7 @@ private SyncedFolderDisplayItem createSyncedFolderFromMediaFolder(@NonNull Media
true,
false,
false,
false,
getAccount().name,
FileUploader.LOCAL_BEHAVIOUR_FORGET,
false,
Expand Down Expand Up @@ -577,7 +580,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_create_custom_folder: {
Log.d(TAG, "Show custom folder dialog");
SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
SyncedFolder.UNPERSISTED_ID, null, null, true, false,
SyncedFolder.UNPERSISTED_ID, null, null, true, false, false,
false, getAccount().name, FileUploader.LOCAL_BEHAVIOUR_FORGET, false,
clock.getCurrentTime(), null, MediaFolderType.CUSTOM, false);
onSyncFolderSettingsClick(0, emptyCustomFolder);
Expand Down Expand Up @@ -619,7 +622,7 @@ public void onSyncStatusToggleClick(int section, SyncedFolderDisplayItem syncedF
}

if (syncedFolderDisplayItem.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolderDisplayItem);
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolderDisplayItem, true);

showBatteryOptimizationInfo();
}
Expand Down Expand Up @@ -709,18 +712,20 @@ public void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
if (MediaFolderType.CUSTOM == syncedFolder.getType() && syncedFolder.getId() == UNPERSISTED_ID) {
SyncedFolderDisplayItem newCustomFolder = new SyncedFolderDisplayItem(
SyncedFolder.UNPERSISTED_ID, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(),
syncedFolder.isWifiOnly(), syncedFolder.isChargingOnly(), syncedFolder.isSubfolderByDate(),
syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.isEnabled(),
clock.getCurrentTime(), new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType(), syncedFolder.isHidden());
syncedFolder.isWifiOnly(), syncedFolder.isChargingOnly(),
syncedFolder.isExisting(), syncedFolder.isSubfolderByDate(), syncedFolder.getAccount(),
syncedFolder.getUploadAction(), syncedFolder.isEnabled(), clock.getCurrentTime(),
new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType(), syncedFolder.isHidden());

saveOrUpdateSyncedFolder(newCustomFolder);
adapter.addSyncFolderItem(newCustomFolder);
} else {
SyncedFolderDisplayItem item = adapter.get(syncedFolder.getSection());
updateSyncedFolderItem(item, syncedFolder.getId(), syncedFolder.getLocalPath(),
syncedFolder.getRemotePath(), syncedFolder
.isWifiOnly(), syncedFolder.isChargingOnly(), syncedFolder.isSubfolderByDate(), syncedFolder
.getUploadAction(), syncedFolder.isEnabled());
syncedFolder.getRemotePath(), syncedFolder.isWifiOnly(),
syncedFolder.isChargingOnly(), syncedFolder.isExisting(),
syncedFolder.isSubfolderByDate(), syncedFolder.getUploadAction(),
syncedFolder.isEnabled());

saveOrUpdateSyncedFolder(item);

Expand All @@ -743,7 +748,7 @@ private void saveOrUpdateSyncedFolder(SyncedFolderDisplayItem item) {
// existing synced folder setup to be updated
syncedFolderProvider.updateSyncFolder(item);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item, true);
} else {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();

Expand All @@ -761,7 +766,7 @@ private void storeSyncedFolder(SyncedFolderDisplayItem item) {
if (storedId != -1) {
item.setId(storedId);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item, true);
} else {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
Expand All @@ -788,6 +793,7 @@ public void onDeleteSyncedFolderPreference(SyncedFolderParcelable syncedFolder)
* @param remotePath the remote path
* @param wifiOnly upload on wifi only
* @param chargingOnly upload on charging only
* @param existing also upload existing
* @param subfolderByDate created sub folders
* @param uploadAction upload action
* @param enabled is sync enabled
Expand All @@ -798,6 +804,7 @@ private void updateSyncedFolderItem(SyncedFolderDisplayItem item,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
Integer uploadAction,
boolean enabled) {
Expand All @@ -806,6 +813,7 @@ private void updateSyncedFolderItem(SyncedFolderDisplayItem item,
item.setRemotePath(remotePath);
item.setWifiOnly(wifiOnly);
item.setChargingOnly(chargingOnly);
item.setExisting(existing);
item.setSubfolderByDate(subfolderByDate);
item.setUploadAction(uploadAction);
item.setEnabled(enabled, clock.getCurrentTime());
Expand Down
Loading

0 comments on commit 1b7bd72

Please sign in to comment.