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

Code refactor: Separate online and offline player #3975

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
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 @@ -5,13 +5,9 @@ import android.media.session.PlaybackState
import android.net.Uri
import android.os.Bundle
import android.text.format.DateUtils
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import androidx.activity.viewModels
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.view.marginTop
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
import androidx.media3.common.C
import androidx.media3.common.MediaItem
Expand All @@ -30,9 +26,7 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.ActivityOfflinePlayerBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.db.DatabaseHolder.Database
import com.github.libretube.db.obj.DownloadItem
import com.github.libretube.enums.FileType
import com.github.libretube.extensions.dpToPx
import com.github.libretube.extensions.toAndroidUri
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.PlayerHelper
Expand Down Expand Up @@ -105,24 +99,14 @@ class OfflinePlayerActivity : BaseActivity() {
playerView.player = player
playerBinding = binding.player.binding

// increase the margin to the status bar
playerBinding.topBar.setPadding(
playerBinding.topBar.paddingLeft,
playerBinding.topBar.paddingTop * 2,
playerBinding.topBar.paddingRight,
playerBinding.topBar.paddingBottom
)

playerBinding.fullscreen.isInvisible = true
playerBinding.closeImageButton.setOnClickListener {
finish()
}

binding.player.initialize(
null,
binding.doubleTapOverlay.binding,
binding.playerGestureControlsView.binding,
trackSelector,
)
}

Expand Down Expand Up @@ -181,6 +165,7 @@ class OfflinePlayerActivity : BaseActivity() {

player.setMediaSource(mediaSource)
}

videoUri != null -> player.setMediaItem(
MediaItem.Builder()
.setUri(videoUri)
Expand All @@ -189,6 +174,7 @@ class OfflinePlayerActivity : BaseActivity() {
}
.build(),
)

audioUri != null -> player.setMediaItem(
MediaItem.Builder()
.setUri(audioUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import android.os.PowerManager
import android.text.format.DateUtils
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.util.Base64
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -76,8 +75,6 @@ import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.BackgroundHelper
import com.github.libretube.helpers.DashHelper
import com.github.libretube.helpers.DisplayHelper
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.LocaleHelper
import com.github.libretube.helpers.NavigationHelper
Expand Down Expand Up @@ -892,14 +889,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
@SuppressLint("SetTextI18n")
private fun initializePlayerView() {
// initialize the player view actions
binding.player.initialize(
this,
doubleTapOverlayBinding,
playerGestureControlsViewBinding,
trackSelector,
viewModel,
viewLifecycleOwner,
)
binding.player.initialize(doubleTapOverlayBinding, playerGestureControlsViewBinding)
binding.player.initPlayerOptions(viewModel, viewLifecycleOwner, trackSelector, this)

binding.apply {
val views = streams.views.formatShort()
Expand Down
Loading