@@ -27,11 +27,17 @@ import android.view.MotionEvent
2727import android.view.View
2828import android.view.View.OnTouchListener
2929import android.view.ViewGroup
30+ import android.widget.FrameLayout
3031import androidx.annotation.OptIn
3132import androidx.annotation.StringRes
3233import androidx.core.net.toUri
3334import androidx.core.view.MenuHost
3435import androidx.core.view.MenuProvider
36+ import androidx.core.view.ViewCompat
37+ import androidx.core.view.WindowInsetsCompat
38+ import androidx.core.view.marginBottom
39+ import androidx.core.view.updateLayoutParams
40+ import androidx.core.view.updatePadding
3541import androidx.drawerlayout.widget.DrawerLayout
3642import androidx.lifecycle.Lifecycle
3743import androidx.lifecycle.lifecycleScope
@@ -40,6 +46,7 @@ import androidx.media3.common.Player
4046import androidx.media3.common.util.UnstableApi
4147import androidx.media3.exoplayer.ExoPlayer
4248import androidx.media3.session.MediaSession
49+ import androidx.media3.ui.DefaultTimeBar
4350import com.nextcloud.client.account.User
4451import com.nextcloud.client.account.UserAccountManager
4552import com.nextcloud.client.di.Injectable
@@ -55,7 +62,6 @@ import com.nextcloud.ui.fileactions.FileAction
5562import com.nextcloud.ui.fileactions.FileActionsBottomSheet.Companion.newInstance
5663import com.nextcloud.utils.extensions.getParcelableArgument
5764import com.nextcloud.utils.extensions.getTypedActivity
58- import com.nextcloud.utils.extensions.logFileSize
5965import com.owncloud.android.R
6066import com.owncloud.android.databinding.FragmentPreviewMediaBinding
6167import com.owncloud.android.datamodel.OCFile
@@ -89,7 +95,7 @@ import javax.inject.Inject
8995 *
9096 * DO NOT CALL IT: an [OCFile] and [User] must be provided for a successful construction
9197 */
92- @Suppress(" NestedBlockDepth" , " ComplexMethod" , " LongMethod" , " TooManyFunctions" )
98+ @Suppress(" NestedBlockDepth" , " ComplexMethod" , " LongMethod" , " TooManyFunctions" , " ReturnCount " )
9399class PreviewMediaFragment :
94100 FileFragment (),
95101 OnTouchListener ,
@@ -117,6 +123,7 @@ class PreviewMediaFragment :
117123 private var exoPlayer: ExoPlayer ? = null
118124 private var mediaSession: MediaSession ? = null
119125 private var nextcloudClient: NextcloudClient ? = null
126+ private var isFullscreenActive = false
120127
121128 @OptIn(UnstableApi ::class )
122129 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -167,7 +174,6 @@ class PreviewMediaFragment :
167174 }
168175
169176 private fun initArguments (bundle : Bundle ) {
170- file.logFileSize(TAG )
171177 file = bundle.getParcelableArgument(FILE , OCFile ::class .java)
172178 user = bundle.getParcelableArgument(USER , User ::class .java)
173179
@@ -176,6 +182,36 @@ class PreviewMediaFragment :
176182 isLivePhoto = bundle.getBoolean(IS_LIVE_PHOTO )
177183 }
178184
185+ override fun onResume () {
186+ super .onResume()
187+ applyWindowInsets()
188+ }
189+
190+ @OptIn(UnstableApi ::class )
191+ private fun applyWindowInsets () {
192+ binding.root.post {
193+ val rootInsets = ViewCompat .getRootWindowInsets(binding.root) ? : return @post
194+ val insets = rootInsets.getInsets(
195+ WindowInsetsCompat .Type .systemBars() or
196+ WindowInsetsCompat .Type .displayCutout()
197+ )
198+ val playerView = binding.exoplayerView
199+ val exoControls = playerView
200+ .findViewById<FrameLayout >(androidx.media3.ui.R .id.exo_bottom_bar)
201+ val exoProgress = playerView
202+ .findViewById<DefaultTimeBar >(androidx.media3.ui.R .id.exo_progress)
203+ val progressOriginalMargin = exoProgress?.marginBottom ? : 0
204+ exoControls?.updateLayoutParams<ViewGroup .MarginLayoutParams > {
205+ bottomMargin = insets.bottom
206+ }
207+ exoProgress?.updateLayoutParams<ViewGroup .MarginLayoutParams > {
208+ bottomMargin = insets.bottom + progressOriginalMargin
209+ }
210+ exoControls?.updatePadding(left = insets.left, right = insets.right)
211+ exoProgress?.updatePadding(left = insets.left, right = insets.right)
212+ }
213+ }
214+
179215 private fun setLoadingView () {
180216 binding.progress.visibility = View .VISIBLE
181217 binding.emptyView.emptyListView.visibility = View .GONE
@@ -196,7 +232,6 @@ class PreviewMediaFragment :
196232
197233 override fun onSaveInstanceState (outState : Bundle ) {
198234 super .onSaveInstanceState(outState)
199- file.logFileSize(TAG )
200235 toggleDrawerLockMode(containerActivity, DrawerLayout .LOCK_MODE_LOCKED_CLOSED )
201236
202237 outState.run {
@@ -431,7 +466,6 @@ class PreviewMediaFragment :
431466 }
432467 }
433468
434- @Suppress(" ReturnCount" )
435469 private fun loadStreamUrl (user : User ? , clientFactory : ClientFactory ? , fileId : Long ): Uri ? {
436470 val client: OwnCloudClient ? = try {
437471 clientFactory?.create(user)
@@ -466,6 +500,9 @@ class PreviewMediaFragment :
466500 }
467501
468502 override fun onStop () {
503+ if (! isFullscreenActive) {
504+ releaseVideoPlayer()
505+ }
469506 releaseVideoPlayer()
470507 super .onStop()
471508 }
@@ -483,13 +520,24 @@ class PreviewMediaFragment :
483520 }
484521
485522 private fun startFullScreenVideo () {
486- activity?.let { activity ->
487- nextcloudClient?.let { client ->
488- exoPlayer?.let { player ->
489- PreviewVideoFullscreenDialog (activity, client, player, binding.exoplayerView).show()
490- }
523+ val activity = activity ? : return
524+ val client = nextcloudClient ? : return
525+ val player = exoPlayer ? : return
526+
527+ isFullscreenActive = true
528+ val dialog = PreviewVideoFullscreenDialog (
529+ activity,
530+ client,
531+ player,
532+ binding.exoplayerView
533+ ).apply {
534+ setOnDismissListener {
535+ isFullscreenActive = false
536+ setupVideoView()
491537 }
492538 }
539+
540+ dialog.show()
493541 }
494542
495543 override fun onConfigurationChanged (newConfig : Configuration ) {
@@ -576,20 +624,14 @@ class PreviewMediaFragment :
576624 startPlaybackPosition : Long ,
577625 autoplay : Boolean ,
578626 isLivePhoto : Boolean
579- ): PreviewMediaFragment {
580- val previewMediaFragment = PreviewMediaFragment ()
581-
582- val bundle = Bundle ().apply {
627+ ): PreviewMediaFragment = PreviewMediaFragment ().apply {
628+ arguments = Bundle ().apply {
583629 putParcelable(FILE , fileToDetail)
584630 putParcelable(USER , user)
585631 putLong(PLAYBACK_POSITION , startPlaybackPosition)
586632 putBoolean(AUTOPLAY , autoplay)
587633 putBoolean(IS_LIVE_PHOTO , isLivePhoto)
588634 }
589-
590- previewMediaFragment.arguments = bundle
591-
592- return previewMediaFragment
593635 }
594636
595637 /* *
0 commit comments