diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index 9882a11d7728e0b5a40cf885c1361bb76c621b03..5929f3709885d120e5dbd7b2226bcb5b0ce0fb46 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -72,7 +72,7 @@ public class AccountsActivity extends AppCompatActivity { final AccountManager accountManager = AccountManager.get(this); final Account account = CommonUtils.getAccount(getString(R.string.eelo_account_type), accountManager); - final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, this); + final String usedQuota = accountManager.getUserData(account, ACCOUNT_DATA_USED_QUOTA_KEY); final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); @@ -156,11 +156,14 @@ public class AccountsActivity extends AppCompatActivity { } }); - Glide.with(this) - .load(client.getBaseUri() + NON_OFFICIAL_AVATAR_PATH - + client.getCredentials().getUsername() + "/" + 300) - .error(R.drawable.ic_murena_eel) - .into(binding.avatar); - binding.avatar.setVisibility(View.VISIBLE); + final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, this); + if (client != null) { + Glide.with(this) + .load(client.getBaseUri() + NON_OFFICIAL_AVATAR_PATH + + client.getCredentials().getUsername() + "/" + 300) + .error(R.drawable.ic_murena_eel) + .into(binding.avatar); + binding.avatar.setVisibility(View.VISIBLE); + } } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index 3900c261bc63e34bdc0f1484a94c1331f178bc9d..141622bc8311c27cb58e045e61dd222570a87332 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -159,6 +159,10 @@ public class UploadFileOperation extends RemoteOperation { } final NextcloudClient ncClient = DavClientProvider.getInstance().getNcClientInstance(account, context); + if (ncClient == null) { + return ResultCode.ACCOUNT_EXCEPTION; + } + final RemoteOperationResult checkQuotaResult = checkAvailableSpace(ncClient, file.length()); if (checkQuotaResult.getCode() != ResultCode.OK) { Timber.d("Impossible to check quota. Cancels upload of %s", syncedState.getLocalPath()); diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index f83eafffca8aff27c1a9032d69ff5f13549ca723..80fecd13e7feb4e1bd76123acdf5585b34abdacd 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -71,6 +71,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation Timber.tag(SynchronizationService.class.getSimpleName()); } + @SuppressWarnings("deprecation") //for OwnCloudClient @Override public int onStartCommand(@NonNull Intent intent, int flags, int startId) { Timber.v("onStartCommand()"); @@ -89,8 +90,11 @@ public class SynchronizationService extends Service implements OnRemoteOperation syncRequestQueue = new ConcurrentLinkedDeque<>(); startedSync = new ConcurrentHashMap<>(); threadPool = new Thread[workerAmount]; - //noinspection deprecation + ocClient = DavClientProvider.getInstance().getClientInstance(account, getApplicationContext()); + if (ocClient == null) { + Timber.w("ocClient is null"); + } handlerThread = new HandlerThread("syncService_onResponse"); handlerThread.start(); @@ -224,6 +228,11 @@ public class SynchronizationService extends Service implements OnRemoteOperation } private void startWorker(int threadIndex) { + if (ocClient == null) { + Timber.w("Can't start sync thread: ocClient is null"); + return; + } + if (!isNetworkAvailable()) { Timber.d("No network available: Clear syncRequestQueue"); syncRequestQueue.clear(); diff --git a/app/src/main/java/foundation/e/drive/utils/DavClientProvider.java b/app/src/main/java/foundation/e/drive/utils/DavClientProvider.java index deb1974f2c7fe083900d37a3438a7bc0c4e29046..fc8ce0006978369363b6952b06b885b1142b9d3f 100644 --- a/app/src/main/java/foundation/e/drive/utils/DavClientProvider.java +++ b/app/src/main/java/foundation/e/drive/utils/DavClientProvider.java @@ -1,5 +1,6 @@ /* * Copyright © CLEUS SAS 2019. + * 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 @@ -30,6 +31,7 @@ import timber.log.Timber; /** * @author Vincent Bourgmayer */ +@SuppressWarnings({"deprecation", "DeprecatedIsStillUsed"}) public class DavClientProvider { private final static DavClientProvider instance = new DavClientProvider(); @@ -43,29 +45,11 @@ public class DavClientProvider { private NextcloudClient ncClientInstance; @Nullable - public OwnCloudClient getClientInstance(@Nullable final Account account, @NonNull final Context ctx) { - if (ocClientInstance == null) { - try { - //Not sure below if code is used... - if (!AppConstants.USER_AGENT.equals(OwnCloudClientManagerFactory.getUserAgent())) { - OwnCloudClientManagerFactory.setUserAgent(AppConstants.USER_AGENT); - } - final Uri serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(ctx, account)); - - ocClientInstance = OwnCloudClientFactory.createOwnCloudClient(serverUri, ctx, true); - final String pwd = getAcountPwd(account, ctx); - Timber.v("name: %s \n%s", account.name, AccountManager.get(ctx).getUserData(account, AccountUtils.Constants.KEY_USER_ID)); - - ocClientInstance.setCredentials(new OwnCloudBasicCredentials(account.name, pwd)); - } catch (AccountUtils.AccountNotFoundException exception) { - Timber.e(exception); - return null; - } - } + public OwnCloudClient getClientInstance(@Nullable final Account account, @NonNull final Context context) { + if (account == null) return null; - if (ocClientInstance.getUserId() == null ) { - final String userId = AccountManager.get(ctx).getUserData(account, AppConstants.ACCOUNT_USER_ID_KEY); - ocClientInstance.setUserId(userId); + if (ocClientInstance == null) { + ocClientInstance = createOcClient(account, context); } return ocClientInstance; @@ -73,19 +57,11 @@ public class DavClientProvider { @Nullable - public NextcloudClient getNcClientInstance(@Nullable final Account account, @NonNull final Context ctx) { - Timber.v("getNcClientInstance()"); + public NextcloudClient getNcClientInstance(@Nullable final Account account, @NonNull final Context context) { + if (account == null) return null; + if (ncClientInstance == null) { - try { - final Uri serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(ctx, account)); - final String credentials = OkHttpCredentialsUtil.basic(account.name, getAcountPwd(account, ctx)); - - ncClientInstance = OwnCloudClientFactory.createNextcloudClient(serverUri, account.name, credentials, ctx, true); - } catch (AccountUtils.AccountNotFoundException exception) { - Timber.e("Can't get server URI for account: %s\n%s", account.name,exception.getMessage()); - return null; - } - ncClientInstance.setUserId(account.name); + ncClientInstance = createNcClient(account, context); } return ncClientInstance; } @@ -95,15 +71,64 @@ public class DavClientProvider { ocClientInstance = null; } + @NonNull + public static DavClientProvider getInstance() { + return instance; + } + @Nullable - private static String getAcountPwd(Account account, Context ctx) throws AccountUtils.AccountNotFoundException { - return AccountManager.get(ctx).getPassword(account); + private OwnCloudBasicCredentials getOcCredentials(@NonNull Account account, @NonNull Context context) throws AccountUtils.AccountNotFoundException { + final String pwd = AccountManager.get(context).getPassword(account); + if (pwd == null) return null; + return new OwnCloudBasicCredentials(account.name, pwd); } - /** Point d'accès pour l'instance unique du singleton */ - @NonNull - public static DavClientProvider getInstance() - { - return instance; + @Nullable + private OwnCloudClient createOcClient(@NonNull Account account, @NonNull Context context) { + OwnCloudClientManagerFactory.setUserAgent(AppConstants.USER_AGENT); + final OwnCloudClient result; + try { + final OwnCloudBasicCredentials credentials = getOcCredentials(account, context); + if (credentials == null) return null; + + final Uri serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account)); + result = OwnCloudClientFactory.createOwnCloudClient(serverUri, context, true); + result.setCredentials(credentials); + } catch (AccountUtils.AccountNotFoundException exception) { + Timber.e(exception); + return null; + } + + if (result.getUserId() == null) { + final String userId = AccountManager.get(context).getUserData(account, AppConstants.ACCOUNT_USER_ID_KEY); + result.setUserId(userId); + } + + return result; + } + + + @Nullable + private String getNcCredentials(@NonNull Account account, @NonNull Context context) throws AccountUtils.AccountNotFoundException { + final String pwd = AccountManager.get(context).getPassword(account); + if (pwd == null) return null; + return OkHttpCredentialsUtil.basic(account.name, pwd); + } + + @Nullable + private NextcloudClient createNcClient(@NonNull Account account, @NonNull Context context) { + final NextcloudClient result; + try { + final String credentials = getNcCredentials(account, context); + if (credentials == null) return null; + + final Uri serverUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, account)); + result = OwnCloudClientFactory.createNextcloudClient(serverUri, account.name, credentials, context, true); + } catch (AccountUtils.AccountNotFoundException exception) { + Timber.e("Can't get server URI for account: %s\n%s", account.name, exception.getMessage()); + return null; + } + result.setUserId(account.name); + return result; } -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java b/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java index 699b12ffe7ef31dd374efa7e40345d1a6341d560..71da229771426b739640e5e0b2d986e2c80d385c 100644 --- a/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java +++ b/app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java @@ -24,11 +24,11 @@ import java.lang.Thread.UncaughtExceptionHandler; * todo: check if still usefull or if it can be remove * @author Vincent Bourgmayer */ -public class ServiceExceptionHandler implements UncaughtExceptionHandler{ +public class ServiceExceptionHandler implements UncaughtExceptionHandler { public final static String CRASH_LOG_FOLDER = "crash-logs"; public final static String LOG_FILE_NAME_PREFIX = "eDrive-crash-"; public final static String LOG_FILE_EXTENSION = ".log"; - private UncaughtExceptionHandler defaultUEH; + private final UncaughtExceptionHandler defaultUEH; Service service; @@ -49,9 +49,9 @@ public class ServiceExceptionHandler implements UncaughtExceptionHandler{ @Override public void uncaughtException(@NonNull Thread t, @NonNull Throwable exception) { - if(isExternalStorageAvailable() && !isExternalStorageReadOnly()){ + if (isExternalStorageAvailable() && !isExternalStorageReadOnly()) { - final Long timestamp = System.currentTimeMillis(); + final long timestamp = System.currentTimeMillis(); final String fileName = LOG_FILE_NAME_PREFIX+timestamp+LOG_FILE_EXTENSION; @@ -66,9 +66,9 @@ public class ServiceExceptionHandler implements UncaughtExceptionHandler{ } } //source: https://stackoverflow.com/questions/9050962/rethrow-uncaughtexceptionhandler-exception-after-logging-it/9050990#9050990 - if(defaultUEH != null){ + if (defaultUEH != null) { defaultUEH.uncaughtException(t, exception); - }else{ + } else { System.exit(1); //Kill /e/ Drive... } } @@ -90,7 +90,8 @@ public class ServiceExceptionHandler implements UncaughtExceptionHandler{ * @param exception the exception * @return the Stacktrace as a string */ - private String getStackTraceAsString(Throwable exception){ + @NonNull + private String getStackTraceAsString(Throwable exception) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index c6f8ce2b59bc842bd007cc615c575a30e4708365..8c01a51e6755bfec3b59ca08f6ca467a603b829a 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -1,5 +1,5 @@ /* - * Copyright © ECORP SAS 2022. + * 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 @@ -103,7 +103,7 @@ public class EDriveWidget extends AppWidgetProvider { } public void updateAppWidget(@NonNull final Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); final ComponentName provider = new ComponentName(context, getClass()); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(provider); @@ -181,12 +181,13 @@ public class EDriveWidget extends AppWidgetProvider { views = new RemoteViews(context.getPackageName(), R.layout.e_drive_widget_login); } - Intent accountIntent = buildIntent(Settings.ACTION_ADD_ACCOUNT, "") + final Intent accountIntent = buildIntent(Settings.ACTION_ADD_ACCOUNT, "") .putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[]{ACCOUNT_PROVIDER_EELO}); - PendingIntent addAccountIntent = PendingIntent.getActivity(context, 0, + final PendingIntent addAccountIntent = PendingIntent.getActivity(context, 0, accountIntent, PendingIntent.FLAG_IMMUTABLE); views.setOnClickPendingIntent(R.id.login, addAccountIntent); - PendingIntent pendingIntentNewAccount = PendingIntent.getActivity(context, 0, + + final PendingIntent pendingIntentNewAccount = PendingIntent.getActivity(context, 0, buildIntent(Intent.ACTION_VIEW, ADD_ACCOUNT_WEBPAGE), PendingIntent.FLAG_IMMUTABLE); views.setOnClickPendingIntent(R.id.newAccount, pendingIntentNewAccount); views.setViewVisibility(R.id.button_container, View.VISIBLE); diff --git a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java index e112c0f393c270ebb8e1fcff685fbce925039eac..035751a0a95743a4e19d5342853e4dd4439928f6 100644 --- a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java +++ b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java @@ -1,5 +1,5 @@ /* - * Copyright © ECORP SAS 2022. + * 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 @@ -14,11 +14,11 @@ import android.content.Context; import android.content.SharedPreferences; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.work.Data; import androidx.work.Worker; import androidx.work.WorkerParameters; -//import com.nextcloud.common.NextcloudClient; //not yet supported import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation; @@ -71,14 +71,15 @@ public class CreateRemoteFolderWorker extends Worker { } final SyncedFolder syncedFolder = getSyncedFolderFromData(); + if (syncedFolder == null) return Result.failure(); + Timber.v("doWork() for : %s", syncedFolder.getLocalFolder()); final File folder = new File(syncedFolder.getLocalFolder() ); if (!folder.exists()) { folder.mkdirs(); syncedFolder.setLastModified(folder.lastModified()); } - //Not yet supported - //final NextcloudClient client = DavClientProvider.getInstance().getNcClientInstance(account, context); + final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, context); if (client == null) { Timber.d("doWork(): Can't get OwnCloudClient"); @@ -88,6 +89,7 @@ public class CreateRemoteFolderWorker extends Worker { final CreateFolderRemoteOperation mkcolRequest = new CreateFolderRemoteOperation(syncedFolder.getRemoteFolder(), true); + @SuppressWarnings("deprecation") final RemoteOperationResult result = mkcolRequest.execute(client); if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS) { DbHelper.insertSyncedFolder(syncedFolder, context); @@ -97,12 +99,20 @@ public class CreateRemoteFolderWorker extends Worker { return Result.retry(); } + @Nullable private SyncedFolder getSyncedFolderFromData() { final Data data = getInputData(); + final String category = data.getString(DATA_KEY_LIBELLE); + final String remotePath = data.getString(DATA_KEY_REMOTE_PATH); + final String localPath = data.getString(DATA_KEY_REMOTE_PATH); + + if( category == null || remotePath == null || localPath == null) { + return null; + } final SyncedFolder result = new SyncedFolder( - data.getString(DATA_KEY_LIBELLE), - data.getString(DATA_KEY_LOCAL_PATH), - data.getString(DATA_KEY_REMOTE_PATH), + category, + remotePath, + localPath, data.getBoolean(DATA_KEY_SCAN_LOCAL, true), data.getBoolean(DATA_KEY_SCAN_REMOTE, true), data.getBoolean(DATA_KEY_ENABLE, true), @@ -115,7 +125,7 @@ public class CreateRemoteFolderWorker extends Worker { return result; } - + @Nullable private Account getAccount() { final SharedPreferences prefs = getApplicationContext().getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); 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 0f960a4f53c9c361676631438aa9d3ea760edb4d..7e4c84748e48bda12aaf99f679d61e03bb5b3a89 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -43,7 +43,7 @@ public class FirstStartWorker extends Worker { Timber.v("FirstStartWorker.doWork()"); final Context appContext = getApplicationContext(); - generateFirstAppListFile(appContext); + enqueueAppListGenerationWorkRequest(appContext); appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) @@ -52,7 +52,7 @@ public class FirstStartWorker extends Worker { .putInt(INITIAL_FOLDER_NUMBER, 9) .apply(); - registerPeriodicWork(appContext); + enqueuePeriodicFileScanWorkRequest(appContext); getApplicationContext().startService(new Intent(getApplicationContext(), foundation.e.drive.services.SynchronizationService.class)); getApplicationContext().startService(new Intent(getApplicationContext(), foundation.e.drive.services.ObserverService.class)); @@ -62,13 +62,12 @@ public class FirstStartWorker extends Worker { return Result.success(); } - - private void generateFirstAppListFile(@NonNull final Context context) { + private void enqueueAppListGenerationWorkRequest(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); workManager.enqueue(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_APP_LIST, null)); } - private void registerPeriodicWork(@NonNull final Context context) { + private void enqueuePeriodicFileScanWorkRequest(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); workManager.enqueueUniquePeriodicWork(PeriodicWorker.UNIQUE_WORK_NAME, diff --git a/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java b/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java index b04e91c5f09580c9c198086ac9ebb39f76895b75..5e7feb917f408008fbb8efb5b83f08188c5de268 100644 --- a/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java +++ b/app/src/main/java/foundation/e/drive/work/ListAppsWorker.java @@ -97,7 +97,7 @@ public class ListAppsWorker extends Worker { } private boolean writeToFile(@NonNull final StringBuilder fileContents) { - try (final FileOutputStream tmp = getApplicationContext().openFileOutput(APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); + try (final FileOutputStream tmp = getApplicationContext().openFileOutput(APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE) ) { tmp.write(fileContents.toString().getBytes()); @@ -111,7 +111,7 @@ public class ListAppsWorker extends Worker { tmp_file.delete(); } } catch (IOException exception) { - Timber.e(exception, "catched exception: can't write app list in file"); + Timber.e(exception, "caught exception: can't write app list in file"); return false; } return true; 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 6331f302873ee2089349408b903dac86cc22fa56..58c87d75572934077c630a43fdcab32ba3681f54 100644 --- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java @@ -69,35 +69,34 @@ public class WorkRequestFactory { * be unmetered) and battery (shouldn't be low) * @return instance of PeriodicWorkRequest */ + @NonNull private static PeriodicWorkRequest createPeriodicScanWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); - final PeriodicWorkRequest workRequest = - new PeriodicWorkRequest.Builder(PeriodicWorker.class, + return new PeriodicWorkRequest.Builder(PeriodicWorker.class, 26, TimeUnit.MINUTES, 5, TimeUnit.MINUTES) .setConstraints(constraints) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); - return workRequest; } /** * Create a periodic work request to get userInfo * @return instance of PeriodicWorkRequest */ + @NonNull private static PeriodicWorkRequest createPeriodicGetUserInfoWorkRequest() { final Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build(); - final PeriodicWorkRequest workRequest = - new PeriodicWorkRequest.Builder(AccountUserInfoWorker.class, + return new PeriodicWorkRequest.Builder(AccountUserInfoWorker.class, 30, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .setConstraints(constraints) .build(); - return workRequest; } + /** * Build an instance of OneTimeWorkRequest depending of the work type specified. * @param type Should be ONE_TIME_USER_INFO, or FIRST_START, or CREATE_REMOTE_DIR @@ -128,6 +127,7 @@ public class WorkRequestFactory { * Create a workRequest to generate file which contains list of installed apps * @return the workRequest */ + @NonNull private static OneTimeWorkRequest createOneTimeAppListGenerationWorkRequest() { final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(ListAppsWorker.class); @@ -142,6 +142,7 @@ public class WorkRequestFactory { * be unmetered) and battery (shouldn't be low) * @return instance of OneTimeWorkRequest */ + @NonNull private static OneTimeWorkRequest createOneTimeFullScanWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); @@ -158,6 +159,7 @@ public class WorkRequestFactory { * Instanciate a OneTimeWorkRequest to retrieve user info * @return instance of OneTimeWorkRequest */ + @NonNull private static OneTimeWorkRequest createOneTimeGetUserInfoWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); @@ -176,10 +178,11 @@ public class WorkRequestFactory { * @param syncedFolder SyncedFolder instance with data about folder to create * @return Instance OneTimeWorkRequest */ + @NonNull private static OneTimeWorkRequest createOneTimeCreateRemoteFolderWorkRequest(@NonNull SyncedFolder syncedFolder) { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); - final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder( + return new OneTimeWorkRequest.Builder( CreateRemoteFolderWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .setInputData(createDataFromSyncedFolder(syncedFolder)) @@ -187,7 +190,6 @@ public class WorkRequestFactory { .addTag(AppConstants.WORK_INITIALIZATION_TAG) .setConstraints(constraints) .build(); - return workRequest; } /** @@ -195,13 +197,13 @@ public class WorkRequestFactory { * after initialization * @return Instance of OneTimeWorkRequest */ + @NonNull private static OneTimeWorkRequest createOneTimeFirstStartWorkRequest() { - final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(FirstStartWorker.class) + return new OneTimeWorkRequest.Builder(FirstStartWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .addTag(AppConstants.WORK_INITIALIZATION_TAG) .build(); - return workRequest; } /** @@ -209,12 +211,12 @@ public class WorkRequestFactory { * and battery not low * @return instance of Constraints */ + @NonNull private static Constraints createUnmeteredNetworkAndHighBatteryConstraints() { - final Constraints constraint = new Constraints.Builder() + return new Constraints.Builder() .setRequiredNetworkType(NetworkType.UNMETERED) .setRequiresBatteryNotLow(true) .build(); - return constraint; } /** @@ -222,6 +224,7 @@ public class WorkRequestFactory { * @param folder SyncedFolder instance * @return Data instance */ + @NonNull private static Data createDataFromSyncedFolder(@NonNull SyncedFolder folder) { return new Data.Builder() .putInt(DATA_KEY_ID, folder.getId()) @@ -236,4 +239,4 @@ public class WorkRequestFactory { .putBoolean(DATA_KEY_MEDIATYPE, folder.isMediaType()) .build(); } -} +} \ No newline at end of file diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index c2bb3dde051e3f791e7b8012730d992e5e9a029d..2deedbf25460b3f0680d1e8c7d408d71e308bd04 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -1,11 +1,11 @@ - + •   /e/ Drive Uppgradera Senast synkroniserat: %1$s %1$s AV %2$s ANVÄNDS - Alias + Alias Bilder och videor alias Mitt konto @@ -22,7 +22,7 @@ eDrives notiskanal Din molnlagring är full. Din molnlagring är nästan full. - 99% av din tilldelade molnlagring används. Vänligen vidta åtgärder. + 99%% av din tilldelade molnlagring används. Vänligen vidta åtgärder. Du har fyllt din tilldelade molnlagring till 90%%. Du har fyllt din tilldelade molnlagring till 80%%. Kopierade %1$s till urklipp