Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Nov 1, 2024
2 parents cb24b05 + ff060ef commit 12754c0
Show file tree
Hide file tree
Showing 40 changed files with 304 additions and 79 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Source code of app:
XML (layout) file:
```xml
<!--
~ Nextcloud Talk - Android Client
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2024 Your name <[email protected]>
~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
Expand Down
2 changes: 1 addition & 1 deletion app/lint.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Nextcloud Talk - Android Client
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
~ SPDX-FileCopyrightText: 2022 Andy Scherzinger <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ class BackgroundJobFactory @Inject constructor(
params,
accountManager,
powerManagementService,
connectivityService
connectivityService,
preferences
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,6 @@ interface BackgroundJobManager {
fun bothFilesSyncJobsRunning(syncedFolderID: Long): Boolean
fun startOfflineOperations()
fun startPeriodicallyOfflineOperation()
fun scheduleInternal2WaySync()
fun scheduleInternal2WaySync(intervalMinutes: Long)
fun cancelInternal2WaySyncJob()
}
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,17 @@ internal class BackgroundJobManagerImpl(
)
}

override fun scheduleInternal2WaySync() {
override fun scheduleInternal2WaySync(intervalMinutes: Long) {
val request = periodicRequestBuilder(
jobClass = InternalTwoWaySyncWork::class,
jobName = JOB_INTERNAL_TWO_WAY_SYNC
jobName = JOB_INTERNAL_TWO_WAY_SYNC,
intervalMins = intervalMinutes
).build()

workManager.enqueueUniquePeriodicWork(JOB_INTERNAL_TWO_WAY_SYNC, ExistingPeriodicWorkPolicy.KEEP, request)
workManager.enqueueUniquePeriodicWork(JOB_INTERNAL_TWO_WAY_SYNC, ExistingPeriodicWorkPolicy.UPDATE, request)
}

override fun cancelInternal2WaySyncJob() {
workManager.cancelJob(JOB_INTERNAL_TWO_WAY_SYNC)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.work.WorkerParameters
import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.MainApp
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
Expand All @@ -21,13 +22,14 @@ import com.owncloud.android.operations.SynchronizeFolderOperation
import com.owncloud.android.utils.FileStorageUtils
import java.io.File

@Suppress("Detekt.NestedBlockDepth", "ReturnCount")
@Suppress("Detekt.NestedBlockDepth", "ReturnCount", "LongParameterList")
class InternalTwoWaySyncWork(
private val context: Context,
params: WorkerParameters,
private val userAccountManager: UserAccountManager,
private val powerManagementService: PowerManagementService,
private val connectivityService: ConnectivityService
private val connectivityService: ConnectivityService,
private val appPreferences: AppPreferences
) : Worker(context, params) {
private var shouldRun = true

Expand All @@ -36,7 +38,9 @@ class InternalTwoWaySyncWork(

var result = true

if (powerManagementService.isPowerSavingEnabled ||
@Suppress("ComplexCondition")
if (!appPreferences.isTwoWaySyncEnabled ||
powerManagementService.isPowerSavingEnabled ||
!connectivityService.isConnected ||
connectivityService.isInternetWalled ||
!connectivityService.connectivity.isWifi
Expand All @@ -61,13 +65,6 @@ class InternalTwoWaySyncWork(
return checkFreeSpaceResult
}

// do not attempt to sync root folder
if (folder.remotePath == OCFile.ROOT_PATH) {
folder.internalFolderSyncTimestamp = -1L
fileDataStorageManager.saveFile(folder)
continue
}

Log_OC.d(TAG, "Folder ${folder.remotePath}: started!")
val operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager)
.execute(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,10 @@ default void onDarkThemeModeChanged(DarkMode mode) {

@NonNull
String getLastSelectedMediaFolder();

void setTwoWaySyncStatus(boolean value);
boolean isTwoWaySyncEnabled();

void setTwoWaySyncInterval(Long value);
Long getTwoWaySyncInterval();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public final class AppPreferencesImpl implements AppPreferences {
private static final String PREF__STORAGE_PERMISSION_REQUESTED = "storage_permission_requested";
private static final String PREF__IN_APP_REVIEW_DATA = "in_app_review_data";

private static final String PREF__TWO_WAY_STATUS = "two_way_sync_status";
private static final String PREF__TWO_WAY_SYNC_INTERVAL = "two_way_sync_interval";

private static final String LOG_ENTRY = "log_entry";

private final Context context;
Expand Down Expand Up @@ -789,4 +792,24 @@ public void setLastSelectedMediaFolder(@NonNull String path) {
public String getLastSelectedMediaFolder() {
return preferences.getString(PREF__MEDIA_FOLDER_LAST_PATH, OCFile.ROOT_PATH);
}

@Override
public void setTwoWaySyncStatus(boolean value) {
preferences.edit().putBoolean(PREF__TWO_WAY_STATUS, value).apply();
}

@Override
public boolean isTwoWaySyncEnabled() {
return preferences.getBoolean(PREF__TWO_WAY_STATUS, true);
}

@Override
public void setTwoWaySyncInterval(Long value) {
preferences.edit().putLong(PREF__TWO_WAY_SYNC_INTERVAL, value).apply();
}

@Override
public Long getTwoWaySyncInterval() {
return preferences.getLong(PREF__TWO_WAY_SYNC_INTERVAL, 15L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ import android.os.Handler
import android.os.Looper
import android.widget.Toast
import com.google.common.io.Resources
import com.owncloud.android.R
import com.owncloud.android.datamodel.ReceiverFlag

fun Context.hourPlural(hour: Int): String = resources.getQuantityString(R.plurals.hours, hour, hour)

fun Context.minPlural(min: Int): String = resources.getQuantityString(R.plurals.minutes, min, min)

@SuppressLint("UnspecifiedRegisterReceiverFlag")
fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,11 @@ public void onCreate() {
backgroundJobManager.scheduleMediaFoldersDetectionJob();
backgroundJobManager.startMediaFoldersDetectionJob();
backgroundJobManager.schedulePeriodicHealthStatus();
backgroundJobManager.scheduleInternal2WaySync();

if (preferences.isTwoWaySyncEnabled()) {
backgroundJobManager.scheduleInternal2WaySync(preferences.getTwoWaySyncInterval());
}

backgroundJobManager.startPeriodicallyOfflineOperation();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,10 @@ public List<OCFile> getInternalTwoWaySyncFolders(User user) {
List<OCFile> files = new ArrayList<>(fileEntities.size());

for (FileEntity fileEntity : fileEntities) {
files.add(createFileInstance(fileEntity));
OCFile file = createFileInstance(fileEntity);
if (file.isFolder() && !file.isRootDirectory()) {
files.add(file);
}
}

return files;
Expand Down
Loading

0 comments on commit 12754c0

Please sign in to comment.