mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-18 18:26:44 -06:00
Fix crash caused by updating view in not attached fragment (#763)
This commit is contained in:
parent
299345b864
commit
a0528496eb
@ -82,6 +82,8 @@ class SettingsFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
|
||||
override fun setSyncInProgress(inProgress: Boolean) {
|
||||
if (activity == null || !isAdded) return
|
||||
|
||||
findPreference<Preference>(getString(R.string.pref_key_services_force_sync))?.run {
|
||||
isEnabled = !inProgress
|
||||
summary = if (inProgress) getString(R.string.pref_services_sync_in_progress) else ""
|
||||
|
@ -58,16 +58,29 @@ class SettingsPresenter @Inject constructor(
|
||||
|
||||
fun onForceSyncDialogSubmit() {
|
||||
view?.run {
|
||||
Timber.i("Setting sync now started")
|
||||
analytics.logEvent("sync_now_started")
|
||||
val successString = syncSuccessString
|
||||
val failedString = syncFailedString
|
||||
disposable.add(syncManager.startOneTimeSyncWorker()
|
||||
.doOnSubscribe { setSyncInProgress(true) }
|
||||
.doOnSubscribe {
|
||||
setSyncInProgress(true)
|
||||
Timber.i("Setting sync now started")
|
||||
analytics.logEvent("sync_now", "status" to "started")
|
||||
}
|
||||
.doFinally { setSyncInProgress(false) }
|
||||
.subscribe({ workInfo ->
|
||||
if (workInfo.state == WorkInfo.State.SUCCEEDED) showMessage(syncSuccessString)
|
||||
else if (workInfo.state == WorkInfo.State.FAILED) showError(syncFailedString, Throwable(workInfo.outputData.getString("error")))
|
||||
when (workInfo.state) {
|
||||
WorkInfo.State.SUCCEEDED -> {
|
||||
showMessage(successString)
|
||||
analytics.logEvent("sync_now", "status" to "success")
|
||||
}
|
||||
WorkInfo.State.FAILED -> {
|
||||
showError(failedString, Throwable(workInfo.outputData.getString("error")))
|
||||
analytics.logEvent("sync_now", "status" to "failed")
|
||||
}
|
||||
else -> Timber.d("Sync now state: ${workInfo.state}")
|
||||
}
|
||||
}, {
|
||||
Timber.e("Sync now failed")
|
||||
Timber.e(it, "Sync now failed")
|
||||
})
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user