Skip to content

Commit b00fa5e

Browse files
committed
refactor: simplify and perf-improve PlayOfflineDialog logic
1 parent 35f52e8 commit b00fa5e

4 files changed

Lines changed: 9 additions & 22 deletions

File tree

app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import androidx.media3.common.ForwardingPlayer
1515
import androidx.media3.common.MediaMetadata
1616
import androidx.media3.common.PlaybackException
1717
import androidx.media3.common.Player
18-
import androidx.media3.common.util.Log
1918
import androidx.media3.common.util.UnstableApi
2019
import androidx.media3.exoplayer.ExoPlayer
2120
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
@@ -244,12 +243,12 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
244243
setExtras(bundleOf(IntentData.segments to segments))
245244
}
246245

247-
Log.e("segments", sponsorBlockSegments.toString())
248246
checkForSegments()
249247
}
250248

251249
/**
252-
* check for SponsorBlock segments
250+
* Check for SponsorBlock segments. This method automatically schedules itself to repeat every
251+
* 100ms using [handler], so it's not needed to schedule it manually.
253252
*/
254253
private fun checkForSegments() {
255254
handler.postDelayed(this::checkForSegments, 100)

app/src/main/java/com/github/libretube/ui/dialogs/PlayOfflineDialog.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.fragment.app.setFragmentResult
99
import com.github.libretube.R
1010
import com.github.libretube.constants.IntentData
1111
import com.github.libretube.databinding.DialogPlayOfflineBinding
12-
import com.github.libretube.helpers.NavigationHelper
1312
import com.github.libretube.util.TextUtils
1413
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1514

@@ -30,12 +29,6 @@ class PlayOfflineDialog : DialogFragment() {
3029
.setTitle(R.string.dialog_play_offline_title)
3130
.setView(binding.root)
3231
.setPositiveButton(R.string.yes) { _, _ ->
33-
NavigationHelper.navigateVideo(
34-
requireContext(),
35-
videoId = videoId,
36-
isOffline = true
37-
)
38-
3932
setFragmentResult(
4033
PLAY_OFFLINE_DIALOG_REQUEST_KEY,
4134
bundleOf(IntentData.isPlayingOffline to true)

app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,11 @@ class PlayerFragment : Fragment(R.layout.fragment_player), CustomPlayerCallback
487487
fragmentManager.setFragmentResultListener(
488488
PlayOfflineDialog.PLAY_OFFLINE_DIALOG_REQUEST_KEY, viewLifecycleOwner
489489
) { _, bundle ->
490-
if (bundle.getBoolean(IntentData.isPlayingOffline)) {
491-
// offline video playback started and thus the player fragment is no longer needed
492-
killPlayerFragment()
493-
} else {
494-
attachToPlayerService(playerData, true)
495-
}
490+
isOffline = bundle.getBoolean(IntentData.isPlayingOffline)
491+
492+
// start a new playback session - the method will read `isOffline` and decide whether
493+
// to play the downloaded video based on it, so it's enough to set `isOffline` here
494+
attachToPlayerService(playerData, true)
496495
}
497496

498497
val downloadInfo = DownloadHelper.extractDownloadInfoText(
@@ -548,12 +547,12 @@ class PlayerFragment : Fragment(R.layout.fragment_player), CustomPlayerCallback
548547
}
549548

550549
private fun attachToPlayerService(playerData: PlayerData, startNewSession: Boolean) {
551-
val (serviceClass, args) = if (playerData.isOffline) {
550+
val (serviceClass, args) = if (isOffline) {
552551
val isNoInternet = activity is NoInternetActivity
553552

554553
OfflinePlayerService::class.java to bundleOf(
555554
IntentData.videoId to videoId,
556-
IntentData.downloadTab to playerData.downloadTab,
555+
IntentData.downloadTab to (playerData.downloadTab ?: DownloadTab.VIDEO),
557556
IntentData.playlistId to playlistId,
558557
IntentData.sortOptions to playerData.downloadSortingOrder,
559558
IntentData.shuffle to playerData.shuffle,

app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.os.Handler
1010
import android.os.Looper
1111
import android.text.format.DateUtils
1212
import android.util.AttributeSet
13-
import android.util.Log
1413
import android.view.KeyEvent
1514
import android.view.MotionEvent
1615
import android.view.Window
@@ -27,7 +26,6 @@ import androidx.core.view.isInvisible
2726
import androidx.core.view.isVisible
2827
import androidx.core.view.marginStart
2928
import androidx.core.view.updateLayoutParams
30-
import androidx.fragment.app.findFragment
3129
import androidx.lifecycle.LifecycleOwner
3230
import androidx.lifecycle.findViewTreeLifecycleOwner
3331
import androidx.media3.common.C
@@ -69,7 +67,6 @@ import com.github.libretube.ui.controllers.FullscreenGestureAnimationController
6967
import com.github.libretube.ui.dialogs.SubmitDeArrowDialog
7068
import com.github.libretube.ui.dialogs.SubmitSegmentDialog
7169
import com.github.libretube.ui.extensions.toggleSystemBars
72-
import com.github.libretube.ui.fragments.PlayerFragment
7370
import com.github.libretube.ui.interfaces.CustomPlayerCallback
7471
import com.github.libretube.ui.interfaces.PlayerGestureOptions
7572
import com.github.libretube.ui.interfaces.PlayerOptions
@@ -382,7 +379,6 @@ class CustomExoPlayerView(
382379
updateMarginsByFullscreenMode()
383380

384381
commonPlayerViewModel?.isFullscreen?.observe(viewLifecycleOwner) { isFullscreen ->
385-
Log.e("is full", isFullscreen.toString())
386382
updateTopBarMargin()
387383

388384
binding.fullscreen.isInvisible = PlayerHelper.autoFullscreenEnabled

0 commit comments

Comments
 (0)