|
|
|
@ -44,6 +44,8 @@ interface ICallBackHandler { |
|
|
|
fun watchPlaylists() |
|
|
|
fun watchHistory() |
|
|
|
fun watchMediaGroups() |
|
|
|
fun pause() |
|
|
|
fun resume() |
|
|
|
} |
|
|
|
|
|
|
|
class CallBackDelegate : ICallBackHandler, |
|
|
|
@ -69,9 +71,36 @@ class CallBackDelegate : ICallBackHandler, |
|
|
|
private var playlistsCb = false |
|
|
|
private var historyCb = false |
|
|
|
private var mediaGroupsCb = false |
|
|
|
var paused = false |
|
|
|
set(value) { |
|
|
|
field = value |
|
|
|
if (!value && isInvalid) { |
|
|
|
refreshActor.trySend(Unit) |
|
|
|
isInvalid = false |
|
|
|
} |
|
|
|
} |
|
|
|
var isInvalid = false |
|
|
|
|
|
|
|
/** |
|
|
|
* Pause the callbacks while the caller is paused to avoid unwanted refreshes |
|
|
|
* During this time, instead of refreshing, it's marked as invalid. |
|
|
|
* If invalid, a refresh is launched upon resuming |
|
|
|
*/ |
|
|
|
override fun pause() { |
|
|
|
paused = true |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Resumes the callback and refresh if it has been marked invalid in the meantime |
|
|
|
*/ |
|
|
|
override fun resume() { |
|
|
|
paused = false |
|
|
|
} |
|
|
|
|
|
|
|
override fun CoroutineScope.registerCallBacks(refresh: () -> Unit) { |
|
|
|
refreshActor = conflatedActor { refresh() } |
|
|
|
refreshActor = conflatedActor { |
|
|
|
if (paused) isInvalid = true else refresh() |
|
|
|
} |
|
|
|
deleteActor = actor(context = Dispatchers.IO, capacity = Channel.UNLIMITED) { |
|
|
|
for (action in channel) when (action) { |
|
|
|
is MediaDeletedAction -> { |
|
|
|
|