mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Proper way to schedule
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
a5a6476e00
commit
9b4b90cc8d
2 changed files with 17 additions and 9 deletions
|
@ -457,6 +457,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
if (syncedFolderDisplayItem.getId() > UNPERSISTED_ID) {
|
||||
mSyncedFolderProvider.updateSyncedFolderEnabled(syncedFolderDisplayItem.getId(),
|
||||
syncedFolderDisplayItem.isEnabled());
|
||||
FilesSyncHelper.scheduleM1Jobs();
|
||||
} else {
|
||||
long storedId = mSyncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem);
|
||||
if (storedId != -1) {
|
||||
|
@ -533,6 +534,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
} else {
|
||||
// existing synced folder setup to be updated
|
||||
mSyncedFolderProvider.updateSyncFolder(item);
|
||||
FilesSyncHelper.scheduleM1Jobs();
|
||||
}
|
||||
|
||||
mAdapter.setSyncFolderItem(syncedFolder.getSection(), item);
|
||||
|
@ -607,6 +609,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(InitiateSyncedFolder event) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(event.getSyncedFolder());
|
||||
FilesSyncHelper.scheduleM1Jobs();
|
||||
}
|
||||
|
||||
public void onAddCustomFolderClick(View view) {
|
||||
|
|
|
@ -244,7 +244,7 @@ public class FilesSyncHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void scheduleFilesSyncIfNeeded() {
|
||||
public static void scheduleM1Jobs() {
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(MainApp.getAppContext().
|
||||
getContentResolver());
|
||||
|
||||
|
@ -265,12 +265,6 @@ public class FilesSyncHelper {
|
|||
}
|
||||
}
|
||||
|
||||
new JobRequest.Builder(FilesSyncJob.TAG)
|
||||
.setPeriodic(900000L, 300000L)
|
||||
.setUpdateCurrent(true)
|
||||
.build()
|
||||
.schedule();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
if (hasImageFolders || hasVideoFolders) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
|
@ -278,14 +272,25 @@ public class FilesSyncHelper {
|
|||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
cancelJobsOnM1();
|
||||
cancelJobOnM1();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleFilesSyncIfNeeded() {
|
||||
// always run this because it also allows us to perform retries of manual uploads
|
||||
new JobRequest.Builder(FilesSyncJob.TAG)
|
||||
.setPeriodic(900000L, 300000L)
|
||||
.setUpdateCurrent(true)
|
||||
.build()
|
||||
.schedule();
|
||||
|
||||
scheduleM1Jobs();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
private static void cancelJobsOnM1() {
|
||||
private static void cancelJobOnM1() {
|
||||
JobScheduler jobScheduler = MainApp.getAppContext().getSystemService(JobScheduler.class);
|
||||
if (isContentObserverJobScheduled()) {
|
||||
jobScheduler.cancel(ContentSyncJobId);
|
||||
|
|
Loading…
Reference in a new issue