Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SyncedFolder implements Serializable, Cloneable {
private String remotePath;
private Boolean wifiOnly;
private Boolean chargingOnly;
private Boolean existing;
private Boolean subfolderByDate;
private String account;
private Integer uploadAction;
Expand All @@ -62,12 +63,13 @@ public class SyncedFolder implements Serializable, Cloneable {
* @param type the type of the folder
*/
public SyncedFolder(String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
MediaFolderType type) {
Boolean existing, Boolean subfolderByDate, String account, Integer uploadAction,
Boolean enabled,MediaFolderType type) {
this.localPath = localPath;
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 @@ -55,19 +56,19 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
* @param type the type of the folder
*/
public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
List<String> filePaths, String folderName, long numberOfFiles, MediaFolderType type)
Boolean existing, Boolean subfolderByDate, String account, Integer uploadAction,
Boolean enabled, List<String> filePaths, String folderName, long numberOfFiles, MediaFolderType type)
{
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction, enabled, type);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
}

public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
String folderName, MediaFolderType type) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
Boolean existing, Boolean subfolderByDate, String account, Integer uploadAction,
Boolean enabled, String folderName, MediaFolderType type) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction, enabled, type);
this.folderName = folderName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,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 @@ -350,8 +352,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
MediaFolderType type = MediaFolderType.getById(cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE)));

syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
accountName, uploadAction, enabled, type);
syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, existing,
subfolderByDate,accountName, uploadAction, enabled, type);
}
return syncedFolder;
}
Expand All @@ -369,6 +371,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.getWifiOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY, syncedFolder.getChargingOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING, syncedFolder.getExisting());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED, syncedFolder.isEnabled());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.getSubfolderByDate());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
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 = 49;
public static final int DB_VERSION = 50;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -219,6 +219,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_TYPE = "type";
public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,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_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
+ ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
Expand Down Expand Up @@ -2013,6 +2014,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 < 50 && newVersion >= 50) {
Log_OC.i(SQL, "Entering in the #50 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));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import com.evernote.android.job.JobRequest;
import com.nextcloud.client.device.PowerManagementService;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.preferences.AppPreferences;
Expand All @@ -56,6 +57,7 @@
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
import com.owncloud.android.datamodel.SyncedFolderProvider;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.jobs.FilesSyncJob;
import com.owncloud.android.jobs.MediaFoldersDetectionJob;
import com.owncloud.android.jobs.NotificationJob;
import com.owncloud.android.ui.adapter.SyncedFolderAdapter;
Expand Down Expand Up @@ -382,6 +384,7 @@ private SyncedFolderDisplayItem createSyncedFolderWithoutMediaFolder(@NonNull Sy
syncedFolder.getRemotePath(),
syncedFolder.getWifiOnly(),
syncedFolder.getChargingOnly(),
syncedFolder.getExisting(),
syncedFolder.getSubfolderByDate(),
syncedFolder.getAccount(),
syncedFolder.getUploadAction(),
Expand All @@ -407,6 +410,7 @@ private SyncedFolderDisplayItem createSyncedFolder(@NonNull SyncedFolder syncedF
syncedFolder.getRemotePath(),
syncedFolder.getWifiOnly(),
syncedFolder.getChargingOnly(),
syncedFolder.getExisting(),
syncedFolder.getSubfolderByDate(),
syncedFolder.getAccount(),
syncedFolder.getUploadAction(),
Expand All @@ -432,7 +436,8 @@ private SyncedFolderDisplayItem createSyncedFolderFromMediaFolder(@NonNull Media
true,
false,
false,
getAccount().name,
false,
getAccount().name,
FileUploader.LOCAL_BEHAVIOUR_FORGET,
false,
mediaFolder.filePaths,
Expand Down Expand Up @@ -518,7 +523,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
Log.d(TAG, "Show custom folder dialog");
SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
SyncedFolder.UNPERSISTED_ID, null, null, true, false,
false, getAccount().name,
false,false, getAccount().name,
FileUploader.LOCAL_BEHAVIOUR_FORGET, false, null, MediaFolderType.CUSTOM);
onSyncFolderSettingsClick(0, emptyCustomFolder);
}
Expand Down Expand Up @@ -608,51 +613,61 @@ 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.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(),
syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.getEnabled(),
new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType());
syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getExisting(),
syncedFolder.getSubfolderByDate(), syncedFolder.getAccount(), syncedFolder.getUploadAction(),
syncedFolder.getEnabled(), new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType());
long storedId = mSyncedFolderProvider.storeSyncedFolder(newCustomFolder);
if (storedId != -1) {
newCustomFolder.setId(storedId);
if (newCustomFolder.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(newCustomFolder);
} else {
if (!newCustomFolder.isEnabled() || newCustomFolder.getExisting()) {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + newCustomFolder.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
}
if (newCustomFolder.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(newCustomFolder);
}
}
mAdapter.addSyncFolderItem(newCustomFolder);
} else {
SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder
.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder
.getUploadAction(), syncedFolder.getEnabled());
.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getExisting(), syncedFolder.getSubfolderByDate(),
syncedFolder.getUploadAction(), syncedFolder.getEnabled());

