[Android] LifecycleAwareScheduler: allow passing data in a bundle

Nicolas Pomepuy git at videolan.org
Tue Jul 25 14:57:29 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jul 20 10:16:10 2023 +0200| [82844b83524e999ce22c44bdd1b30e5ba1f8a3a4] | committer: Duncan McNamara

LifecycleAwareScheduler: allow passing data in a bundle

> https://code.videolan.org/videolan/vlc-android/commit/82844b83524e999ce22c44bdd1b30e5ba1f8a3a4
---

 .../org/videolan/vlc/gui/browser/BaseBrowserFragment.kt    |  2 +-
 .../src/org/videolan/vlc/gui/view/FastScroller.kt          |  3 ++-
 .../src/org/videolan/vlc/util/LifecycleAwareScheduler.kt   | 14 +++++++++-----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index daea72c8fd..7d82d1cc70 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -347,7 +347,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
         playAll(null)
     }
 
-    override fun onTaskTriggered(id: String) {
+    override fun onTaskTriggered(id: String, data:Bundle) {
         when (id) {
             MSG_SHOW_LOADING -> swipeRefreshLayout.isRefreshing = true
             MSG_HIDE_LOADING -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt
index b6cc04955f..2092db8c6b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/FastScroller.kt
@@ -28,6 +28,7 @@ import android.animation.AnimatorListenerAdapter
 import android.animation.AnimatorSet
 import android.animation.ObjectAnimator
 import android.content.Context
+import android.os.Bundle
 import android.util.AttributeSet
 import android.util.Log
 import android.view.LayoutInflater
@@ -385,7 +386,7 @@ class FastScroller : LinearLayout, Observer<HeadersIndex>, SchedulerCallback {
         actor.trySend(Unit)
     }
 
-    override fun onTaskTriggered(id: String) {
+    override fun onTaskTriggered(id: String, data:Bundle) {
         when (id) {
             HIDE_HANDLE -> hideBubble()
             HIDE_SCROLLER -> animate().translationX(hiddenTranslationX)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/LifecycleAwareScheduler.kt b/application/vlc-android/src/org/videolan/vlc/util/LifecycleAwareScheduler.kt
index c0dd3d2b0f..06549cde6f 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/LifecycleAwareScheduler.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/LifecycleAwareScheduler.kt
@@ -24,6 +24,7 @@
 
 package org.videolan.vlc.util
 
+import android.os.Bundle
 import android.util.Log
 import androidx.lifecycle.DefaultLifecycleObserver
 import androidx.lifecycle.LifecycleOwner
@@ -45,8 +46,9 @@ interface SchedulerCallback : LifecycleOwner {
      * It's guaranteed to be ran on the main thread
      *
      * @param id the action id
+     * @param data the data passed by the caller
      */
-    fun onTaskTriggered(id: String)
+    fun onTaskTriggered(id: String, data:Bundle)
 
     /**
      * (Optional) Called when the action is cancelled
@@ -79,9 +81,10 @@ class LifecycleAwareScheduler(private val callback: SchedulerCallback) : Default
      * Can be called in any thread
      *
      * @param id the action id
+     * @param data the data to be passed
      */
-    fun startAction(id: String) {
-        scheduleAction(id, 0L)
+    fun startAction(id: String, data:Bundle = Bundle()) {
+        scheduleAction(id, 0L, data)
     }
 
     /**
@@ -90,13 +93,14 @@ class LifecycleAwareScheduler(private val callback: SchedulerCallback) : Default
      *
      * @param id the action id
      * @param delay the delay before the action is ran
+     * @param data the data to be passed
      */
-    fun scheduleAction(id: String, delay: Long) {
+    fun scheduleAction(id: String, delay: Long, data:Bundle = Bundle()) {
         if (BuildConfig.DEBUG) Log.d("LifecycleAwareScheduler", "Scheduling action for $callback on thread ${Thread.currentThread()} with id $id")
         callback.lifecycle.addObserver(this at LifecycleAwareScheduler)
         if (timeTasks.keys.contains(id)) cancelAction(id)
         timeTasks[id] = timerTask {
-            callback.lifecycleScope.launch(Dispatchers.Main) { callback.onTaskTriggered(id) }
+            callback.lifecycleScope.launch(Dispatchers.Main) { callback.onTaskTriggered(id, data) }
         }
         timer.schedule(timeTasks[id], delay)
     }



More information about the Android mailing list