Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ce17463 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Merge branch '1246-refactor-CommonUtils' into 'main'

refactor common utils

See merge request !239
parents 344e6191 a5f354d8
Loading
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -13,13 +13,14 @@ import static foundation.e.drive.models.SyncRequest.Type.UPLOAD;
import static foundation.e.drive.models.SyncedFileState.DEVICE_SCANNABLE;
import static foundation.e.drive.models.SyncedFileState.ECLOUD_SCANNABLE;
import static foundation.e.drive.models.SyncedFileState.NOT_SCANNABLE;
import static foundation.e.drive.utils.FileUtils.getLocalPath;

import android.content.Context;
import android.os.FileObserver;

import androidx.annotation.NonNull;

import com.owncloud.android.lib.resources.files.FileUtils;
import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR;

import java.io.File;

@@ -28,7 +29,6 @@ import foundation.e.drive.models.SyncRequest;
import foundation.e.drive.models.SyncedFileState;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.services.SynchronizationService;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.SynchronizationServiceConnection;
import timber.log.Timber;

@@ -125,10 +125,10 @@ public class FileEventListener {
     */
    private void handleDirectoryCreate(@NonNull File directory) {
        Timber.d("handleDirectoryCreate( %s )",directory.getAbsolutePath());
        final String parentPath = CommonUtils.getLocalPath(directory.getParentFile());
        final String parentPath = getLocalPath(directory.getParentFile());
        final SyncedFolder parentFolder = DbHelper.getSyncedFolderByLocalPath(parentPath, appContext);
        if (parentFolder != null) {
            final SyncedFolder folder = new SyncedFolder(parentFolder, directory.getName() + FileUtils.PATH_SEPARATOR, directory.lastModified(), "");
            final SyncedFolder folder = new SyncedFolder(parentFolder, directory.getName() + PATH_SEPARATOR, directory.lastModified(), "");
            DbHelper.insertSyncedFolder(folder, appContext);
        }
    }
@@ -139,7 +139,7 @@ public class FileEventListener {
     * @param directory
     */
    private void handleDirectoryCloseWrite(@NonNull File directory) {
        final String fileLocalPath = CommonUtils.getLocalPath(directory);
        final String fileLocalPath = getLocalPath(directory);
        Timber.d("handleDirectoryCloseWrite( %s )",fileLocalPath );
        final SyncedFolder folder = DbHelper.getSyncedFolderByLocalPath(fileLocalPath, appContext);
        if (folder == null) {
@@ -155,7 +155,7 @@ public class FileEventListener {
     * @param directory
     */
    private void handleDirectoryDelete(@NonNull File directory) {
        final String fileLocalPath = CommonUtils.getLocalPath(directory);
        final String fileLocalPath = getLocalPath(directory);
        Timber.d("handleDirectoryDelete( %s )", fileLocalPath);
        SyncedFolder folder = DbHelper.getSyncedFolderByLocalPath(fileLocalPath, appContext);
        if (folder == null) {
@@ -163,12 +163,12 @@ public class FileEventListener {
            final File parentFile = directory.getParentFile();
            if (parentFile == null) return;

            final String parentPath = CommonUtils.getLocalPath(parentFile);
            final String parentPath = getLocalPath(parentFile);
            final SyncedFolder parentFolder = DbHelper.getSyncedFolderByLocalPath(parentPath, appContext);
            if (parentFolder == null ) { //if parent is not in the DB
                return;
            }
            folder = new SyncedFolder(parentFolder, directory.getName()+ FileUtils.PATH_SEPARATOR, directory.lastModified(), "");
            folder = new SyncedFolder(parentFolder, directory.getName() + PATH_SEPARATOR, directory.lastModified(), "");
            folder.setEnabled(false);
            DbHelper.insertSyncedFolder(folder, appContext);
        } else if (folder.isEnabled()) {
@@ -182,13 +182,13 @@ public class FileEventListener {
     * @param file
     */
    private void handleFileCloseWrite(@NonNull File file) {
        final String fileLocalPath = CommonUtils.getLocalPath(file);
        final String fileLocalPath = getLocalPath(file);
        Timber.d("handleFileCloseWrite( %s )", fileLocalPath);
        SyncRequest request = null;
        SyncedFileState fileState = DbHelper.loadSyncedFile( appContext, fileLocalPath, true);

        if (fileState == null) { //New file discovered
            final String parentPath = CommonUtils.getLocalPath(file.getParentFile());
            final String parentPath = getLocalPath(file.getParentFile());
            SyncedFolder parentFolder = DbHelper.getSyncedFolderByLocalPath(parentPath, appContext);
            if (parentFolder == null || !parentFolder.isEnabled()) {
                Timber.d("Won't send sync request: no parent are known for new file: %s", file.getName());
@@ -201,7 +201,7 @@ public class FileEventListener {
            }

            final String remotePath = parentFolder.getRemoteFolder()+file.getName();
            fileState = new SyncedFileState(-1, file.getName(), CommonUtils.getLocalPath(file), remotePath, "", 0L, parentFolder.getId(), parentFolder.isMediaType(), scannableValue);
            fileState = new SyncedFileState(-1, file.getName(), getLocalPath(file), remotePath, "", 0L, parentFolder.getId(), parentFolder.isMediaType(), scannableValue);
            int storedId = DbHelper.manageSyncedFileStateDB(fileState, "INSERT", appContext);
            if (storedId > 0) {
                fileState.setId(storedId);
@@ -225,7 +225,7 @@ public class FileEventListener {
     * @param file
     */
    private void handleFileDelete(@NonNull File file) {
        final String fileLocalPath = CommonUtils.getLocalPath(file);
        final String fileLocalPath = getLocalPath(file);
        Timber.d("handleFileDelete( %s )",fileLocalPath);
        final SyncedFileState fileState = DbHelper.loadSyncedFile( appContext, fileLocalPath, true);
        if (fileState == null) {
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncRequest;
import foundation.e.drive.models.SyncedFileState;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.FileDiffUtils;
import foundation.e.drive.utils.FileUtils;
import timber.log.Timber;

/**
@@ -92,7 +92,7 @@ public class LocalContentScanner extends AbstractContentScanner<File>{

    @Override
    protected boolean isFileMatchingSyncedFileState(@NonNull File file, @NonNull SyncedFileState fileState) {
        final String filePath = CommonUtils.getLocalPath(file);
        final String filePath = FileUtils.getLocalPath(file);
        final String localPath = fileState.getLocalPath();

        return localPath != null && localPath.equals(filePath);
+2 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ import foundation.e.drive.models.DownloadRequest;
import foundation.e.drive.models.SyncRequest;
import foundation.e.drive.models.SyncedFileState;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.FileDiffUtils;
import foundation.e.drive.utils.FileUtils;
import timber.log.Timber;

/**
@@ -69,7 +69,7 @@ public class RemoteContentScanner extends AbstractContentScanner<RemoteFile> {
        final SyncedFolder parentDir = getParentSyncedFolder(remoteFilePath);
        if (parentDir == null) return;

        final String fileName = CommonUtils.getFileNameFromPath(remoteFilePath);
        final String fileName = FileUtils.getFileNameFromPath(remoteFilePath);

        int scannableValue = NOT_SCANNABLE;
        if (parentDir.isEnabled()) {
+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import java.util.List;

import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.FileUtils;

/**
 * Implementation of AbstractFileLister with method adapted to remote content
@@ -42,13 +42,13 @@ public class RemoteFileLister extends AbstractFileLister<RemoteFile> {
    @Override
    protected boolean skipSyncedFolder(@NonNull SyncedFolder folder) {
        return (folder.isMediaType()
                && CommonUtils.getFileNameFromPath(folder.getRemoteFolder()).startsWith("."))
                && FileUtils.getFileNameFromPath(folder.getRemoteFolder()).startsWith("."))
                || !folder.isScanRemote();
    }

    @Override
    protected boolean skipFile(@NonNull RemoteFile file) {
        final String fileName = CommonUtils.getFileNameFromPath(file.getRemotePath());
        final String fileName = FileUtils.getFileNameFromPath(file.getRemotePath());
        return fileName == null || fileName.isEmpty() || fileName.startsWith(".");
    }

@@ -66,7 +66,7 @@ public class RemoteFileLister extends AbstractFileLister<RemoteFile> {
    @Override
    @Nullable
    protected String getFileName(@NonNull RemoteFile file) {
        return CommonUtils.getFileNameFromPath(file.getRemotePath());
        return FileUtils.getFileNameFromPath(file.getRemotePath());
    }

    @Override
+6 −4
Original line number Diff line number Diff line
@@ -12,16 +12,18 @@ package foundation.e.drive.fileFilters;
import java.io.File;
import java.io.FileFilter;

import foundation.e.drive.utils.CommonUtils;

/**
 * @author Vincent Bourgmayer
 */
class MediaFileFilter implements FileFilter {
    /**
     * Only accept not hidden files:
     * Media should not be synced if they're hidden files
     * @param file File to check
     * @return true if file is accepted
     */
    @Override
    public boolean accept(File file) {
        //Return true if it's not a hidden file

        return !file.isHidden();
    }
}
Loading