reset databases in CompositeDisposable
This commit is contained in:
parent
4cbc30171c
commit
420c5584cd
1 changed files with 26 additions and 9 deletions
|
@ -12,24 +12,33 @@ import info.nightscout.androidaps.database.AppRepository
|
|||
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
||||
import info.nightscout.androidaps.events.EventNewBG
|
||||
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.food.FoodPlugin
|
||||
import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.Completable.fromAction
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import javax.inject.Inject
|
||||
|
||||
class MaintenanceFragment : DaggerFragment() {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var maintenancePlugin: MaintenancePlugin
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Inject lateinit var foodPlugin: FoodPlugin
|
||||
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var repository: AppRepository
|
||||
|
||||
private val compositeDisposable = CompositeDisposable()
|
||||
|
||||
private var _binding: MaintenanceFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
|
@ -48,15 +57,22 @@ class MaintenanceFragment : DaggerFragment() {
|
|||
binding.navResetdb.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.maintenance), resourceHelper.gs(R.string.reset_db_confirm), Runnable {
|
||||
compositeDisposable.add(
|
||||
fromAction {
|
||||
MainApp.getDbHelper().resetDatabases()
|
||||
Thread {
|
||||
// should be handled by Plugin-Interface and
|
||||
// additional service interface and plugin registry
|
||||
foodPlugin.service?.resetFood()
|
||||
treatmentsPlugin.service.resetTreatments()
|
||||
repository.clearDatabases()
|
||||
rxBus.send(EventNewBG(null))
|
||||
} .start()
|
||||
}
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribeBy(
|
||||
onError = { aapsLogger.error("Error clearing databases", it) },
|
||||
onComplete = { rxBus.send(EventNewBG(null)) }
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +94,7 @@ class MaintenanceFragment : DaggerFragment() {
|
|||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
compositeDisposable.clear()
|
||||
_binding = null
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue