From 29685d52dc72fcf94eec5a81cf14bf25ef0a0b31 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 11 Jul 2023 17:08:23 +0200 Subject: [PATCH 1/3] remove useless field from AppConstants --- .../AccountRemoveCallbackReceiver.java | 4 ++-- .../e/drive/utils/AppConstants.java | 16 ++++---------- .../foundation/e/drive/utils/CommonUtils.java | 8 +++---- .../e/drive/work/FirstStartWorker.java | 4 ++-- .../e/drive/services/AbstractServiceIT.java | 22 +++++++++---------- .../e/drive/services/ObserverServiceTest.java | 4 +--- 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java index c4b08a69..fc7293f7 100644 --- a/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java @@ -8,7 +8,7 @@ package foundation.e.drive.receivers; -import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; +import static foundation.e.drive.utils.AppConstants.INITIAL_FOLDER_NUMBER; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; import android.accounts.AccountManager; @@ -115,7 +115,7 @@ public class AccountRemoveCallbackReceiver extends BroadcastReceiver { prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) .remove(AccountManager.KEY_ACCOUNT_TYPE) .remove(INITIALIZATION_HAS_BEEN_DONE) - .remove(INITIALFOLDERS_NUMBER) + .remove(INITIAL_FOLDER_NUMBER) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); } diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java index 1c9da75a..6b45bbac 100644 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.java @@ -9,11 +9,7 @@ package foundation.e.drive.utils; -import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; - import android.os.Build; -import android.os.Environment; - import java.text.SimpleDateFormat; import java.util.Locale; @@ -25,15 +21,14 @@ import foundation.e.drive.BuildConfig; */ public abstract class AppConstants { - public static final String MEDIASYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.MediasSyncProvider"; - public static final String SETTINGSYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.SettingsSyncProvider"; + public static final String MEDIA_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.MediasSyncProvider"; + public static final String SETTINGS_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.SettingsSyncProvider"; public static final String METERED_NETWORK_ALLOWED_AUTHORITY = "foundation.e.drive.providers.MeteredConnectionAllowedProvider"; public static final String INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"; - public static final String INITIALFOLDERS_NUMBER = "initial_folder_number"; + public static final String INITIAL_FOLDER_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 KEY_LAST_SYNC_TIME = "lastSyncTimestamp"; - public static final String ACCOUNT_DATA_NAME = "display_name"; public static final String ACCOUNT_DATA_USED_QUOTA_KEY = "used_quota"; public static final String ACCOUNT_DATA_TOTAL_QUOTA_KEY = "total_quota"; @@ -42,9 +37,6 @@ public abstract class AppConstants { public static final String ACCOUNT_DATA_ALIAS_KEY = "alias"; public static final String ACCOUNT_DATA_EMAIL = "email"; public static final String ACCOUNT_USER_ID_KEY = "USERID"; - public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"}; - public static final String[] SETTINGS_SYNCABLE_CATEGORIES = new String[]{"Rom settings"}; - public static final String notificationChannelID = "foundation.e.drive"; public static final String WORK_GENERIC_TAG = "eDrive"; public static final String WORK_INITIALIZATION_TAG = "eDrive-init"; @@ -60,4 +52,4 @@ public abstract class AppConstants { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); return sdf.format(ts); } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java index 1ffb3a1e..80dc0c73 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -44,9 +44,9 @@ import foundation.e.drive.work.AccountUserInfoWorker; import foundation.e.drive.work.WorkRequestFactory; import timber.log.Timber; -import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.MEDIA_SYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.METERED_NETWORK_ALLOWED_AUTHORITY; -import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNC_PROVIDER_AUTHORITY; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -137,7 +137,7 @@ public abstract class CommonUtils { * @return true if media sync enabled */ public static boolean isMediaSyncEnabled(@NonNull Account account) { - return ContentResolver.getSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY); + return ContentResolver.getSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY); } /** @@ -147,7 +147,7 @@ public abstract class CommonUtils { * @return true if enabled */ public static boolean isSettingsSyncEnabled(@NonNull Account account) { - return ContentResolver.getSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY); + return ContentResolver.getSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY); } /** 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 7cdbf4f1..0f960a4f 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -8,7 +8,7 @@ package foundation.e.drive.work; -import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; +import static foundation.e.drive.utils.AppConstants.INITIAL_FOLDER_NUMBER; import static foundation.e.drive.work.WorkRequestFactory.WorkType.ONE_TIME_APP_LIST; import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_SCAN; @@ -49,7 +49,7 @@ public class FirstStartWorker extends Worker { Context.MODE_PRIVATE) .edit() .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true) - .putInt(INITIALFOLDERS_NUMBER, 9) + .putInt(INITIAL_FOLDER_NUMBER, 9) .apply(); registerPeriodicWork(appContext); diff --git a/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java b/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java index 6d82245a..c7b695cb 100644 --- a/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java +++ b/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java @@ -22,8 +22,8 @@ import foundation.e.drive.database.DbHelper; import foundation.e.drive.utils.AppConstants; import static foundation.e.drive.TestUtils.TEST_ACCOUNT_NAME; import static foundation.e.drive.TestUtils.TEST_ACCOUNT_TYPE; -import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; -import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.MEDIA_SYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNC_PROVIDER_AUTHORITY; import com.nextcloud.common.NextcloudClient; @@ -70,32 +70,32 @@ public abstract class AbstractServiceIT { * enable Media & settings sync */ protected void enableMediaAndSettingsSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, true); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, true); } /** * disable Media & enable settings sync */ protected void disableMediaSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, false); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, true); } /** * enable Media and disable settings sync */ protected void disableSettingsSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, true); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, false); } /** * disable Media & settings sync */ protected void disableMediaAndSettingsSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, false); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, false); } /** @@ -114,7 +114,7 @@ public abstract class AbstractServiceIT { sharedPreferences.edit().putBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, init_done) .putString(AccountManager.KEY_ACCOUNT_NAME, TEST_ACCOUNT_NAME) .putString(AccountManager.KEY_ACCOUNT_TYPE, TEST_ACCOUNT_TYPE) - .putInt(AppConstants.INITIALFOLDERS_NUMBER, initial_folder_number) + .putInt(AppConstants.INITIAL_FOLDER_NUMBER, initial_folder_number) .putLong(AppConstants.KEY_LAST_SYNC_TIME, last_sync_time) .apply(); } diff --git a/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java index 2a25755e..bb9ff1ad 100644 --- a/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java +++ b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation; @@ -34,7 +33,6 @@ import static foundation.e.drive.TestUtils.TEST_LOCAL_ROOT_FOLDER_PATH; import static foundation.e.drive.TestUtils.TEST_REMOTE_ROOT_FOLDER_PATH; import static foundation.e.drive.TestUtils.getValidAccount; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; -import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -97,7 +95,7 @@ public class ObserverServiceTest extends AbstractServiceIT { }catch(SecurityException e){ fail(e.getMessage()); } - final SyncedFolder sFolder = new SyncedFolder(MEDIA_SYNCABLE_CATEGORIES[0], TEST_LOCAL_ROOT_FOLDER_PATH, TEST_REMOTE_ROOT_FOLDER_PATH, true); + final SyncedFolder sFolder = new SyncedFolder("Images", TEST_LOCAL_ROOT_FOLDER_PATH, TEST_REMOTE_ROOT_FOLDER_PATH, true); return sFolder; } -- GitLab From dba1a33eac17f3141c006dfcc882bc8c9f80bf8c Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 11 Jul 2023 17:32:12 +0200 Subject: [PATCH 2/3] convert AppConstant.java into kotlin --- .../e/drive/utils/AppConstants.java | 55 ------------------- .../foundation/e/drive/utils/AppConstants.kt | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 55 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/utils/AppConstants.java create mode 100644 app/src/main/java/foundation/e/drive/utils/AppConstants.kt diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java deleted file mode 100644 index 6b45bbac..00000000 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © CLEUS SAS 2018-2019. - * Copyright © ECORP SAS 2022-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.os.Build; -import java.text.SimpleDateFormat; -import java.util.Locale; - -import foundation.e.drive.BuildConfig; - -/** - * @author Vincent Bourgmayer - * @author Abhishek Aggarwal - */ -public abstract class AppConstants { - - public static final String MEDIA_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.MediasSyncProvider"; - public static final String SETTINGS_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.SettingsSyncProvider"; - public static final String METERED_NETWORK_ALLOWED_AUTHORITY = "foundation.e.drive.providers.MeteredConnectionAllowedProvider"; - public static final String INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"; - public static final String INITIAL_FOLDER_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 KEY_LAST_SYNC_TIME = "lastSyncTimestamp"; - public static final String ACCOUNT_DATA_NAME = "display_name"; - public static final String ACCOUNT_DATA_USED_QUOTA_KEY = "used_quota"; - public static final String ACCOUNT_DATA_TOTAL_QUOTA_KEY = "total_quota"; - public static final String ACCOUNT_DATA_RELATIVE_QUOTA_KEY = "relative_quota"; - public static final String ACCOUNT_DATA_GROUPS = "group"; - public static final String ACCOUNT_DATA_ALIAS_KEY = "alias"; - public static final String ACCOUNT_DATA_EMAIL = "email"; - public static final String ACCOUNT_USER_ID_KEY = "USERID"; - public static final String notificationChannelID = "foundation.e.drive"; - public static final String WORK_GENERIC_TAG = "eDrive"; - public static final String WORK_INITIALIZATION_TAG = "eDrive-init"; - public static final String USER_AGENT = "eos(" + getBuildTime() + ")-eDrive(" + BuildConfig.VERSION_NAME + ")"; - - /** - * Get a readable OS's build date String - * - * @return Os'build date - */ - private static String getBuildTime() { - long ts = Build.TIME; - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - return sdf.format(ts); - } -} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.kt b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt new file mode 100644 index 00000000..a8613570 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt @@ -0,0 +1,55 @@ +/* + * Copyright © CLEUS SAS 2018-2019. + * Copyright © ECORP SAS 2022-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.os.Build +import foundation.e.drive.BuildConfig +import java.text.SimpleDateFormat +import java.util.Locale + +/** + * @author Vincent Bourgmayer + * @author Abhishek Aggarwal + */ +object AppConstants { + const val MEDIA_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.MediasSyncProvider" + const val SETTINGS_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.SettingsSyncProvider" + const val METERED_NETWORK_ALLOWED_AUTHORITY = + "foundation.e.drive.providers.MeteredConnectionAllowedProvider" + const val INITIALIZATION_HAS_BEEN_DONE = "initService_has_run" + const val INITIAL_FOLDER_NUMBER = "initial_folder_number" + const val APPLICATIONS_LIST_FILE_NAME = "packages_list.csv" + const val SHARED_PREFERENCE_NAME = "preferences" + const val KEY_LAST_SYNC_TIME = "lastSyncTimestamp" + const val ACCOUNT_DATA_NAME = "display_name" + const val ACCOUNT_DATA_USED_QUOTA_KEY = "used_quota" + const val ACCOUNT_DATA_TOTAL_QUOTA_KEY = "total_quota" + const val ACCOUNT_DATA_RELATIVE_QUOTA_KEY = "relative_quota" + const val ACCOUNT_DATA_GROUPS = "group" + const val ACCOUNT_DATA_ALIAS_KEY = "alias" + const val ACCOUNT_DATA_EMAIL = "email" + const val ACCOUNT_USER_ID_KEY = "USERID" + const val notificationChannelID = "foundation.e.drive" + const val WORK_GENERIC_TAG = "eDrive" + const val WORK_INITIALIZATION_TAG = "eDrive-init" + @JvmField + val USER_AGENT = "eos(" + buildTime + ")-eDrive(" + BuildConfig.VERSION_NAME + ")" + + /** + * Get a readable OS's build date String + * + * @return Os'build date + */ + private val buildTime: String + get() { + val ts = Build.TIME + val sdf = SimpleDateFormat("yyyyMMdd", Locale.getDefault()) + return sdf.format(ts) + } +} \ No newline at end of file -- GitLab From 0bf5a29b43dd7358f00e2798a5c87d8b53c8a083 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 12 Jul 2023 08:17:22 +0000 Subject: [PATCH 3/3] Apply 1 suggestion(s) to 1 file(s) --- app/src/main/java/foundation/e/drive/utils/AppConstants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.kt b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt index a8613570..9822b5b8 100644 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.kt +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt @@ -1,6 +1,6 @@ /* * Copyright © CLEUS SAS 2018-2019. - * Copyright © ECORP SAS 2022-2023. + * Copyright © MURENA SAS 2022-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 -- GitLab