Create a new worker for export

This commit is contained in:
Philoul 2021-10-18 09:59:26 +02:00
parent 26c702c7c0
commit c723058628
4 changed files with 9 additions and 13 deletions

View file

@ -68,7 +68,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_csv) + "?") {
uel.log(Action.EXPORT_CSV, Sources.Treatments)
importExportPrefs.exportUserEntriesCsv()
importExportPrefs.exportUserEntriesCsv(activity)
}
}
}

View file

@ -11,10 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.work.OneTimeWorkRequest
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import androidx.work.*
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.MainApp
@ -32,7 +29,6 @@ import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.maintenance.formats.*
import info.nightscout.androidaps.receivers.DataWorker
import info.nightscout.androidaps.utils.AndroidPermission
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.MidnightTime
@ -71,7 +67,6 @@ class ImportExportPrefsImpl @Inject constructor(
private val encryptedPrefsFormat: EncryptedPrefsFormat,
private val prefFileList: PrefFileListProvider,
private val uel: UserEntryLogger,
private val dataWorker: DataWorker,
private val dateUtil: DateUtil
) : ImportExportPrefs {
@ -369,10 +364,11 @@ class ImportExportPrefsImpl @Inject constructor(
}
}
override fun exportUserEntriesCsv() {
dataWorker.enqueue(
OneTimeWorkRequest.Builder(CsvExportWorker::class.java)
.build()
override fun exportUserEntriesCsv(activity: FragmentActivity) {
WorkManager.getInstance(activity).enqueueUniqueWork(
"export",
ExistingWorkPolicy.APPEND_OR_REPLACE,
OneTimeWorkRequest.Builder(CsvExportWorker::class.java).build()
)
}

View file

@ -118,7 +118,7 @@ class MaintenanceFragment : DaggerFragment() {
activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.ue_export_to_csv) + "?") {
uel.log(Action.EXPORT_CSV, Sources.Maintenance)
importExportPrefs.exportUserEntriesCsv()
importExportPrefs.exportUserEntriesCsv(activity)
}
}
}

View file

@ -14,5 +14,5 @@ interface ImportExportPrefs {
fun prefsFileExists(): Boolean
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable)
fun exportSharedPreferences(f: Fragment)
fun exportUserEntriesCsv()
fun exportUserEntriesCsv(activity: FragmentActivity)
}