Skip to content

Commit

Permalink
nested
Browse files Browse the repository at this point in the history
view{
 view{ }
 view{ }
}
  • Loading branch information
apikyanrobert committed Oct 31, 2018
1 parent 4a96090 commit c2f6f92
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package robertapikyan.com.lifecyclemvp.lifecycle
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.Observer
import android.os.Handler
import android.os.Looper
import robertapikyan.com.abstractmvp.presentation.view.*
import java.util.*
Expand Down Expand Up @@ -30,6 +31,7 @@ class ViewActionDispatcherLiveData<V : IView> : LiveData<IViewAction<V>>(),

private val pending = AtomicBoolean(false)
private val dispatching = AtomicBoolean(false)
private val uiHandler by lazy { Handler(Looper.getMainLooper()) }

private val pendingActions: Queue<IViewAction<V>>
by lazy { LinkedList<IViewAction<V>>() }
Expand Down Expand Up @@ -111,7 +113,11 @@ class ViewActionDispatcherLiveData<V : IView> : LiveData<IViewAction<V>>(),
}

private fun sendImmediate(viewAction: IViewAction<V>) {
if (dispatching.get() || !isMainThread()) {
if (dispatching.get()) {
uiHandler.post {
value = viewAction
}
} else if (!isMainThread()) {
postValue(viewAction)
} else {
value = viewAction
Expand Down

0 comments on commit c2f6f92

Please sign in to comment.