From e8845c55057fd3dde41f16ad69300d935c38d464 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 11:06:37 +0200 Subject: [PATCH 01/14] save idea for a further refactoring --- .../e/drive/services/InitializerService.java | 7 ++- .../e/drive/utils/RootSyncedFolderFactory.kt | 63 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 5e9f6086..ecc1ff52 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -43,6 +43,10 @@ import androidx.work.WorkManager; * @author Abhishek Aggarwal */ public class InitializerService extends Service { + private static final String LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/"; + private static final String REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + Build.BRAND + "_"+ Build.MODEL + "_" + + Build.SERIAL + "/rom_settings/"; + private Account account; @Override @@ -167,7 +171,8 @@ public class InitializerService extends Service { case "Rom settings": final String remoteFolderPath = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + Build.BRAND + "_"+ Build.MODEL + "_" + Build.SERIAL + "/rom_settings/"; - syncedFolders.add(new SyncedFolder(category, "/data/system/users/0/", remoteFolderPath, true, false, true, false)); + + syncedFolders.add(new SyncedFolder(category, LOCAL_ROM_SETTINGS_PATH, remoteFolderPath, true, false, true, false)); try{ syncedFolders.add(new SyncedFolder( category, diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt new file mode 100644 index 00000000..5ef76941 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt @@ -0,0 +1,63 @@ +package foundation.e.drive.utils + +import androidx.annotation.NonNull +import foundation.e.drive.models.SyncedFolder +import java.security.InvalidParameterException + +sealed class RootSyncedFolderFactory { + + enum class MediaCategories(val label: String) { + Images("Images"), + Movies("Movies"), + Music("Music"), + Ringtones("Ringtones"), + Documents("Documents"), + Podcasts("Podcasts") + } + + + val settingsCategories = listOf("Rom settings") + + + fun getRootSyncedFolders () { + val result = ArrayList() + + + } + + + + + fun getSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + if (MediaCategories.values().contains(category)) + return buildMediaSyncedFolder(category, localPath, remotePath) + else if (settingsCategories.contains(category)) + return buildSettingsSyncedFolder(category, localPath, remotePath) + else + throw InvalidParameterException("Invalid syncedFolder category passed as a parameter:" + category) + } + + private fun listOfMediaSyncedFolder() : List{ + val result = ArrayList() + + MediaCategories.values().forEach { + when(it) { + MediaCategories.Images -> { + result.add(buildMediaSyncedFolder(it, )) + } + } + } + + return result + } + + + private fun buildMediaSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + return SyncedFolder(category, localPath, remotePath, true) + } + + private fun buildSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + return SyncedFolder(category, localPath, remotePath, true, false, true, false) + } + +} \ No newline at end of file -- GitLab From edfda6fb5ef09d1c877b3c90180c2284b403ef74 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 15:00:58 +0200 Subject: [PATCH 02/14] move code to generate syncedFolders into a dedicated class from IntializerService --- .../e/drive/services/InitializerService.java | 84 +------------ .../e/drive/utils/RootSyncedFolderFactory.kt | 115 ++++++++++++------ 2 files changed, 83 insertions(+), 116 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index ecc1ff52..d79e5b91 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -15,24 +15,17 @@ import android.app.Service; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.os.Build; -import android.os.Environment; import android.os.IBinder; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; +import foundation.e.drive.utils.RootSyncedFolderFactory; import timber.log.Timber; -import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; -import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; -import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNCABLE_CATEGORIES; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.work.WorkManager; @@ -43,10 +36,7 @@ import androidx.work.WorkManager; * @author Abhishek Aggarwal */ public class InitializerService extends Service { - private static final String LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/"; - private static final String REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + Build.BRAND + "_"+ Build.MODEL + "_" - + Build.SERIAL + "/rom_settings/"; - + private Account account; @Override @@ -119,11 +109,7 @@ public class InitializerService extends Service { CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(this)); - final List syncCategories = new ArrayList<>(); - syncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES)); - syncCategories.addAll(Arrays.asList(SETTINGS_SYNCABLE_CATEGORIES)); - - final List syncedFolders = getInitialSyncedFolders(syncCategories); + final List syncedFolders = RootSyncedFolderFactory.INSTANCE.getSyncedFolderRoots(getApplicationContext()); final boolean recycleBinCreated = new File(AppConstants.RECYCLE_BIN_PATH).mkdirs(); if (!recycleBinCreated) Timber.w("Cannot create recycle bin. It may be already existing"); @@ -131,70 +117,6 @@ public class InitializerService extends Service { CommonUtils.registerInitializationWorkers(syncedFolders, WorkManager.getInstance(getApplicationContext()) ); } - /** - * Return a list of SyncedFolder - * @param categories categories indicating which syncedFolder to create - */ - private ArrayList getInitialSyncedFolders(List categories) { - Timber.d("getInitialSyncedFolders"); - - final ArrayList syncedFolders = new ArrayList<>(); - - for (final String category : categories) { - switch (category) { - case "Images": - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_DCIM), - "/Photos/", true)); - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_PICTURES), - "/Pictures/", true)); - break; - case "Movies": - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_MOVIES), - "/Movies/", true)); - break; - case "Music": - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_MUSIC), - "/Music/", true)); - break; - case "Ringtones": - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_RINGTONES), - "/Ringtones/", true)); - break; - case "Documents": - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_DOCUMENTS), - "/Documents/", true)); - break; - case "Podcasts": - syncedFolders.add(new SyncedFolder(category, getExternalFolder(Environment.DIRECTORY_PODCASTS), - "/Podcasts/", true)); - break; - case "Rom settings": - final String remoteFolderPath = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + Build.BRAND + "_"+ Build.MODEL + "_" - + Build.SERIAL + "/rom_settings/"; - - syncedFolders.add(new SyncedFolder(category, LOCAL_ROM_SETTINGS_PATH, remoteFolderPath, true, false, true, false)); - try{ - syncedFolders.add(new SyncedFolder( - category, - getFilesDir().getCanonicalPath() + PATH_SEPARATOR, - remoteFolderPath + "app_list/", - true, - false, - CommonUtils.isSettingsSyncEnabled(account), - false)); - } catch (Exception exception) { - Timber.e(exception); - } - break; - } - } - return syncedFolders; - } - - private String getExternalFolder(String directory) { - return CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(directory))+ PATH_SEPARATOR; - } - @Nullable @Override public IBinder onBind(Intent intent) { diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt index 5ef76941..9bf33ee2 100644 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt @@ -1,63 +1,108 @@ package foundation.e.drive.utils +import android.content.Context +import android.os.Build +import android.os.Build.BRAND +import android.os.Build.MODEL +import android.os.Environment import androidx.annotation.NonNull +import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR import foundation.e.drive.models.SyncedFolder -import java.security.InvalidParameterException - -sealed class RootSyncedFolderFactory { - - enum class MediaCategories(val label: String) { - Images("Images"), - Movies("Movies"), - Music("Music"), - Ringtones("Ringtones"), - Documents("Documents"), - Podcasts("Podcasts") - } +object RootSyncedFolderFactory { + private const val CATEGORIE_IMAGES = "Images" + private const val CATEGORIE_MOVIES = "Movies" + private const val CATEGORIE_MUSIC = "Music" + private const val CATEGORIE_RINGTONES = "Ringtones" + private const val CATEGORIE_DOCUMENTS = "Documents" + private const val CATEGORIE_PODCASTS = "Podcasts" + private const val CATEGORIE_ROM_SETTINGS = "Rom settings" + + private const val LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/" + private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.SERIAL + "/rom_settings/" + private val REMOTE_APP_LIST_PATH = REMOTE_ROM_SETTINGS_PATH + "app_list/" + + fun getSyncedFolderRoots(@NonNull context : Context): ArrayList { + val syncedFolders = ArrayList() + val categories = getSyncableCategories() + + categories.forEach { + when (it) { + CATEGORIE_IMAGES -> { + syncedFolders.add(createPhotosSyncedFolder()) + syncedFolders.add(createPicturesSyncedFolder()) + } + CATEGORIE_MOVIES -> syncedFolders.add(createMovieSyncedFolder()) + CATEGORIE_DOCUMENTS -> syncedFolders.add(createDocumentsSyncedFolder()) + CATEGORIE_MUSIC -> syncedFolders.add(createMusicsSyncedFolder()) + CATEGORIE_PODCASTS -> syncedFolders.add(createPodcastsSyncedFolder()) + CATEGORIE_RINGTONES -> syncedFolders.add(createRingtonesSyncedFolder()) + CATEGORIE_ROM_SETTINGS -> { + syncedFolders.add(createRomSettingsSyncedFolder()) + syncedFolders.add(createAppListSyncedFolder(context)) + } + } + } - val settingsCategories = listOf("Rom settings") + return syncedFolders + } - fun getRootSyncedFolders () { - val result = ArrayList() + private fun getSyncableCategories(): List { + return listOf(CATEGORIE_IMAGES, + CATEGORIE_MOVIES, + CATEGORIE_MUSIC, + CATEGORIE_RINGTONES, + CATEGORIE_DOCUMENTS, + CATEGORIE_PODCASTS, + CATEGORIE_ROM_SETTINGS) + } + private fun createPhotosSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_DCIM, "/Photos/") } + private fun createPicturesSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_PICTURES, "/Pictures/") + } + private fun createMovieSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_MOVIES, Environment.DIRECTORY_MOVIES, "/Movies/") + } + private fun createDocumentsSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_DOCUMENTS, Environment.DIRECTORY_DOCUMENTS, "/Documents/") + } - fun getSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { - if (MediaCategories.values().contains(category)) - return buildMediaSyncedFolder(category, localPath, remotePath) - else if (settingsCategories.contains(category)) - return buildSettingsSyncedFolder(category, localPath, remotePath) - else - throw InvalidParameterException("Invalid syncedFolder category passed as a parameter:" + category) + private fun createMusicsSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_MUSIC, Environment.DIRECTORY_MUSIC, "/Music/") } - private fun listOfMediaSyncedFolder() : List{ - val result = ArrayList() + private fun createRingtonesSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_RINGTONES, Environment.DIRECTORY_RINGTONES, "/Ringtones/") + } - MediaCategories.values().forEach { - when(it) { - MediaCategories.Images -> { - result.add(buildMediaSyncedFolder(it, )) - } - } - } + private fun createPodcastsSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_PODCASTS, Environment.DIRECTORY_PODCASTS, "/Podcasts/") + } - return result + private fun createRomSettingsSyncedFolder(): SyncedFolder { + return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, LOCAL_ROM_SETTINGS_PATH, REMOTE_ROM_SETTINGS_PATH) } + private fun createAppListSyncedFolder(@NonNull context: Context): SyncedFolder { + val localPath = context.filesDir.absolutePath + PATH_SEPARATOR + return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, localPath, REMOTE_APP_LIST_PATH) + } - private fun buildMediaSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + private fun createMediaSyncedFolder(@NonNull category: String, @NonNull publicDirectoryType: String, @NonNull remotePath: String): SyncedFolder { + val dirPath = CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(publicDirectoryType)) + val localPath = dirPath + PATH_SEPARATOR return SyncedFolder(category, localPath, remotePath, true) } - private fun buildSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + private fun createSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { return SyncedFolder(category, localPath, remotePath, true, false, true, false) } - } \ No newline at end of file -- GitLab From 7e55c06ba6e071521950146e76e29f6c6317459d Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 16:14:31 +0200 Subject: [PATCH 03/14] add missing header and fix typos --- .../e/drive/utils/RootSyncedFolderFactory.kt | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt index 9bf33ee2..7ffbb26d 100644 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt @@ -1,3 +1,10 @@ +/* + * Copyright © MURENA SAS 2023. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ package foundation.e.drive.utils import android.content.Context @@ -5,18 +12,19 @@ import android.os.Build import android.os.Build.BRAND import android.os.Build.MODEL import android.os.Environment +import android.os.Environment.* import androidx.annotation.NonNull import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR import foundation.e.drive.models.SyncedFolder object RootSyncedFolderFactory { - private const val CATEGORIE_IMAGES = "Images" - private const val CATEGORIE_MOVIES = "Movies" - private const val CATEGORIE_MUSIC = "Music" - private const val CATEGORIE_RINGTONES = "Ringtones" - private const val CATEGORIE_DOCUMENTS = "Documents" - private const val CATEGORIE_PODCASTS = "Podcasts" - private const val CATEGORIE_ROM_SETTINGS = "Rom settings" + private const val CATEGORY_IMAGES = "Images" + private const val CATEGORY_MOVIES = "Movies" + private const val CATEGORY_MUSIC = "Music" + private const val CATEGORY_RINGTONES = "Ringtones" + private const val CATEGORY_DOCUMENTS = "Documents" + private const val CATEGORY_PODCASTS = "Podcasts" + private const val CATEGORY_ROM_SETTINGS = "Rom settings" private const val LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/" private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.SERIAL + "/rom_settings/" @@ -28,72 +36,69 @@ object RootSyncedFolderFactory { categories.forEach { when (it) { - CATEGORIE_IMAGES -> { + CATEGORY_IMAGES -> { syncedFolders.add(createPhotosSyncedFolder()) syncedFolders.add(createPicturesSyncedFolder()) } - CATEGORIE_MOVIES -> syncedFolders.add(createMovieSyncedFolder()) - CATEGORIE_DOCUMENTS -> syncedFolders.add(createDocumentsSyncedFolder()) - CATEGORIE_MUSIC -> syncedFolders.add(createMusicsSyncedFolder()) - CATEGORIE_PODCASTS -> syncedFolders.add(createPodcastsSyncedFolder()) - CATEGORIE_RINGTONES -> syncedFolders.add(createRingtonesSyncedFolder()) - CATEGORIE_ROM_SETTINGS -> { + CATEGORY_MOVIES -> syncedFolders.add(createMovieSyncedFolder()) + CATEGORY_DOCUMENTS -> syncedFolders.add(createDocumentsSyncedFolder()) + CATEGORY_MUSIC -> syncedFolders.add(createMusicsSyncedFolder()) + CATEGORY_PODCASTS -> syncedFolders.add(createPodcastsSyncedFolder()) + CATEGORY_RINGTONES -> syncedFolders.add(createRingtonesSyncedFolder()) + CATEGORY_ROM_SETTINGS -> { syncedFolders.add(createRomSettingsSyncedFolder()) syncedFolders.add(createAppListSyncedFolder(context)) } } } - - return syncedFolders } private fun getSyncableCategories(): List { - return listOf(CATEGORIE_IMAGES, - CATEGORIE_MOVIES, - CATEGORIE_MUSIC, - CATEGORIE_RINGTONES, - CATEGORIE_DOCUMENTS, - CATEGORIE_PODCASTS, - CATEGORIE_ROM_SETTINGS) + return listOf(CATEGORY_IMAGES, + CATEGORY_MOVIES, + CATEGORY_MUSIC, + CATEGORY_RINGTONES, + CATEGORY_DOCUMENTS, + CATEGORY_PODCASTS, + CATEGORY_ROM_SETTINGS) } - private fun createPhotosSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_DCIM, "/Photos/") + return createMediaSyncedFolder(CATEGORY_IMAGES, DIRECTORY_DCIM, "/Photos/") } private fun createPicturesSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_PICTURES, "/Pictures/") + return createMediaSyncedFolder(CATEGORY_IMAGES, DIRECTORY_PICTURES, "/Pictures/") } private fun createMovieSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_MOVIES, Environment.DIRECTORY_MOVIES, "/Movies/") + return createMediaSyncedFolder(CATEGORY_MOVIES, DIRECTORY_MOVIES, "/Movies/") } private fun createDocumentsSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_DOCUMENTS, Environment.DIRECTORY_DOCUMENTS, "/Documents/") + return createMediaSyncedFolder(CATEGORY_DOCUMENTS, DIRECTORY_DOCUMENTS, "/Documents/") } private fun createMusicsSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_MUSIC, Environment.DIRECTORY_MUSIC, "/Music/") + return createMediaSyncedFolder(CATEGORY_MUSIC, DIRECTORY_MUSIC, "/Music/") } private fun createRingtonesSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_RINGTONES, Environment.DIRECTORY_RINGTONES, "/Ringtones/") + return createMediaSyncedFolder(CATEGORY_RINGTONES, DIRECTORY_RINGTONES, "/Ringtones/") } private fun createPodcastsSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_PODCASTS, Environment.DIRECTORY_PODCASTS, "/Podcasts/") + return createMediaSyncedFolder(CATEGORY_PODCASTS, DIRECTORY_PODCASTS, "/Podcasts/") } private fun createRomSettingsSyncedFolder(): SyncedFolder { - return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, LOCAL_ROM_SETTINGS_PATH, REMOTE_ROM_SETTINGS_PATH) + return createSettingsSyncedFolder(CATEGORY_ROM_SETTINGS, LOCAL_ROM_SETTINGS_PATH, REMOTE_ROM_SETTINGS_PATH) } private fun createAppListSyncedFolder(@NonNull context: Context): SyncedFolder { val localPath = context.filesDir.absolutePath + PATH_SEPARATOR - return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, localPath, REMOTE_APP_LIST_PATH) + return createSettingsSyncedFolder(CATEGORY_ROM_SETTINGS, localPath, REMOTE_APP_LIST_PATH) } private fun createMediaSyncedFolder(@NonNull category: String, @NonNull publicDirectoryType: String, @NonNull remotePath: String): SyncedFolder { -- GitLab From 09f06ad881ce16d56a12bc382470bd62ff733e6d Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 16:14:31 +0200 Subject: [PATCH 04/14] add missing header and fix typos --- .../java/foundation/e/drive/utils/RootSyncedFolderFactory.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt index 7ffbb26d..cd3dc45e 100644 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt @@ -11,7 +11,6 @@ import android.content.Context import android.os.Build import android.os.Build.BRAND import android.os.Build.MODEL -import android.os.Environment import android.os.Environment.* import androidx.annotation.NonNull import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR @@ -102,7 +101,7 @@ object RootSyncedFolderFactory { } private fun createMediaSyncedFolder(@NonNull category: String, @NonNull publicDirectoryType: String, @NonNull remotePath: String): SyncedFolder { - val dirPath = CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(publicDirectoryType)) + val dirPath = CommonUtils.getLocalPath(getExternalStoragePublicDirectory(publicDirectoryType)) val localPath = dirPath + PATH_SEPARATOR return SyncedFolder(category, localPath, remotePath, true) } -- GitLab From 885e3b7be04e1fd544f59bb4cbbf85cce49a4c48 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 28 Mar 2023 09:38:32 +0200 Subject: [PATCH 05/14] apply Jonathan's suggestion --- .../e/drive/services/InitializerService.java | 4 ++-- ...Factory.kt => RootSyncedFolderProvider.kt} | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) rename app/src/main/java/foundation/e/drive/utils/{RootSyncedFolderFactory.kt => RootSyncedFolderProvider.kt} (82%) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index d79e5b91..46bfdd8d 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -23,7 +23,7 @@ import java.util.List; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.RootSyncedFolderFactory; +import foundation.e.drive.utils.RootSyncedFolderProvider; import timber.log.Timber; import androidx.annotation.NonNull; @@ -109,7 +109,7 @@ public class InitializerService extends Service { CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(this)); - final List syncedFolders = RootSyncedFolderFactory.INSTANCE.getSyncedFolderRoots(getApplicationContext()); + final List syncedFolders = RootSyncedFolderProvider.INSTANCE.getSyncedFolderRoots(getApplicationContext()); final boolean recycleBinCreated = new File(AppConstants.RECYCLE_BIN_PATH).mkdirs(); if (!recycleBinCreated) Timber.w("Cannot create recycle bin. It may be already existing"); diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt similarity index 82% rename from app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt rename to app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt index cd3dc45e..6fd12064 100644 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt @@ -11,12 +11,18 @@ import android.content.Context import android.os.Build import android.os.Build.BRAND import android.os.Build.MODEL -import android.os.Environment.* -import androidx.annotation.NonNull +import android.os.Environment +import android.os.Environment.DIRECTORY_PODCASTS +import android.os.Environment.DIRECTORY_MUSIC +import android.os.Environment.DIRECTORY_DCIM +import android.os.Environment.DIRECTORY_DOCUMENTS +import android.os.Environment.DIRECTORY_PICTURES +import android.os.Environment.DIRECTORY_RINGTONES +import android.os.Environment.DIRECTORY_MOVIES import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR import foundation.e.drive.models.SyncedFolder -object RootSyncedFolderFactory { +object RootSyncedFolderProvider { private const val CATEGORY_IMAGES = "Images" private const val CATEGORY_MOVIES = "Movies" private const val CATEGORY_MUSIC = "Music" @@ -29,7 +35,7 @@ object RootSyncedFolderFactory { private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.SERIAL + "/rom_settings/" private val REMOTE_APP_LIST_PATH = REMOTE_ROM_SETTINGS_PATH + "app_list/" - fun getSyncedFolderRoots(@NonNull context : Context): ArrayList { + fun getSyncedFolderRoots(context : Context): ArrayList { val syncedFolders = ArrayList() val categories = getSyncableCategories() @@ -95,18 +101,18 @@ object RootSyncedFolderFactory { return createSettingsSyncedFolder(CATEGORY_ROM_SETTINGS, LOCAL_ROM_SETTINGS_PATH, REMOTE_ROM_SETTINGS_PATH) } - private fun createAppListSyncedFolder(@NonNull context: Context): SyncedFolder { + private fun createAppListSyncedFolder(context: Context): SyncedFolder { val localPath = context.filesDir.absolutePath + PATH_SEPARATOR return createSettingsSyncedFolder(CATEGORY_ROM_SETTINGS, localPath, REMOTE_APP_LIST_PATH) } - private fun createMediaSyncedFolder(@NonNull category: String, @NonNull publicDirectoryType: String, @NonNull remotePath: String): SyncedFolder { - val dirPath = CommonUtils.getLocalPath(getExternalStoragePublicDirectory(publicDirectoryType)) + private fun createMediaSyncedFolder(category: String, publicDirectoryType: String, remotePath: String): SyncedFolder { + val dirPath = CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(publicDirectoryType)) val localPath = dirPath + PATH_SEPARATOR return SyncedFolder(category, localPath, remotePath, true) } - private fun createSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + private fun createSettingsSyncedFolder(category: String, localPath: String, remotePath: String): SyncedFolder { return SyncedFolder(category, localPath, remotePath, true, false, true, false) } } \ No newline at end of file -- GitLab From de08711cbd19a70c7926feea0894ae3a80914057 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 28 Mar 2023 10:23:43 +0200 Subject: [PATCH 06/14] fix way to get serial no --- app/src/main/AndroidManifest.xml | 1 + .../java/foundation/e/drive/utils/RootSyncedFolderProvider.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1c47ced4..4cf129c0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ + diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt index 6fd12064..2c3d46b9 100644 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderProvider.kt @@ -32,7 +32,7 @@ object RootSyncedFolderProvider { private const val CATEGORY_ROM_SETTINGS = "Rom settings" private const val LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/" - private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.SERIAL + "/rom_settings/" + private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.getSerial() + "/rom_settings/" private val REMOTE_APP_LIST_PATH = REMOTE_ROM_SETTINGS_PATH + "app_list/" fun getSyncedFolderRoots(context : Context): ArrayList { -- GitLab From d4c6c1e1d91430a017998e15affd34cfea35b784 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 27 Mar 2023 12:59:00 +0000 Subject: [PATCH 07/14] Apply 5 suggestion(s) to 1 file(s) --- app/src/main/java/foundation/e/drive/RecycleBin.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/RecycleBin.kt b/app/src/main/java/foundation/e/drive/RecycleBin.kt index dd893343..4252434c 100644 --- a/app/src/main/java/foundation/e/drive/RecycleBin.kt +++ b/app/src/main/java/foundation/e/drive/RecycleBin.kt @@ -25,7 +25,7 @@ import kotlin.time.toDuration * This class contains method for trashing file & cleaning the trash */ object RecycleBin { - private val DELAY_FOR_DELETION = 30.toDuration(DurationUnit.DAYS); + private val DELAY_FOR_DELETION = 30.toDuration(DurationUnit.DAYS) private val BIN_PATH = AppConstants.RECYCLE_BIN_PATH //TMP only, Need to find a way to get context /** @@ -34,7 +34,7 @@ object RecycleBin { * @return false as soon as some files that should be removed is not removed */ fun clearOldestFiles(): Boolean { - val binDir = File(BIN_PATH); + val binDir = File(BIN_PATH) if (!binDir.exists()) return true @@ -56,7 +56,7 @@ object RecycleBin { * Compute time from which file is in Bin * and return it as a Duration in days */ - private fun computeTimeInBin(@NonNull fileLastModified : Long): Duration { + private fun computeTimeInBin(fileLastModified : Long): Duration { return (System.currentTimeMillis() - fileLastModified).toDuration(DurationUnit.DAYS) } @@ -64,7 +64,7 @@ object RecycleBin { /** * put a file into the bin */ - fun trashFile(@NonNull file:File): Boolean { + fun trashFile(file: File): Boolean { File(BIN_PATH).mkdirs() //Assert that recycle bin exist if (file.exists()) { @@ -82,7 +82,7 @@ object RecycleBin { Timber.e(exception) } } - Timber.d("Can't move %s to trashbin", file.getAbsolutePath()) + Timber.d("Can't move %s to trashbin", file.absolutePath) return false } } \ No newline at end of file -- GitLab From 16c0942e2a0f2a25a3d115802626d75b66057208 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 16:04:14 +0200 Subject: [PATCH 08/14] fix Jonathan's suggestion #3 --- app/src/main/java/foundation/e/drive/RecycleBin.kt | 2 -- .../java/foundation/e/drive/services/InitializerService.java | 3 ++- .../java/foundation/e/drive/work/RecycleBinCleaningWorker.kt | 5 ++++- .../java/foundation/e/drive/work/WorkRequestFactory.java | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/RecycleBin.kt b/app/src/main/java/foundation/e/drive/RecycleBin.kt index 4252434c..197fd2ba 100644 --- a/app/src/main/java/foundation/e/drive/RecycleBin.kt +++ b/app/src/main/java/foundation/e/drive/RecycleBin.kt @@ -10,7 +10,6 @@ package foundation.e.drive -import androidx.annotation.NonNull import foundation.e.drive.utils.AppConstants import timber.log.Timber import java.io.File @@ -60,7 +59,6 @@ object RecycleBin { return (System.currentTimeMillis() - fileLastModified).toDuration(DurationUnit.DAYS) } - /** * put a file into the bin */ diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 46bfdd8d..aa468f31 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -79,7 +79,8 @@ public class InitializerService extends Service { * - Account available * @return true if condition are met */ - private boolean checkStartConditions(@NonNull final SharedPreferences prefs, @NonNull final String accountName, @NonNull final String accountType) { + private boolean checkStartConditions(@NonNull final SharedPreferences prefs, + @NonNull final String accountName, @NonNull final String accountType) { if (prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) { Timber.w("Initialization has already been done"); return false; diff --git a/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt b/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt index e560ae7c..45328ed3 100644 --- a/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt +++ b/app/src/main/java/foundation/e/drive/work/RecycleBinCleaningWorker.kt @@ -17,8 +17,11 @@ import foundation.e.drive.RecycleBin * and cleaning * @author Vincent Bourgmayer */ -const val UNIQUE_NAME = "binCleaner" + class RecycleBinCleaningWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { + companion object { + const val UNIQUE_NAME = "binCleaner" + } override fun doWork(): Result { val result = RecycleBin.clearOldestFiles() diff --git a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java index 0eeebfff..3b6a0892 100644 --- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java @@ -59,7 +59,7 @@ public class WorkRequestFactory { case PERIODIC_USER_INFO: return createPeriodicGetUserInfoWorkRequest(); case PERIODIC_CLEANING: - return createPeriodicCleaningWorkRequest(); + return createPeriodicCleaningWorkRequest(); default: throw new InvalidParameterException("Unsupported Work Type: " + type); } -- GitLab From 7329e51ada8c90d46fe9e88a995827581c9b22f4 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 16:24:41 +0200 Subject: [PATCH 09/14] fix build issue due to RecycleBinCleaningWorker's unique tag --- app/src/main/java/foundation/e/drive/work/FirstStartWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java index 894cb85d..5890e103 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -76,7 +76,7 @@ public class FirstStartWorker extends Worker { ExistingPeriodicWorkPolicy.KEEP, WorkRequestFactory.getPeriodicWorkRequest(PERIODIC_SCAN)); - workManager.enqueueUniquePeriodicWork(RecycleBinCleaningWorkerKt.UNIQUE_NAME, + workManager.enqueueUniquePeriodicWork(RecycleBinCleaningWorker.UNIQUE_NAME, ExistingPeriodicWorkPolicy.KEEP, WorkRequestFactory.getPeriodicWorkRequest(PERIODIC_CLEANING)); } -- GitLab From 4ea77e11c36b543eadb10f499e09c845ee15246f Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 28 Mar 2023 10:29:23 +0200 Subject: [PATCH 10/14] fix serial no --- .../java/foundation/e/drive/services/InitializerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index aa468f31..1ac47d01 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -117,7 +117,7 @@ public class InitializerService extends Service { CommonUtils.registerInitializationWorkers(syncedFolders, WorkManager.getInstance(getApplicationContext()) ); } - + @Nullable @Override public IBinder onBind(Intent intent) { -- GitLab From 7005b1ff454c9e5fe39562ae05254803a2c021b9 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 11:06:37 +0200 Subject: [PATCH 11/14] save idea for a further refactoring --- .../e/drive/services/InitializerService.java | 1 - .../e/drive/utils/RootSyncedFolderFactory.kt | 63 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 1ac47d01..519aa82b 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -36,7 +36,6 @@ import androidx.work.WorkManager; * @author Abhishek Aggarwal */ public class InitializerService extends Service { - private Account account; @Override diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt new file mode 100644 index 00000000..5ef76941 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt @@ -0,0 +1,63 @@ +package foundation.e.drive.utils + +import androidx.annotation.NonNull +import foundation.e.drive.models.SyncedFolder +import java.security.InvalidParameterException + +sealed class RootSyncedFolderFactory { + + enum class MediaCategories(val label: String) { + Images("Images"), + Movies("Movies"), + Music("Music"), + Ringtones("Ringtones"), + Documents("Documents"), + Podcasts("Podcasts") + } + + + val settingsCategories = listOf("Rom settings") + + + fun getRootSyncedFolders () { + val result = ArrayList() + + + } + + + + + fun getSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + if (MediaCategories.values().contains(category)) + return buildMediaSyncedFolder(category, localPath, remotePath) + else if (settingsCategories.contains(category)) + return buildSettingsSyncedFolder(category, localPath, remotePath) + else + throw InvalidParameterException("Invalid syncedFolder category passed as a parameter:" + category) + } + + private fun listOfMediaSyncedFolder() : List{ + val result = ArrayList() + + MediaCategories.values().forEach { + when(it) { + MediaCategories.Images -> { + result.add(buildMediaSyncedFolder(it, )) + } + } + } + + return result + } + + + private fun buildMediaSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + return SyncedFolder(category, localPath, remotePath, true) + } + + private fun buildSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + return SyncedFolder(category, localPath, remotePath, true, false, true, false) + } + +} \ No newline at end of file -- GitLab From b6c1dce3d79affd2f4ccb3272c4230c98b3478eb Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 27 Mar 2023 15:00:58 +0200 Subject: [PATCH 12/14] move code to generate syncedFolders into a dedicated class from IntializerService --- .../e/drive/utils/RootSyncedFolderFactory.kt | 115 ++++++++++++------ 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt index 5ef76941..9bf33ee2 100644 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt +++ b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt @@ -1,63 +1,108 @@ package foundation.e.drive.utils +import android.content.Context +import android.os.Build +import android.os.Build.BRAND +import android.os.Build.MODEL +import android.os.Environment import androidx.annotation.NonNull +import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR import foundation.e.drive.models.SyncedFolder -import java.security.InvalidParameterException - -sealed class RootSyncedFolderFactory { - - enum class MediaCategories(val label: String) { - Images("Images"), - Movies("Movies"), - Music("Music"), - Ringtones("Ringtones"), - Documents("Documents"), - Podcasts("Podcasts") - } +object RootSyncedFolderFactory { + private const val CATEGORIE_IMAGES = "Images" + private const val CATEGORIE_MOVIES = "Movies" + private const val CATEGORIE_MUSIC = "Music" + private const val CATEGORIE_RINGTONES = "Ringtones" + private const val CATEGORIE_DOCUMENTS = "Documents" + private const val CATEGORIE_PODCASTS = "Podcasts" + private const val CATEGORIE_ROM_SETTINGS = "Rom settings" + + private const val LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/" + private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.SERIAL + "/rom_settings/" + private val REMOTE_APP_LIST_PATH = REMOTE_ROM_SETTINGS_PATH + "app_list/" + + fun getSyncedFolderRoots(@NonNull context : Context): ArrayList { + val syncedFolders = ArrayList() + val categories = getSyncableCategories() + + categories.forEach { + when (it) { + CATEGORIE_IMAGES -> { + syncedFolders.add(createPhotosSyncedFolder()) + syncedFolders.add(createPicturesSyncedFolder()) + } + CATEGORIE_MOVIES -> syncedFolders.add(createMovieSyncedFolder()) + CATEGORIE_DOCUMENTS -> syncedFolders.add(createDocumentsSyncedFolder()) + CATEGORIE_MUSIC -> syncedFolders.add(createMusicsSyncedFolder()) + CATEGORIE_PODCASTS -> syncedFolders.add(createPodcastsSyncedFolder()) + CATEGORIE_RINGTONES -> syncedFolders.add(createRingtonesSyncedFolder()) + CATEGORIE_ROM_SETTINGS -> { + syncedFolders.add(createRomSettingsSyncedFolder()) + syncedFolders.add(createAppListSyncedFolder(context)) + } + } + } - val settingsCategories = listOf("Rom settings") + return syncedFolders + } - fun getRootSyncedFolders () { - val result = ArrayList() + private fun getSyncableCategories(): List { + return listOf(CATEGORIE_IMAGES, + CATEGORIE_MOVIES, + CATEGORIE_MUSIC, + CATEGORIE_RINGTONES, + CATEGORIE_DOCUMENTS, + CATEGORIE_PODCASTS, + CATEGORIE_ROM_SETTINGS) + } + private fun createPhotosSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_DCIM, "/Photos/") } + private fun createPicturesSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_PICTURES, "/Pictures/") + } + private fun createMovieSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_MOVIES, Environment.DIRECTORY_MOVIES, "/Movies/") + } + private fun createDocumentsSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_DOCUMENTS, Environment.DIRECTORY_DOCUMENTS, "/Documents/") + } - fun getSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { - if (MediaCategories.values().contains(category)) - return buildMediaSyncedFolder(category, localPath, remotePath) - else if (settingsCategories.contains(category)) - return buildSettingsSyncedFolder(category, localPath, remotePath) - else - throw InvalidParameterException("Invalid syncedFolder category passed as a parameter:" + category) + private fun createMusicsSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_MUSIC, Environment.DIRECTORY_MUSIC, "/Music/") } - private fun listOfMediaSyncedFolder() : List{ - val result = ArrayList() + private fun createRingtonesSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_RINGTONES, Environment.DIRECTORY_RINGTONES, "/Ringtones/") + } - MediaCategories.values().forEach { - when(it) { - MediaCategories.Images -> { - result.add(buildMediaSyncedFolder(it, )) - } - } - } + private fun createPodcastsSyncedFolder(): SyncedFolder { + return createMediaSyncedFolder(CATEGORIE_PODCASTS, Environment.DIRECTORY_PODCASTS, "/Podcasts/") + } - return result + private fun createRomSettingsSyncedFolder(): SyncedFolder { + return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, LOCAL_ROM_SETTINGS_PATH, REMOTE_ROM_SETTINGS_PATH) } + private fun createAppListSyncedFolder(@NonNull context: Context): SyncedFolder { + val localPath = context.filesDir.absolutePath + PATH_SEPARATOR + return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, localPath, REMOTE_APP_LIST_PATH) + } - private fun buildMediaSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + private fun createMediaSyncedFolder(@NonNull category: String, @NonNull publicDirectoryType: String, @NonNull remotePath: String): SyncedFolder { + val dirPath = CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(publicDirectoryType)) + val localPath = dirPath + PATH_SEPARATOR return SyncedFolder(category, localPath, remotePath, true) } - private fun buildSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { + private fun createSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { return SyncedFolder(category, localPath, remotePath, true, false, true, false) } - } \ No newline at end of file -- GitLab From f6500ad4171c5a032d8cf6769dd221c5fce3b1a1 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 28 Mar 2023 16:28:19 +0200 Subject: [PATCH 13/14] remove invalid class after rebasing --- .../e/drive/utils/RootSyncedFolderFactory.kt | 108 ------------------ 1 file changed, 108 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt diff --git a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt b/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt deleted file mode 100644 index 9bf33ee2..00000000 --- a/app/src/main/java/foundation/e/drive/utils/RootSyncedFolderFactory.kt +++ /dev/null @@ -1,108 +0,0 @@ -package foundation.e.drive.utils - -import android.content.Context -import android.os.Build -import android.os.Build.BRAND -import android.os.Build.MODEL -import android.os.Environment -import androidx.annotation.NonNull -import com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR -import foundation.e.drive.models.SyncedFolder - -object RootSyncedFolderFactory { - private const val CATEGORIE_IMAGES = "Images" - private const val CATEGORIE_MOVIES = "Movies" - private const val CATEGORIE_MUSIC = "Music" - private const val CATEGORIE_RINGTONES = "Ringtones" - private const val CATEGORIE_DOCUMENTS = "Documents" - private const val CATEGORIE_PODCASTS = "Podcasts" - private const val CATEGORIE_ROM_SETTINGS = "Rom settings" - - private const val LOCAL_ROM_SETTINGS_PATH = "/data/system/users/0/" - private val REMOTE_ROM_SETTINGS_PATH = PATH_SEPARATOR + "Devices" + PATH_SEPARATOR + BRAND + "_" + MODEL + "_" + Build.SERIAL + "/rom_settings/" - private val REMOTE_APP_LIST_PATH = REMOTE_ROM_SETTINGS_PATH + "app_list/" - - fun getSyncedFolderRoots(@NonNull context : Context): ArrayList { - val syncedFolders = ArrayList() - val categories = getSyncableCategories() - - categories.forEach { - when (it) { - CATEGORIE_IMAGES -> { - syncedFolders.add(createPhotosSyncedFolder()) - syncedFolders.add(createPicturesSyncedFolder()) - } - CATEGORIE_MOVIES -> syncedFolders.add(createMovieSyncedFolder()) - CATEGORIE_DOCUMENTS -> syncedFolders.add(createDocumentsSyncedFolder()) - CATEGORIE_MUSIC -> syncedFolders.add(createMusicsSyncedFolder()) - CATEGORIE_PODCASTS -> syncedFolders.add(createPodcastsSyncedFolder()) - CATEGORIE_RINGTONES -> syncedFolders.add(createRingtonesSyncedFolder()) - CATEGORIE_ROM_SETTINGS -> { - syncedFolders.add(createRomSettingsSyncedFolder()) - syncedFolders.add(createAppListSyncedFolder(context)) - } - } - } - - - return syncedFolders - } - - private fun getSyncableCategories(): List { - return listOf(CATEGORIE_IMAGES, - CATEGORIE_MOVIES, - CATEGORIE_MUSIC, - CATEGORIE_RINGTONES, - CATEGORIE_DOCUMENTS, - CATEGORIE_PODCASTS, - CATEGORIE_ROM_SETTINGS) - } - - - private fun createPhotosSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_DCIM, "/Photos/") - } - - private fun createPicturesSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_IMAGES, Environment.DIRECTORY_PICTURES, "/Pictures/") - } - - private fun createMovieSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_MOVIES, Environment.DIRECTORY_MOVIES, "/Movies/") - } - - private fun createDocumentsSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_DOCUMENTS, Environment.DIRECTORY_DOCUMENTS, "/Documents/") - } - - private fun createMusicsSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_MUSIC, Environment.DIRECTORY_MUSIC, "/Music/") - } - - private fun createRingtonesSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_RINGTONES, Environment.DIRECTORY_RINGTONES, "/Ringtones/") - } - - private fun createPodcastsSyncedFolder(): SyncedFolder { - return createMediaSyncedFolder(CATEGORIE_PODCASTS, Environment.DIRECTORY_PODCASTS, "/Podcasts/") - } - - private fun createRomSettingsSyncedFolder(): SyncedFolder { - return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, LOCAL_ROM_SETTINGS_PATH, REMOTE_ROM_SETTINGS_PATH) - } - - private fun createAppListSyncedFolder(@NonNull context: Context): SyncedFolder { - val localPath = context.filesDir.absolutePath + PATH_SEPARATOR - return createSettingsSyncedFolder(CATEGORIE_ROM_SETTINGS, localPath, REMOTE_APP_LIST_PATH) - } - - private fun createMediaSyncedFolder(@NonNull category: String, @NonNull publicDirectoryType: String, @NonNull remotePath: String): SyncedFolder { - val dirPath = CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(publicDirectoryType)) - val localPath = dirPath + PATH_SEPARATOR - return SyncedFolder(category, localPath, remotePath, true) - } - - private fun createSettingsSyncedFolder(@NonNull category: String, @NonNull localPath: String, @NonNull remotePath: String): SyncedFolder { - return SyncedFolder(category, localPath, remotePath, true, false, true, false) - } -} \ No newline at end of file -- GitLab From 537120fde32060c90e6ab976646992a4fb7c6dd6 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 29 Mar 2023 06:59:23 +0000 Subject: [PATCH 14/14] one more typo --- app/src/main/java/foundation/e/drive/RecycleBin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/RecycleBin.kt b/app/src/main/java/foundation/e/drive/RecycleBin.kt index 197fd2ba..447106bb 100644 --- a/app/src/main/java/foundation/e/drive/RecycleBin.kt +++ b/app/src/main/java/foundation/e/drive/RecycleBin.kt @@ -55,7 +55,7 @@ object RecycleBin { * Compute time from which file is in Bin * and return it as a Duration in days */ - private fun computeTimeInBin(fileLastModified : Long): Duration { + private fun computeTimeInBin(fileLastModified: Long): Duration { return (System.currentTimeMillis() - fileLastModified).toDuration(DurationUnit.DAYS) } -- GitLab