@@ -20,6 +20,8 @@ import com.github.libretube.ui.activities.MainActivity
2020import com.github.libretube.ui.activities.ZoomableImageActivity
2121import com.github.libretube.ui.base.BaseActivity
2222import com.github.libretube.ui.fragments.AudioPlayerFragment
23+ import com.github.libretube.ui.fragments.DownloadSortingOrder
24+ import com.github.libretube.ui.fragments.DownloadTab
2325import com.github.libretube.ui.fragments.PlayerFragment
2426import com.github.libretube.ui.views.SingleViewTouchableMotionLayout
2527import com.github.libretube.util.PlayingQueue
@@ -57,8 +59,14 @@ object NavigationHelper {
5759 alreadyStarted : Boolean = false,
5860 forceVideo : Boolean = false,
5961 audioOnlyPlayerRequested : Boolean = false,
62+ downloadTab : DownloadTab ? = null,
63+ downloadSortingOrder : DownloadSortingOrder ? = null,
64+ shuffle : Boolean = false,
65+ isOffline : Boolean = false
6066 ) {
6167 if (videoId == null ) return
68+ // TODO: refactor all related methods to take [PlayerData] objects as arguments instead
69+ // of all these overcomplex amount of arguments!
6270
6371 // attempt to attach to the current media session first by using the corresponding
6472 // video/audio player instance
@@ -104,14 +112,25 @@ object NavigationHelper {
104112 if (audioOnlyPlayerRequested || (audioOnlyMode && ! forceVideo)) {
105113 // in contrast to the video player, the audio player doesn't start a media service on
106114 // its own!
107- BackgroundHelper .playOnBackground(
108- context,
109- videoId.toID(),
110- timestamp,
111- playlistId,
112- channelId,
113- keepQueue
114- )
115+ if (isOffline) {
116+ BackgroundHelper .playOnBackground(
117+ context,
118+ videoId.toID(),
119+ timestamp,
120+ playlistId,
121+ channelId,
122+ keepQueue
123+ )
124+ } else {
125+ BackgroundHelper .playOnBackgroundOffline(
126+ context,
127+ videoId.toID(),
128+ playlistId,
129+ downloadTab!! ,
130+ shuffle,
131+ downloadSortingOrder
132+ )
133+ }
115134
116135 openAudioPlayerFragment(context, minimizeByDefault = true )
117136 } else {
@@ -122,7 +141,11 @@ object NavigationHelper {
122141 channelId,
123142 keepQueue,
124143 timestamp,
125- alreadyStarted
144+ alreadyStarted,
145+ shuffle,
146+ isOffline,
147+ downloadTab,
148+ downloadSortingOrder
126149 )
127150 }
128151 }
@@ -164,15 +187,19 @@ object NavigationHelper {
164187 channelId : String? = null,
165188 keepQueue : Boolean = false,
166189 timestamp : Long = 0,
167- alreadyStarted : Boolean = false
190+ alreadyStarted : Boolean = false,
191+ shuffle : Boolean = false,
192+ isOffline : Boolean = false,
193+ downloadTab : DownloadTab ? = null,
194+ downloadSortingOrder : DownloadSortingOrder ? = null,
168195 ) {
169196 val activity = ContextHelper .unwrapActivity<BaseActivity >(context)
170197
171198 val playerData =
172- PlayerData (videoId, playlistId, channelId, keepQueue, timestamp)
199+ PlayerData (videoId, playlistId, channelId, keepQueue, timestamp, shuffle, isOffline, downloadTab, downloadSortingOrder )
173200 val bundle = bundleOf(
174201 IntentData .playerData to playerData,
175- IntentData .alreadyStarted to alreadyStarted
202+ IntentData .alreadyStarted to alreadyStarted,
176203 )
177204 activity.supportFragmentManager.commitNow {
178205 replace<PlayerFragment >(R .id.container, args = bundle)
0 commit comments