Эх сурвалжийг харах

ADD: [instantupload] setting to also upload existing files

Signed-off-by: Chris Koying Browet <cbro@semperpax.com>
Chris Koying Browet 6 жил өмнө
parent
commit
1b7bd72c49

+ 1 - 1
src/main/java/com/owncloud/android/MainApp.java

@@ -773,7 +773,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
 
                 for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
                     if (syncedFolder.isEnabled()) {
-                        FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder);
+                        FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder, true);
                     }
                 }
 

+ 7 - 2
src/main/java/com/owncloud/android/datamodel/SyncedFolder.java

@@ -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;
@@ -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
@@ -66,6 +68,7 @@ public class SyncedFolder implements Serializable, Cloneable {
                         String remotePath,
                         boolean wifiOnly,
                         boolean chargingOnly,
+                        boolean existing,
                         boolean subfolderByDate,
                         String account,
                         int uploadAction,
@@ -73,8 +76,8 @@ public class SyncedFolder implements Serializable, Cloneable {
                         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);
     }
 
     /**
@@ -87,6 +90,7 @@ public class SyncedFolder implements Serializable, Cloneable {
                            String remotePath,
                            boolean wifiOnly,
                            boolean chargingOnly,
+                           boolean existing,
                            boolean subfolderByDate,
                            String account,
                            int uploadAction,
@@ -99,6 +103,7 @@ public class SyncedFolder implements Serializable, Cloneable {
         this.remotePath = remotePath;
         this.wifiOnly = wifiOnly;
         this.chargingOnly = chargingOnly;
+        this.existing = existing;
         this.subfolderByDate = subfolderByDate;
         this.account = account;
         this.uploadAction = uploadAction;

+ 7 - 4
src/main/java/com/owncloud/android/datamodel/SyncedFolderDisplayItem.java

@@ -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
@@ -60,6 +61,7 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
                                    String remotePath,
                                    boolean wifiOnly,
                                    boolean chargingOnly,
+                                   boolean existing,
                                    boolean subfolderByDate,
                                    String account,
                                    int uploadAction,
@@ -70,8 +72,8 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
                                    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;
@@ -82,14 +84,15 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
                                    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;
     }
 }

+ 6 - 2
src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java

@@ -342,6 +342,8 @@ public class SyncedFolderProvider extends Observable {
                     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(
@@ -357,8 +359,9 @@ public class SyncedFolderProvider extends Observable {
             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;
     }
@@ -376,6 +379,7 @@ public class SyncedFolderProvider extends Observable {
         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());

+ 2 - 1
src/main/java/com/owncloud/android/db/ProviderMeta.java

@@ -31,7 +31,7 @@ import com.owncloud.android.MainApp;
  */
 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
@@ -223,6 +223,7 @@ public class ProviderMeta {
         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";

+ 1 - 1
src/main/java/com/owncloud/android/jobs/FilesSyncJob.java

@@ -131,7 +131,7 @@ public class FilesSyncJob extends Job {
                                             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();

+ 19 - 0
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -830,6 +830,7 @@ public class FileContentProvider extends ContentProvider {
                        + 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
@@ -2104,6 +2105,24 @@ public class FileContentProvider extends ContentProvider {
             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));
+            }
         }
     }
 }

+ 18 - 10
src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java

@@ -416,6 +416,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
                 syncedFolder.getRemotePath(),
                 syncedFolder.isWifiOnly(),
                 syncedFolder.isChargingOnly(),
+                syncedFolder.isExisting(),
                 syncedFolder.isSubfolderByDate(),
                 syncedFolder.getAccount(),
                 syncedFolder.getUploadAction(),
@@ -443,6 +444,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
                 syncedFolder.getRemotePath(),
                 syncedFolder.isWifiOnly(),
                 syncedFolder.isChargingOnly(),
+                syncedFolder.isExisting(),
                 syncedFolder.isSubfolderByDate(),
                 syncedFolder.getAccount(),
                 syncedFolder.getUploadAction(),
@@ -470,6 +472,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
                 true,
                 false,
                 false,
+                false,
                 getAccount().name,
                 FileUploader.LOCAL_BEHAVIOUR_FORGET,
                 false,
@@ -577,7 +580,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
             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);
@@ -619,7 +622,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         }
 
         if (syncedFolderDisplayItem.isEnabled()) {
-            FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolderDisplayItem);
+            FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolderDisplayItem, true);
 
             showBatteryOptimizationInfo();
         }
@@ -709,18 +712,20 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         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);
 
@@ -743,7 +748,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
             // 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();
 
@@ -761,7 +766,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         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);
@@ -788,6 +793,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
      * @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
@@ -798,6 +804,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
                                                            String remotePath,
                                                            boolean wifiOnly,
                                                            boolean chargingOnly,
