浏览代码

remove going fullscreen using dialog

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
parneet-guraya 1 年之前
父节点
当前提交
67465459c7

+ 0 - 211
app/src/main/java/com/owncloud/android/ui/preview/PreviewVideoFullscreenDialog.kt

@@ -1,211 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- *  @author Álvaro Brey
- *  Copyright (C) 2022 Álvaro Brey
- *  Copyright (C) 2022 Nextcloud GmbH
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.ui.preview
-
-import android.app.Activity
-import android.app.Dialog
-import android.os.Build
-import android.view.View
-import android.view.ViewGroup
-import android.view.Window
-import androidx.core.view.WindowCompat
-import androidx.core.view.WindowInsetsCompat
-import androidx.core.view.WindowInsetsControllerCompat
-import androidx.media3.common.Player
-import androidx.media3.common.util.UnstableApi
-import androidx.media3.exoplayer.ExoPlayer
-import androidx.media3.ui.PlayerView
-import com.nextcloud.client.media.ExoplayerListener
-import com.nextcloud.client.media.NextcloudExoPlayer
-import com.nextcloud.common.NextcloudClient
-import com.owncloud.android.R
-import com.owncloud.android.databinding.DialogPreviewVideoBinding
-import com.owncloud.android.lib.common.utils.Log_OC
-
-@UnstableApi /**
- * Transfers a previously playing video to a fullscreen dialog, and handles the switch back to the previous player
- * when closed
- *
- * @param activity the Activity hosting the original non-fullscreen player
- * @param sourceExoPlayer the ExoPlayer playing the video
- * @param sourceView the original non-fullscreen surface that [sourceExoPlayer] is linked to
- */
-class PreviewVideoFullscreenDialog(
-    private val activity: Activity,
-    nextcloudClient: NextcloudClient,
-    private val sourceExoPlayer: ExoPlayer,
-    private val sourceView: PlayerView
-) : Dialog(sourceView.context, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
-
-    private val binding: DialogPreviewVideoBinding = DialogPreviewVideoBinding.inflate(layoutInflater)
-    private var playingStateListener: Player.Listener? = null
-
-    /**
-     * exoPlayer instance used for this view, either the original one or a new one in specific cases.
-     * @see getShouldUseRotatedVideoWorkaround
-     */
-    private val mExoPlayer: ExoPlayer
-
-    /**
-     * Videos with rotation metadata present a bug in sdk < 30 where they are rotated incorrectly and stretched when
-     * the video is resumed on a new surface. To work around this, in those circumstances we'll create a new ExoPlayer
-     * instance, which is slower but should avoid the bug.
-     */
-    private val shouldUseRotatedVideoWorkaround
-        get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.R && isRotatedVideo()
-
-    init {
-        addContentView(
-            binding.root,
-            ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
-        )
-        mExoPlayer = getExoPlayer(nextcloudClient)
-        if (shouldUseRotatedVideoWorkaround) {
-            sourceExoPlayer.currentMediaItem?.let { mExoPlayer.setMediaItem(it, sourceExoPlayer.currentPosition) }
-            binding.videoPlayer.player = mExoPlayer
-            mExoPlayer.prepare()
-        }
-    }
-
-    private fun isRotatedVideo(): Boolean {
-        val videoFormat = sourceExoPlayer.videoFormat
-        return videoFormat != null && videoFormat.rotationDegrees != 0
-    }
-
-    private fun getExoPlayer(nextcloudClient: NextcloudClient): ExoPlayer {
-        return if (shouldUseRotatedVideoWorkaround) {
-            Log_OC.d(TAG, "Using new ExoPlayer instance to deal with rotated video")
-            NextcloudExoPlayer
-                .createNextcloudExoplayer(sourceView.context, nextcloudClient)
-                .apply {
-                    addListener(ExoplayerListener(sourceView.context, binding.videoPlayer, this))
-                }
-        } else {
-            sourceExoPlayer
-        }
-    }
-
-    override fun show() {
-        val isPlaying = sourceExoPlayer.isPlaying
-        if (isPlaying) {
-            sourceExoPlayer.pause()
-        }
-        setOnShowListener {
-            enableImmersiveMode()
-            switchTargetViewFromSource()
-            setListeners()
-            if (isPlaying) {
-                mExoPlayer.play()
-            }
-            binding.videoPlayer.showController()
-        }
-        super.show()
-    }
-
-    private fun switchTargetViewFromSource() {
-        if (shouldUseRotatedVideoWorkaround) {
-            mExoPlayer.seekTo(sourceExoPlayer.currentPosition)
-        } else {
-            PlayerView.switchTargetView(sourceExoPlayer, sourceView, binding.videoPlayer)
-        }
-    }
-
-    private fun setListeners() {
-        binding.root.findViewById<View>(R.id.exo_exit_fs).setOnClickListener { onBackPressed() }
-        val pauseButton: View = binding.root.findViewById(R.id.exo_pause)
-        pauseButton.setOnClickListener { sourceExoPlayer.pause() }
-        val playButton: View = binding.root.findViewById(R.id.exo_play)
-        playButton.setOnClickListener { sourceExoPlayer.play() }
-
-        val playListener = object : Player.Listener {
-            override fun onIsPlayingChanged(isPlaying: Boolean) {
-                super.onIsPlayingChanged(isPlaying)
-                if (isPlaying) {
-                    playButton.visibility = View.GONE
-                    pauseButton.visibility = View.VISIBLE
-                } else {
-                    playButton.visibility = View.VISIBLE
-                    pauseButton.visibility = View.GONE
-                }
-            }
-        }
-        mExoPlayer.addListener(playListener)
-        playingStateListener = playListener
-
-        // Run once to set initial state of play or pause buttons
-        playListener.onIsPlayingChanged(sourceExoPlayer.isPlaying)
-    }
-
-    override fun onBackPressed() {
-        val isPlaying = mExoPlayer.isPlaying
-        if (isPlaying) {
-            mExoPlayer.pause()
-        }
-        setOnDismissListener {
-            disableImmersiveMode()
-            playingStateListener?.let {
-                mExoPlayer.removeListener(it)
-            }
-            switchTargetViewToSource()
-            if (isPlaying) {
-                sourceExoPlayer.play()
-            }
-            sourceView.showController()
-        }
-        dismiss()
-    }
-
-    private fun switchTargetViewToSource() {
-        if (shouldUseRotatedVideoWorkaround) {
-            sourceExoPlayer.seekTo(mExoPlayer.currentPosition)
-        } else {
-            PlayerView.switchTargetView(sourceExoPlayer, binding.videoPlayer, sourceView)
-        }
-    }
-
-    private fun enableImmersiveMode() {
-        activity.window?.let {
-            hideInset(it, WindowInsetsCompat.Type.systemBars())
-        }
-    }
-
-    private fun hideInset(window: Window, type: Int) {
-        val windowInsetsController =
-            WindowCompat.getInsetsController(window, window.decorView)
-        windowInsetsController.systemBarsBehavior =
-            WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
-        windowInsetsController.hide(type)
-    }
-
-    private fun disableImmersiveMode() {
-        activity.window?.let {
-            val windowInsetsController =
-                WindowCompat.getInsetsController(it, it.decorView)
-            windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
-        } ?: return
-    }
-
-    companion object {
-        private val TAG = PreviewVideoFullscreenDialog::class.simpleName
-    }
-}

