Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: now playing notification for downloaded videos #5924

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.WindowHelper
import com.github.libretube.obj.PlayerNotificationData
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.interfaces.TimeFrameReceiver
import com.github.libretube.ui.listeners.SeekbarPreviewListener
import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.util.NowPlayingNotification
import com.github.libretube.util.OfflineTimeFrameReceiver
import com.github.libretube.util.PauseableTimer
import kotlin.io.path.exists
Expand All @@ -62,6 +64,7 @@
private lateinit var playerView: PlayerView
private lateinit var trackSelector: DefaultTrackSelector
private var timeFrameReceiver: TimeFrameReceiver? = null
private var nowPlayingNotification: NowPlayingNotification? = null

private lateinit var playerBinding: ExoStyledPlayerControlViewBinding
private val playerViewModel: PlayerViewModel by viewModels()
Expand Down Expand Up @@ -191,19 +194,21 @@
binding.doubleTapOverlay.binding,
binding.playerGestureControlsView.binding
)

nowPlayingNotification = NowPlayingNotification(this, player, NowPlayingNotification.Companion.NowPlayingNotificationType.VIDEO_OFFLINE)

Check failure on line 198 in app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Argument should be on a separate line (unless all arguments can fit a single line) Raw Output: app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt:198:57: error: Argument should be on a separate line (unless all arguments can fit a single line) (standard:argument-list-wrapping)

Check failure on line 198 in app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Argument should be on a separate line (unless all arguments can fit a single line) Raw Output: app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt:198:63: error: Argument should be on a separate line (unless all arguments can fit a single line) (standard:argument-list-wrapping)

Check failure on line 198 in app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Argument should be on a separate line (unless all arguments can fit a single line) Raw Output: app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt:198:71: error: Argument should be on a separate line (unless all arguments can fit a single line) (standard:argument-list-wrapping)

Check failure on line 198 in app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Exceeded max line length (140) Raw Output: app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt:198:140: error: Exceeded max line length (140) (standard:max-line-length)

Check failure on line 198 in app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing newline before ")" Raw Output: app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt:198:144: error: Missing newline before ")" (standard:argument-list-wrapping)
}

private fun playVideo() {
lifecycleScope.launch {
val downloadInfo = withContext(Dispatchers.IO) {
val (downloadInfo, downloadItems, downloadChapters) = withContext(Dispatchers.IO) {

Check failure on line 203 in app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt:203:67: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
Database.downloadDao().findById(videoId)
}
val chapters = downloadInfo.downloadChapters.map(DownloadChapter::toChapterSegment)
val chapters = downloadChapters.map(DownloadChapter::toChapterSegment)
playerViewModel.chaptersLiveData.value = chapters
binding.player.setChapters(chapters)

val downloadFiles = downloadInfo.downloadItems.filter { it.path.exists() }
playerBinding.exoTitle.text = downloadInfo.download.title
val downloadFiles = downloadItems.filter { it.path.exists() }
playerBinding.exoTitle.text = downloadInfo.title
playerBinding.exoTitle.isVisible = true

val video = downloadFiles.firstOrNull { it.type == FileType.VIDEO }
Expand All @@ -229,10 +234,13 @@
player.prepare()

if (PlayerHelper.watchPositionsVideo) {
PlayerHelper.getStoredWatchPosition(videoId, downloadInfo.download.duration)?.let {
PlayerHelper.getStoredWatchPosition(videoId, downloadInfo.duration)?.let {
player.seekTo(it)
}
}

val data = PlayerNotificationData(downloadInfo.title, downloadInfo.uploader, downloadInfo.thumbnailPath.toString())
nowPlayingNotification?.updatePlayerNotification(videoId, data)
}
}

Expand Down Expand Up @@ -310,6 +318,7 @@
playerViewModel.player = null
player.release()
watchPositionTimer.destroy()
nowPlayingNotification?.destroySelf()

unregisterReceiver(playerActionReceiver)

Expand Down
Loading