if (syncedFolder.getId() == UNPERSISTED_ID) {
// newly set up folder sync config
long storedId = mSyncedFolderProvider.storeSyncedFolder(item);
if (storedId != -1) {
item.setId(storedId);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
} else {
if (!item.isEnabled() || item.getExisting()) {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
}
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
}
}
} else {
// existing synced folder setup to be updated
mSyncedFolderProvider.updateSyncFolder(item);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
} else {
if (!item.isEnabled() || item.getExisting()) {
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
}
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
}
}

mAdapter.setSyncFolderItem(syncedFolder.getSection(), item);
}
if (syncedFolder.getEnabled() && syncedFolder.getExisting()) {
new JobRequest.Builder(FilesSyncJob.TAG)
.setExact(1_000L)
.setUpdateCurrent(false)
.build()
.schedule();
}

mSyncedFolderPreferencesDialogFragment = null;

Expand Down Expand Up @@ -680,6 +695,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 @@ -690,13 +706,15 @@ private SyncedFolderDisplayItem updateSyncedFolderItem(SyncedFolderDisplayItem i
String remotePath,
Boolean wifiOnly,
Boolean chargingOnly,
Boolean existing,
Boolean subfolderByDate,
Integer uploadAction,
Boolean enabled) {
item.setLocalPath(localPath);
item.setRemotePath(remotePath);
item.setWifiOnly(wifiOnly);
item.setChargingOnly(chargingOnly);
item.setExisting(existing);
item.setSubfolderByDate(subfolderByDate);
item.setUploadAction(uploadAction);
item.setEnabled(enabled);
Expand Down Expand Up @@ -724,6 +742,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String permissi
}
}


@Override
protected void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
private SwitchCompat mEnabledSwitch;
private AppCompatCheckBox mUploadOnWifiCheckbox;
private AppCompatCheckBox mUploadOnChargingCheckbox;
private AppCompatCheckBox mUploadExistingCheckbox;
private AppCompatCheckBox mUploadUseSubfoldersCheckbox;
private TextView mUploadBehaviorSummary;
private TextView mLocalFolderPath;
Expand Down Expand Up @@ -189,6 +190,9 @@ private void setupDialogElements(View view) {
ThemeUtils.tintCheckbox(mUploadOnChargingCheckbox, accentColor);
}

mUploadExistingCheckbox = view.findViewById(R.id.setting_instant_upload_existing_checkbox);
ThemeUtils.tintCheckbox(mUploadExistingCheckbox, accentColor);

mUploadUseSubfoldersCheckbox = view.findViewById(
R.id.setting_instant_upload_path_use_subfolders_checkbox);
ThemeUtils.tintCheckbox(mUploadUseSubfoldersCheckbox, accentColor);
Expand Down Expand Up @@ -227,6 +231,7 @@ private void setupDialogElements(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mUploadOnChargingCheckbox.setChecked(mSyncedFolder.getChargingOnly());
}
mUploadExistingCheckbox.setChecked(mSyncedFolder.getExisting());
mUploadUseSubfoldersCheckbox.setChecked(mSyncedFolder.getSubfolderByDate());

mUploadBehaviorSummary.setText(mUploadBehaviorItemStrings[mSyncedFolder.getUploadActionInteger()]);
Expand Down Expand Up @@ -318,6 +323,9 @@ private void setupViews(View view, boolean enable) {
view.findViewById(R.id.setting_instant_upload_on_charging_container).setAlpha(alpha);
}

view.findViewById(R.id.setting_instant_upload_existing_container).setEnabled(enable);
view.findViewById(R.id.setting_instant_upload_existing_container).setAlpha(alpha);

view.findViewById(R.id.setting_instant_upload_path_use_subfolders_container).setEnabled(enable);
view.findViewById(R.id.setting_instant_upload_path_use_subfolders_container).setAlpha(alpha);

Expand Down Expand Up @@ -361,6 +369,15 @@ public void onClick(View v) {
});
}

view.findViewById(R.id.setting_instant_upload_existing_container).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
mSyncedFolder.setExisting(!mSyncedFolder.getExisting());
mUploadExistingCheckbox.toggle();
}
});

view.findViewById(R.id.setting_instant_upload_path_use_subfolders_container).setOnClickListener(
new OnClickListener() {
@Override
Expand Down
Loading