Loading app/src/main/java/io/eelo/drive/operations/ListRemoteFileOperation.java +6 −29 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.util.ListIterator; import io.eelo.drive.database.DbHelper; import io.eelo.drive.models.SyncedFolder; import io.eelo.drive.utils.AppConstants; /** * Loading @@ -37,11 +38,13 @@ public class ListRemoteFileOperation extends RemoteOperation { private final List<SyncedFolder> mSyncedFolders; private final Context mContext; private final int initialFolderNumber; public ListRemoteFileOperation(List<SyncedFolder> syncedFolders, Context context){ public ListRemoteFileOperation(List<SyncedFolder> syncedFolders, Context context, int initialFolderNumber){ Log.i(TAG, "Constructor of ListRemoteFileOperation"); this.mSyncedFolders = syncedFolders; this.mContext = context; this.initialFolderNumber = initialFolderNumber; } /** Loading Loading @@ -112,20 +115,16 @@ public class ListRemoteFileOperation extends RemoteOperation { }else{ //Result isn't a success if(result.getHttpCode() == 404){ //File not found atLeastOneDirAsChanged = true; syncedFolder.setToSync(true); //@TODO: tester de mettre à true et de commenter le code ci dessous, juste pour voir syncedFolder.setToSync(true); //If there is no remote file, then try to delete local one if empty. Finally remove Synced Folder from DB. File localFolder = new File(syncedFolder.getLocalFolder()); if(localFolder.exists() && localFolder.listFiles().length == 0){ localFolder.delete(); } /*if( deleteDirectory(localFolder)) { Log.d(TAG, "Removed local folder and all subelement" ); }*/ if( !localFolder.exists() ) { if (syncedFolder.getId() > -1) { //does the synced folder has been persisted? if (syncedFolder.getId() > this.initialFolderNumber/*-1*/) { //does the synced folder has been persisted? //remove it from DB int deleteResult = DbHelper.deleteSyncedFolder(syncedFolder.getId(), mContext); //int deleteResult = DbHelper.deleteSyncedFolderAndSyncedFileStates(syncedFolder.getId(), mContext); Log.d(TAG, "syncedFolder Id: "+syncedFolder.getId() + " deletion from db return " + deleteResult + " row affected"); } mSyncedFolderIterator.remove(); Loading @@ -149,26 +148,4 @@ public class ListRemoteFileOperation extends RemoteOperation { Log.v(TAG, "end of run()"); return finalResult; } /** * Delete a folder and all subelements of this folder * @param path folder to delete * @return true if folder is deleted */ private boolean deleteDirectory(File path){ if( path.exists() ) { File[] files = path.listFiles(); for(int i=-1, size = files.length; ++i<size;) { if(files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } return( path.delete() ); } return true; } } app/src/main/java/io/eelo/drive/services/InitializerService.java +6 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,9 @@ import io.eelo.drive.utils.JobUtils; import io.fabric.sdk.android.Fabric; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static io.eelo.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static io.eelo.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; import static io.eelo.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static io.eelo.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; /** * @author Vincent Bourgmayer Loading Loading @@ -126,7 +128,7 @@ public class InitializerService extends Service implements OnRemoteOperationList List<String> mSyncCategories = new ArrayList<>(); if (CommonUtils.isMediaSyncEnabled(mAccount)) { Log.d(TAG, "ContentResolver.getSyncAutomatically(account, '" + MEDIASYNC_PROVIDER_AUTHORITY + "') return true"); mSyncCategories.addAll(Arrays.asList("Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts")); mSyncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES)); } else { Log.w(TAG, "ContentResolver.getSyncAutomatically(account, '" + MEDIASYNC_PROVIDER_AUTHORITY + "') return false"); } Loading Loading @@ -268,7 +270,9 @@ public class InitializerService extends Service implements OnRemoteOperationList AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor edit = settings.edit(); edit.putBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, true).apply(); edit.putBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, true) .putInt(INITIALFOLDERS_NUMBER, mSyncedFolders.size()) .apply(); CommonUtils.sendNotification(this,this.notificationID, "Initialisation is over", android.R.drawable.stat_notify_sync_noanim); stopSelf(); }else { Loading app/src/main/java/io/eelo/drive/services/ObserverService.java +6 −6 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import io.eelo.drive.utils.IGetOCClient; import io.eelo.drive.utils.JobUtils; import io.fabric.sdk.android.Fabric; import static io.eelo.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static io.eelo.drive.utils.AppConstants.INITIALIZERSERVICE_HAS_RUN; Loading @@ -69,6 +70,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene private boolean isWorking = false; private OperationManagerService mOperationManagerService; private int initialFolderCounter; /** * ServiceConnection for binder to OperationManagerService */ Loading Loading @@ -129,6 +131,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, ""); initialFolderCounter = prefs.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0); Account mAccount = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this)); //There is no account set Loading @@ -139,6 +142,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, "") .putString(AccountManager.KEY_ACCOUNT_TYPE, "") .putBoolean(INITIALIZERSERVICE_HAS_RUN, false) .putInt(INITIALFOLDERS_NUMBER, 0) .apply(); //clear DB Loading Loading @@ -247,7 +251,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene if(remote){ Log.d(TAG+"_startScan(...)", "Going to scan remote files"); this.mSyncedFolders = DbHelper.getSyncedFolders(this); ListRemoteFileOperation loadOperation = new ListRemoteFileOperation(this.mSyncedFolders, this); ListRemoteFileOperation loadOperation = new ListRemoteFileOperation(this.mSyncedFolders, this, this.initialFolderCounter); loadOperation.execute(mClient, this, mHandler); }else{ Log.d(TAG+"_startScan(...)", "Going to scan local files"); Loading Loading @@ -421,12 +425,8 @@ public class ObserverService extends Service implements OnRemoteOperationListene MediaStore.Files.FileColumns.DATA + "=?", new String[]{CommonUtils.getLocalPath(file)}); Log.d(CURRENTTAG, "deleted rows by mediastore : "+rowAffected); //if delete failed, try another methods //if (rowAffected < 1) { //Log.d(CURRENTTAG, "first deletion trials failed"); //sometimes (it seems to be relative to file's type) mediastore don't remove local file from storage fileExists = !file.delete(); /*}else fileExists = false;*/ } if(! fileExists ) { Log.d(CURRENTTAG, file.getName()+" doesn't exists *2"); Loading app/src/main/java/io/eelo/drive/utils/AppConstants.java +5 −6 Original line number Diff line number Diff line Loading @@ -9,22 +9,21 @@ package io.eelo.drive.utils; /** * @author Vincent Bourgmayer */ //Contains some constant value public abstract class AppConstants { //public static final int EELO_SYNCHRONIZER_REQUEST_CODE = 0x01; public static final int PERMISSION_ASK_MULTIPLE_CODE = 0x01; public static final String INITIALIZERSERVICE_HAS_RUN="initService_has_run"; public static final String MEDIASYNC_PROVIDER_AUTHORITY ="io.eelo.drive.providers.MediasSyncProvider"; public static final String SETTINGSYNC_PROVIDER_AUTHORITY ="io.eelo.drive.providers.SettingsSyncProvider"; public static final String INITIALIZERSERVICE_HAS_RUN="initService_has_run"; public static final String INITIALFOLDERS_NUMBER="initial_folder_number"; public static final String APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"; public static final String SHARED_PREFERENCE_NAME ="preferences"; public static final String LOGIN_STATUS_INVALID = "Invalid status"; public static final String LOGIN_STATUS_WAITING_USER_ACTION ="Waiting for client action"; public static final String UI_NO_INTERNET ="There is no internet connexion"; public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"}; } Loading
app/src/main/java/io/eelo/drive/operations/ListRemoteFileOperation.java +6 −29 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.util.ListIterator; import io.eelo.drive.database.DbHelper; import io.eelo.drive.models.SyncedFolder; import io.eelo.drive.utils.AppConstants; /** * Loading @@ -37,11 +38,13 @@ public class ListRemoteFileOperation extends RemoteOperation { private final List<SyncedFolder> mSyncedFolders; private final Context mContext; private final int initialFolderNumber; public ListRemoteFileOperation(List<SyncedFolder> syncedFolders, Context context){ public ListRemoteFileOperation(List<SyncedFolder> syncedFolders, Context context, int initialFolderNumber){ Log.i(TAG, "Constructor of ListRemoteFileOperation"); this.mSyncedFolders = syncedFolders; this.mContext = context; this.initialFolderNumber = initialFolderNumber; } /** Loading Loading @@ -112,20 +115,16 @@ public class ListRemoteFileOperation extends RemoteOperation { }else{ //Result isn't a success if(result.getHttpCode() == 404){ //File not found atLeastOneDirAsChanged = true; syncedFolder.setToSync(true); //@TODO: tester de mettre à true et de commenter le code ci dessous, juste pour voir syncedFolder.setToSync(true); //If there is no remote file, then try to delete local one if empty. Finally remove Synced Folder from DB. File localFolder = new File(syncedFolder.getLocalFolder()); if(localFolder.exists() && localFolder.listFiles().length == 0){ localFolder.delete(); } /*if( deleteDirectory(localFolder)) { Log.d(TAG, "Removed local folder and all subelement" ); }*/ if( !localFolder.exists() ) { if (syncedFolder.getId() > -1) { //does the synced folder has been persisted? if (syncedFolder.getId() > this.initialFolderNumber/*-1*/) { //does the synced folder has been persisted? //remove it from DB int deleteResult = DbHelper.deleteSyncedFolder(syncedFolder.getId(), mContext); //int deleteResult = DbHelper.deleteSyncedFolderAndSyncedFileStates(syncedFolder.getId(), mContext); Log.d(TAG, "syncedFolder Id: "+syncedFolder.getId() + " deletion from db return " + deleteResult + " row affected"); } mSyncedFolderIterator.remove(); Loading @@ -149,26 +148,4 @@ public class ListRemoteFileOperation extends RemoteOperation { Log.v(TAG, "end of run()"); return finalResult; } /** * Delete a folder and all subelements of this folder * @param path folder to delete * @return true if folder is deleted */ private boolean deleteDirectory(File path){ if( path.exists() ) { File[] files = path.listFiles(); for(int i=-1, size = files.length; ++i<size;) { if(files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } return( path.delete() ); } return true; } }
app/src/main/java/io/eelo/drive/services/InitializerService.java +6 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,9 @@ import io.eelo.drive.utils.JobUtils; import io.fabric.sdk.android.Fabric; import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static io.eelo.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static io.eelo.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; import static io.eelo.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static io.eelo.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; /** * @author Vincent Bourgmayer Loading Loading @@ -126,7 +128,7 @@ public class InitializerService extends Service implements OnRemoteOperationList List<String> mSyncCategories = new ArrayList<>(); if (CommonUtils.isMediaSyncEnabled(mAccount)) { Log.d(TAG, "ContentResolver.getSyncAutomatically(account, '" + MEDIASYNC_PROVIDER_AUTHORITY + "') return true"); mSyncCategories.addAll(Arrays.asList("Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts")); mSyncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES)); } else { Log.w(TAG, "ContentResolver.getSyncAutomatically(account, '" + MEDIASYNC_PROVIDER_AUTHORITY + "') return false"); } Loading Loading @@ -268,7 +270,9 @@ public class InitializerService extends Service implements OnRemoteOperationList AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor edit = settings.edit(); edit.putBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, true).apply(); edit.putBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, true) .putInt(INITIALFOLDERS_NUMBER, mSyncedFolders.size()) .apply(); CommonUtils.sendNotification(this,this.notificationID, "Initialisation is over", android.R.drawable.stat_notify_sync_noanim); stopSelf(); }else { Loading
app/src/main/java/io/eelo/drive/services/ObserverService.java +6 −6 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import io.eelo.drive.utils.IGetOCClient; import io.eelo.drive.utils.JobUtils; import io.fabric.sdk.android.Fabric; import static io.eelo.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static io.eelo.drive.utils.AppConstants.INITIALIZERSERVICE_HAS_RUN; Loading @@ -69,6 +70,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene private boolean isWorking = false; private OperationManagerService mOperationManagerService; private int initialFolderCounter; /** * ServiceConnection for binder to OperationManagerService */ Loading Loading @@ -129,6 +131,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, ""); initialFolderCounter = prefs.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0); Account mAccount = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this)); //There is no account set Loading @@ -139,6 +142,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, "") .putString(AccountManager.KEY_ACCOUNT_TYPE, "") .putBoolean(INITIALIZERSERVICE_HAS_RUN, false) .putInt(INITIALFOLDERS_NUMBER, 0) .apply(); //clear DB Loading Loading @@ -247,7 +251,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene if(remote){ Log.d(TAG+"_startScan(...)", "Going to scan remote files"); this.mSyncedFolders = DbHelper.getSyncedFolders(this); ListRemoteFileOperation loadOperation = new ListRemoteFileOperation(this.mSyncedFolders, this); ListRemoteFileOperation loadOperation = new ListRemoteFileOperation(this.mSyncedFolders, this, this.initialFolderCounter); loadOperation.execute(mClient, this, mHandler); }else{ Log.d(TAG+"_startScan(...)", "Going to scan local files"); Loading Loading @@ -421,12 +425,8 @@ public class ObserverService extends Service implements OnRemoteOperationListene MediaStore.Files.FileColumns.DATA + "=?", new String[]{CommonUtils.getLocalPath(file)}); Log.d(CURRENTTAG, "deleted rows by mediastore : "+rowAffected); //if delete failed, try another methods //if (rowAffected < 1) { //Log.d(CURRENTTAG, "first deletion trials failed"); //sometimes (it seems to be relative to file's type) mediastore don't remove local file from storage fileExists = !file.delete(); /*}else fileExists = false;*/ } if(! fileExists ) { Log.d(CURRENTTAG, file.getName()+" doesn't exists *2"); Loading
app/src/main/java/io/eelo/drive/utils/AppConstants.java +5 −6 Original line number Diff line number Diff line Loading @@ -9,22 +9,21 @@ package io.eelo.drive.utils; /** * @author Vincent Bourgmayer */ //Contains some constant value public abstract class AppConstants { //public static final int EELO_SYNCHRONIZER_REQUEST_CODE = 0x01; public static final int PERMISSION_ASK_MULTIPLE_CODE = 0x01; public static final String INITIALIZERSERVICE_HAS_RUN="initService_has_run"; public static final String MEDIASYNC_PROVIDER_AUTHORITY ="io.eelo.drive.providers.MediasSyncProvider"; public static final String SETTINGSYNC_PROVIDER_AUTHORITY ="io.eelo.drive.providers.SettingsSyncProvider"; public static final String INITIALIZERSERVICE_HAS_RUN="initService_has_run"; public static final String INITIALFOLDERS_NUMBER="initial_folder_number"; public static final String APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"; public static final String SHARED_PREFERENCE_NAME ="preferences"; public static final String LOGIN_STATUS_INVALID = "Invalid status"; public static final String LOGIN_STATUS_WAITING_USER_ACTION ="Waiting for client action"; public static final String UI_NO_INTERNET ="There is no internet connexion"; public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"}; }