+                                                           boolean existing,
                                                            boolean subfolderByDate,
                                                            Integer uploadAction,
                                                            boolean enabled) {
@@ -806,6 +813,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         item.setRemotePath(remotePath);
         item.setWifiOnly(wifiOnly);
         item.setChargingOnly(chargingOnly);
+        item.setExisting(existing);
         item.setSubfolderByDate(subfolderByDate);
         item.setUploadAction(uploadAction);
         item.setEnabled(enabled, clock.getCurrentTime());

+ 17 - 0
src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java

@@ -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;
@@ -189,6 +190,9 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
             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);
@@ -227,6 +231,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
             mUploadOnChargingCheckbox.setChecked(mSyncedFolder.isChargingOnly());
         }
+        mUploadExistingCheckbox.setChecked(mSyncedFolder.isExisting());
         mUploadUseSubfoldersCheckbox.setChecked(mSyncedFolder.isSubfolderByDate());
 
         mUploadBehaviorSummary.setText(mUploadBehaviorItemStrings[mSyncedFolder.getUploadActionInteger()]);
@@ -318,6 +323,9 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
             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);
 
@@ -361,6 +369,15 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
                     });
         }
 
+        view.findViewById(R.id.setting_instant_upload_existing_container).setOnClickListener(
+              new OnClickListener() {
+                  @Override
+                  public void onClick(View v) {
+                      mSyncedFolder.setExisting(!mSyncedFolder.isExisting());
+                      mUploadExistingCheckbox.toggle();
+                  }
+              });
+
         view.findViewById(R.id.setting_instant_upload_path_use_subfolders_container).setOnClickListener(
                 new OnClickListener() {
                     @Override

+ 4 - 0
src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java

@@ -41,6 +41,7 @@ public class SyncedFolderParcelable implements Parcelable {
     @Getter @Setter private String remotePath;
     @Getter @Setter private boolean wifiOnly = false;
     @Getter @Setter private boolean chargingOnly = false;
+    @Getter @Setter private boolean existing = true;
     @Getter @Setter private boolean enabled = false;
     @Getter @Setter private boolean subfolderByDate = false;
     @Getter private Integer uploadAction;
@@ -57,6 +58,7 @@ public class SyncedFolderParcelable implements Parcelable {
         remotePath = syncedFolderDisplayItem.getRemotePath();
         wifiOnly = syncedFolderDisplayItem.isWifiOnly();
         chargingOnly = syncedFolderDisplayItem.isChargingOnly();
+        existing = syncedFolderDisplayItem.isExisting();
         enabled = syncedFolderDisplayItem.isEnabled();
         subfolderByDate = syncedFolderDisplayItem.isSubfolderByDate();
         type = syncedFolderDisplayItem.getType();
@@ -73,6 +75,7 @@ public class SyncedFolderParcelable implements Parcelable {
         remotePath = read.readString();
         wifiOnly = read.readInt()!= 0;
         chargingOnly = read.readInt() != 0;
+        existing = read.readInt() != 0;
         enabled = read.readInt() != 0;
         subfolderByDate = read.readInt() != 0;
         type = MediaFolderType.getById(read.readInt());
@@ -90,6 +93,7 @@ public class SyncedFolderParcelable implements Parcelable {
         dest.writeString(remotePath);
         dest.writeInt(wifiOnly ? 1 : 0);
         dest.writeInt(chargingOnly ? 1 : 0);
+        dest.writeInt(existing ? 1 : 0);
         dest.writeInt(enabled ? 1 : 0);
         dest.writeInt(subfolderByDate ? 1 : 0);
         dest.writeInt(type.getId());

+ 16 - 7
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -79,13 +79,13 @@ public final class FilesSyncHelper {
         // utility class -> private constructor
     }
 
-    public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
+    public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder, boolean syncNow) {
         final Context context = MainApp.getAppContext();
         final ContentResolver contentResolver = context.getContentResolver();
 
         final long enabledTimestampMs = syncedFolder.getEnabledTimestampMs();
 
-        if (syncedFolder.isEnabled() && enabledTimestampMs >= 0) {
+        if (syncedFolder.isEnabled() && (syncedFolder.isExisting() || enabledTimestampMs >= 0)) {
             MediaFolderType mediaType = syncedFolder.getType();
             if (mediaType == MediaFolderType.IMAGE) {
                 FilesSyncHelper.insertContentIntoDB(MediaStore.Images.Media.INTERNAL_CONTENT_URI
@@ -106,7 +106,7 @@ public final class FilesSyncHelper {
                         @Override
                         public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
                             File file = path.toFile();
-                            if (attrs.lastModifiedTime().toMillis() >= enabledTimestampMs) {
+                            if (syncedFolder.isExisting() || attrs.lastModifiedTime().toMillis() >= enabledTimestampMs) {
                                 filesystemDataProvider.storeOrUpdateFileValue(path.toAbsolutePath().toString(),
                                                                               attrs.lastModifiedTime().toMillis(),
                                                                               file.isDirectory(), syncedFolder);
@@ -124,17 +124,26 @@ public final class FilesSyncHelper {
                     Log_OC.e(TAG, "Something went wrong while indexing files for auto upload", e);
                 }
             }
+
+            if (syncNow) {
+                new JobRequest.Builder(FilesSyncJob.TAG)
+                    .setExact(1_000L)
+                    .setUpdateCurrent(false)
+                    .build()
+                    .schedule();
+            }
         }
     }
 
-    public static void insertAllDBEntries(AppPreferences preferences, Clock clock, boolean skipCustom) {
+    public static void insertAllDBEntries(AppPreferences preferences, Clock clock, boolean skipCustom,
+                                          boolean syncNow) {
         final Context context = MainApp.getAppContext();
         final ContentResolver contentResolver = context.getContentResolver();
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver, preferences, clock);
 
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
-            if (syncedFolder.isEnabled() && (MediaFolderType.CUSTOM != syncedFolder.getType() || !skipCustom)) {
-                insertAllDBEntriesForSyncedFolder(syncedFolder);
+            if (syncedFolder.isEnabled() && (!skipCustom || syncedFolder.getType() != MediaFolderType.CUSTOM)) {
+                insertAllDBEntriesForSyncedFolder(syncedFolder, syncNow);
             }
         }
     }
@@ -171,7 +180,7 @@ public final class FilesSyncHelper {
             while (cursor.moveToNext()) {
                 contentPath = cursor.getString(column_index_data);
                 isFolder = new File(contentPath).isDirectory();
-                if (cursor.getLong(column_index_date_modified) >= enabledTimestampMs / 1000.0) {
+                if (syncedFolder.isExisting() || cursor.getLong(column_index_date_modified) >= enabledTimestampMs / 1000.0) {
                     filesystemDataProvider.storeOrUpdateFileValue(contentPath,
                                                                   cursor.getLong(column_index_date_modified), isFolder,
                                                                   syncedFolder);

+ 50 - 0
src/main/res/layout/synced_folders_settings_layout.xml

@@ -317,6 +317,56 @@
 
             </LinearLayout>
 
+            <LinearLayout
+                android:id="@+id/setting_instant_upload_existing_container"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:baselineAligned="false"
+                android:clipToPadding="false"
+                android:gravity="center_vertical"
+                android:minHeight="?attr/listPreferredItemHeightSmall">
+
+                <RelativeLayout
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:paddingBottom="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_padding">
+
+                    <TextView
+                        android:id="@+id/setting_instant_upload_existing_label"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:ellipsize="marquee"
+                        android:singleLine="true"
+                        android:text="@string/instant_upload_existing"
+                        android:textAppearance="?attr/textAppearanceListItem"/>
+
+                </RelativeLayout>
+
+                <LinearLayout
+                    android:id="@+id/setting_instant_upload_existing"
+                    android:layout_width="wrap_content"
+                    android:layout_height="match_parent"
+                    android:gravity="end|center_vertical"
+                    android:orientation="vertical"
+                    android:paddingLeft="@dimen/standard_padding"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingRight="@dimen/zero"
+                    android:paddingEnd="@dimen/zero">
+
+                    <androidx.appcompat.widget.AppCompatCheckBox
+                        android:id="@+id/setting_instant_upload_existing_checkbox"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:background="@null"
+                        android:clickable="false"
+                        android:focusable="false"/>
+
+                </LinearLayout>
+
+            </LinearLayout>
+
             <LinearLayout
                 android:id="@+id/setting_instant_upload_path_use_subfolders_container"
                 android:layout_width="match_parent"

+ 1 - 0
src/main/res/values/strings.xml

@@ -323,6 +323,7 @@
 
     <string name="auto_upload_on_wifi">Only upload on unmetered Wi-Fi</string>
     <string name="instant_upload_on_charging">Only upload when charging</string>
+    <string name="instant_upload_existing">Also upload existing files</string>
     <string name="instant_upload_path">/InstantUpload</string>
     <string name="auto_upload_path">/AutoUpload</string>
     <string name="conflict_title">File conflict</string>

+ 1 - 0
src/test/java/com/owncloud/android/ui/activity/SyncedFoldersActivityTest.java

@@ -164,6 +164,7 @@ public class SyncedFoldersActivityTest {
                                            true,
                                            true,
                                            true,
+                                           true,
                                            "test@nextcloud.com",
                                            1,
                                            enabled,