forked from github/wulkanowy-mirror
Add last sync date in sync settings (#1436)
This commit is contained in:

committed by
GitHub

parent
626169de11
commit
9c819835ca
@ -39,6 +39,12 @@ class SyncFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
}
|
||||
|
||||
override fun setLastSyncDate(lastSyncDate: String) {
|
||||
findPreference<Preference>(getString(R.string.pref_key_services_force_sync))?.run {
|
||||
summary = getString(R.string.pref_services_last_full_sync_date, lastSyncDate)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
presenter.onAttachView(this)
|
||||
|
@ -8,6 +8,7 @@ import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.isHolidays
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
@ -27,6 +28,7 @@ class SyncPresenter @Inject constructor(
|
||||
Timber.i("Settings sync view was initialized")
|
||||
view.setServicesSuspended(preferencesRepository.serviceEnableKey, now().isHolidays)
|
||||
view.initView()
|
||||
setSyncDateInView()
|
||||
}
|
||||
|
||||
fun onSharedPreferenceChanged(key: String) {
|
||||
@ -63,10 +65,21 @@ class SyncPresenter @Inject constructor(
|
||||
}
|
||||
else -> Timber.d("Sync now state: ${workInfo.state}")
|
||||
}
|
||||
if (workInfo.state.isFinished) setSyncInProgress(false)
|
||||
if (workInfo.state.isFinished) {
|
||||
setSyncInProgress(false)
|
||||
setSyncDateInView()
|
||||
}
|
||||
}.catch {
|
||||
Timber.e(it, "Sync now failed")
|
||||
}.launch("sync")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setSyncDateInView() {
|
||||
val lastSyncDate = preferencesRepository.lasSyncDate
|
||||
|
||||
if (lastSyncDate.year == 1970) return
|
||||
|
||||
view?.setLastSyncDate(lastSyncDate.toFormattedString("dd.MM.yyyy HH:mm:ss"))
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ interface SyncView : BaseView {
|
||||
|
||||
fun initView()
|
||||
|
||||
fun setLastSyncDate(lastSyncDate: String)
|
||||
|
||||
fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean)
|
||||
|
||||
fun setSyncInProgress(inProgress: Boolean)
|
||||
|
Reference in New Issue
Block a user