mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 20:10:04 +03:00
Sync: fix liveState not initialized and add method to get current state without livedata
This commit is contained in:
parent
73ce38c6a9
commit
faeeec0e37
4 changed files with 13 additions and 5 deletions
|
@ -127,6 +127,12 @@ interface Session :
|
|||
*/
|
||||
fun getSyncStateLive(): LiveData<SyncState>
|
||||
|
||||
/**
|
||||
* This method returns the current sync state.
|
||||
* @return the current [SyncState].
|
||||
*/
|
||||
fun getSyncState(): SyncState
|
||||
|
||||
/**
|
||||
* This methods return true if an initial sync has been processed
|
||||
*/
|
||||
|
|
|
@ -197,9 +197,9 @@ internal class DefaultSession @Inject constructor(
|
|||
eventBus.unregister(this)
|
||||
}
|
||||
|
||||
override fun getSyncStateLive(): LiveData<SyncState> {
|
||||
return getSyncThread().liveState()
|
||||
}
|
||||
override fun getSyncStateLive() = getSyncThread().liveState()
|
||||
|
||||
override fun getSyncState() = getSyncThread().currentState()
|
||||
|
||||
override fun hasAlreadySynced(): Boolean {
|
||||
return syncTokenStore.getLastToken() != null
|
||||
|
|
|
@ -104,7 +104,7 @@ abstract class SyncService : Service() {
|
|||
try {
|
||||
syncTask.execute(params)
|
||||
// Start sync if we were doing an initial sync and the syncThread is not launched yet
|
||||
if (isInitialSync && session.getSyncStateLive().value == SyncState.Idle) {
|
||||
if (isInitialSync && session.getSyncState() == SyncState.Idle) {
|
||||
val isForeground = !backgroundDetectionObserver.isInBackground
|
||||
session.startSync(isForeground)
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
|
|||
: Thread(), NetworkConnectivityChecker.Listener, BackgroundDetectionObserver.Listener {
|
||||
|
||||
private var state: SyncState = SyncState.Idle
|
||||
private var liveState = MutableLiveData<SyncState>()
|
||||
private var liveState = MutableLiveData<SyncState>(state)
|
||||
private val lock = Object()
|
||||
private val syncScope = CoroutineScope(SupervisorJob())
|
||||
private val debouncer = Debouncer(createUIHandler())
|
||||
|
@ -98,6 +98,8 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
|
|||
lock.notify()
|
||||
}
|
||||
|
||||
fun currentState() = state
|
||||
|
||||
fun liveState(): LiveData<SyncState> {
|
||||
return liveState
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue