forked from github/wulkanowy-mirror
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) {
|
override fun setSyncInProgress(inProgress: Boolean) {
|
||||||
|
if (activity == null || !isAdded) return
|
||||||
|
|
||||||
findPreference<Preference>(getString(R.string.pref_key_services_force_sync))?.run {
|
findPreference<Preference>(getString(R.string.pref_key_services_force_sync))?.run {
|
||||||
isEnabled = !inProgress
|
isEnabled = !inProgress
|
||||||
summary = if (inProgress) getString(R.string.pref_services_sync_in_progress) else ""
|
summary = if (inProgress) getString(R.string.pref_services_sync_in_progress) else ""
|
||||||
|
@ -58,16 +58,29 @@ class SettingsPresenter @Inject constructor(
|
|||||||
|
|
||||||
fun onForceSyncDialogSubmit() {
|
fun onForceSyncDialogSubmit() {
|
||||||
view?.run {
|
view?.run {
|
||||||
Timber.i("Setting sync now started")
|
val successString = syncSuccessString
|
||||||
analytics.logEvent("sync_now_started")
|
val failedString = syncFailedString
|
||||||
disposable.add(syncManager.startOneTimeSyncWorker()
|
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) }
|
.doFinally { setSyncInProgress(false) }
|
||||||
.subscribe({ workInfo ->
|
.subscribe({ workInfo ->
|
||||||
if (workInfo.state == WorkInfo.State.SUCCEEDED) showMessage(syncSuccessString)
|
when (workInfo.state) {
|
||||||
else if (workInfo.state == WorkInfo.State.FAILED) showError(syncFailedString, Throwable(workInfo.outputData.getString("error")))
|
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