+ 0 - 29
app/src/main/res/layout/dialog_preview_video.xml

@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
-  Nextcloud Android client application
-
-  @author Tobias Kaminsky
-  Copyright (C) 2021 Tobias Kaminsky
-  Copyright (C) 2021 Nextcloud GmbH
- 
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU Affero General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
- 
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  GNU Affero General Public License for more details.
- 
-  You should have received a copy of the GNU Affero General Public License
-  along with this program. If not, see <https://www.gnu.org/licenses/>.
--->
-<androidx.media3.ui.PlayerView xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/videoPlayer"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:layout_gravity="center"
-    android:background="@color/black"
-    app:show_buffering="always"
-    app:controller_layout_id="@layout/exo_player_control_view" />

+ 0 - 110
app/src/main/res/layout/exo_player_control_view.xml

@@ -1,110 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2016 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:layout_gravity="bottom"
-    android:layoutDirection="ltr"
-    android:background="#CC000000"
-    android:orientation="vertical"
-    tools:targetApi="28">
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="center"
-        android:paddingTop="4dp"
-        android:orientation="horizontal">
-
-        <ImageButton
-            android:id="@id/exo_prev"
-            style="@style/FullScreenExoControlButton"
-            android:background="?attr/selectableItemBackgroundBorderless"
-            android:src="@drawable/exo_controls_previous"
-            android:contentDescription="@string/exo_controls_previous_description" />
-
-        <ImageButton
-            android:id="@id/exo_rew"
-            style="@style/FullScreenExoControlButton"
-            android:contentDescription="@string/exo_controls_rewind_description"
-            android:src="@drawable/exo_controls_rewind" />
-
-        <ImageButton
-            android:id="@id/exo_play"
-            style="@style/FullScreenExoControlButton"
-            android:contentDescription="@string/exo_controls_play_description"
-            android:src="@drawable/exo_controls_play"
-            android:visibility="gone"
-            tools:visibility="visible" />
-
-        <ImageButton
-            android:id="@id/exo_pause"
-            style="@style/FullScreenExoControlButton"
-            android:contentDescription="@string/exo_controls_pause_description"
-            android:src="@drawable/exo_controls_pause" />
-
-        <ImageButton
-            android:id="@id/exo_ffwd"
-            style="@style/FullScreenExoControlButton"
-            android:contentDescription="@string/exo_controls_fastforward_description"
-            android:src="@drawable/exo_controls_fastforward" />
-
-        <ImageButton
-            android:id="@+id/exo_exit_fs"
-            style="@style/FullScreenExoControlButton"
-            android:contentDescription="@string/exo_controls_fullscreen_exit_description"
-            android:src="@drawable/exo_styled_controls_fullscreen_exit" />
-
-    </LinearLayout>
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="4dp"
-        android:gravity="center_vertical"
-        android:orientation="horizontal">
-
-        <TextView
-            android:id="@id/exo_position"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textSize="14sp"
-            android:textStyle="bold"
-            android:layout_marginStart="@dimen/standard_margin"
-            android:paddingHorizontal="4dp"
-            android:includeFontPadding="false"
-            android:textColor="#FFBEBEBE" />
-
-        <View
-            android:id="@id/exo_progress_placeholder"
-            android:layout_width="0dp"
-            android:layout_weight="1"
-            android:layout_height="26dp" />
-
-        <TextView
-            android:id="@id/exo_duration"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:textSize="14sp"
-            android:textStyle="bold"
-            android:layout_marginEnd="@dimen/standard_margin"
-            android:paddingHorizontal="4dp"
-            android:includeFontPadding="false"
-            android:textColor="#FFBEBEBE" />
-
-    </LinearLayout>
-
-</LinearLayout>