<commit_before>package org.wikipedia.savedpages

import android.content.Intent
import androidx.core.app.JobIntentService
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import okhttp3.Request
import okio.Buffer
import okio.Sink
import okio.Timeout
import org.wikipedia.WikipediaApp
import org.wikipedia.database.contract.PageImageHistoryContract
import org.wikipedia.dataclient.RestService
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.dataclient.okhttp.HttpStatusException
import org.wikipedia.dataclient.okhttp.OfflineCacheInterceptor
import org.wikipedia.dataclient.okhttp.OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK
import org.wikipedia.dataclient.okhttp.OkHttpConnectionFactory.client
import org.wikipedia.dataclient.page.PageSummary
import org.wikipedia.events.PageDownloadEvent
import org.wikipedia.gallery.MediaList
import org.wikipedia.offline.OfflineObjectDbHelper
import org.wikipedia.page.PageTitle
import org.wikipedia.pageimages.PageImage
import org.wikipedia.readinglist.database.ReadingListDbHelper
import org.wikipedia.readinglist.database.ReadingListPage
import org.wikipedia.readinglist.sync.ReadingListSyncAdapter
import org.wikipedia.readinglist.sync.ReadingListSyncEvent
import org.wikipedia.settings.Prefs
import org.wikipedia.util.*
import org.wikipedia.util.ImageUrlUtil
import org.wikipedia.util.log.L
import org.wikipedia.views.CircularProgressBar
import retrofit2.Response
import java.io.IOException

class SavedPageSyncService : JobIntentService() {
    private val savedPageSyncNotification = SavedPageSyncNotification()
    val app: WikipediaApp = WikipediaApp.getInstance()

    override fun onHandleWork(intent: Intent) {
        if (ReadingListSyncAdapter.inProgress()) {
            // Reading list sync was started in the meantime, so bail.
            return
        }
        val pagesToSave = ReadingListDbHelper.instance().allPagesToBeForcedSave
        if ((!Prefs.isDownloadOnlyOverWiFiEnabled() || DeviceUtil.isOnWiFi()) &&
                Prefs.isDownloadingReadingListArticlesEnabled()) {
            pagesToSave.addAll(ReadingListDbHelper.instance().allPagesToBeSaved)
        }
        val pagesToUnSave = ReadingListDbHelper.instance().allPagesToBeUnsaved
        val pagesToDelete = ReadingListDbHelper.instance().allPagesToBeDeleted
        var shouldSendSyncEvent = false
        try {
            for (page in pagesToDelete) {
                deletePageContents(page)
            }<commit_msg>Fix pausing and canceling of Saved Pages sync notification. (#2207)<commit_after>package org.wikipedia.savedpages

import android.content.Intent
import androidx.core.app.JobIntentService
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import okhttp3.Request
import okio.Buffer
import okio.Sink
import okio.Timeout
import org.wikipedia.WikipediaApp
import org.wikipedia.database.contract.PageImageHistoryContract
import org.wikipedia.dataclient.RestService
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.dataclient.okhttp.HttpStatusException
import org.wikipedia.dataclient.okhttp.OfflineCacheInterceptor
import org.wikipedia.dataclient.okhttp.OkHttpConnectionFactory.CACHE_CONTROL_FORCE_NETWORK
import org.wikipedia.dataclient.okhttp.OkHttpConnectionFactory.client
import org.wikipedia.dataclient.page.PageSummary
import org.wikipedia.events.PageDownloadEvent
import org.wikipedia.gallery.MediaList
import org.wikipedia.offline.OfflineObjectDbHelper
import org.wikipedia.page.PageTitle
import org.wikipedia.pageimages.PageImage
import org.wikipedia.readinglist.database.ReadingListDbHelper
import org.wikipedia.readinglist.database.ReadingListPage
import org.wikipedia.readinglist.sync.ReadingListSyncAdapter
import org.wikipedia.readinglist.sync.ReadingListSyncEvent
import org.wikipedia.settings.Prefs
import org.wikipedia.util.*
import org.wikipedia.util.ImageUrlUtil
import org.wikipedia.util.log.L
import org.wikipedia.views.CircularProgressBar
import retrofit2.Response
import java.io.IOException

class SavedPageSyncService : JobIntentService() {
    private val savedPageSyncNotification = SavedPageSyncNotification.instance
    val app: WikipediaApp = WikipediaApp.getInstance()

    override fun onHandleWork(intent: Intent) {
        if (ReadingListSyncAdapter.inProgress()) {
            // Reading list sync was started in the meantime, so bail.
            return
        }
        val pagesToSave = ReadingListDbHelper.instance().allPagesToBeForcedSave
        if ((!Prefs.isDownloadOnlyOverWiFiEnabled() || DeviceUtil.isOnWiFi()) &&
                Prefs.isDownloadingReadingListArticlesEnabled()) {
            pagesToSave.addAll(ReadingListDbHelper.instance().allPagesToBeSaved)
        }
        val pagesToUnSave = ReadingListDbHelper.instance().allPagesToBeUnsaved
        val pagesToDelete = ReadingListDbHelper.instance().allPagesToBeDeleted
        var shouldSendSyncEvent = false
        try {
            for (page in pagesToDelete) {
                deletePageContents(page)
            }
{'fraction_non_alphanumeric': 0.07298578199052133, 'fraction_numerical': 0.002654028436018957, 'mean_word_length': 4.823399558498896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6035882', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1415, 'n_words': 255}