Skip to content
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 @@ -181,7 +181,7 @@ public abstract class FileActivity extends DrawerActivity
@Inject public ConnectivityService connectivityService;

@Inject
BackgroundJobManager backgroundJobManager;
protected BackgroundJobManager backgroundJobManager;

@Inject
EditorUtils editorUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2828,6 +2828,7 @@ class FileDisplayActivity :
initFile()
}

@Suppress("LongMethod")
private fun initFile() {
val userOpt = user
if (userOpt.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ internal class LinkShareViewHolder(itemView: View) : RecyclerView.ViewHolder(ite
}
}

@Suppress("ReturnCount")
private fun setSubline(binding: FileDetailsShareLinkShareItemBinding?, context: Context?, publicShare: OCShare) {
if (binding == null || context == null) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ class OCFileListDelegate(
fileUploadHelper.isUploading(file.remotePath, user.accountName)
}

@Suppress("ComplexCondition")
private fun showLocalFileIndicator(file: OCFile, holder: ListViewHolder) {
var isFolderDown = false
if (file.isFolder && !file.isEncrypted && file.fileLength != 0L && file.etag.isNotBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.MoreExecutors
import com.nextcloud.client.account.User
import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.download.FileDownloadHelper
import com.nextcloud.client.media.BackgroundPlayerService
import com.nextcloud.client.media.ErrorFormat
import com.nextcloud.client.media.ExoplayerListener
import com.nextcloud.client.media.NextcloudExoPlayer.createNextcloudExoplayer
import com.nextcloud.client.network.ClientFactory
import com.nextcloud.client.network.ClientFactory.CreationException
import com.nextcloud.common.NextcloudClient
import com.nextcloud.ui.fileactions.FileAction
import com.nextcloud.ui.fileactions.FileActionsBottomSheet.Companion.newInstance
import com.nextcloud.ui.fileactions.FileActionsBottomSheet.ResultListener
Expand Down Expand Up @@ -101,7 +100,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.lang.ref.WeakReference
import javax.inject.Inject

/**
* This activity shows a preview of a downloaded media file (audio or video).
Expand All @@ -126,15 +124,7 @@ class PreviewMediaActivity :
private var savedPlaybackPosition: Long = 0
private var autoplay = true
private var streamUri: Uri? = null

@Inject
lateinit var clientFactory: ClientFactory

@Inject
lateinit var accountManager: UserAccountManager

@Inject
lateinit var backgroundJobManager: BackgroundJobManager
private var nextcloudClient: NextcloudClient? = null

private lateinit var binding: ActivityPreviewMediaBinding
private var emptyListView: ViewGroup? = null
Expand Down Expand Up @@ -332,6 +322,7 @@ class PreviewMediaActivity :
val client = clientRepository.getNextcloudClient() ?: return@launch

withContext(Dispatchers.Main) {
nextcloudClient = client
videoPlayer = createNextcloudExoplayer(this@PreviewMediaActivity, client)
val uniqueSessionId = "preview_session_" + System.currentTimeMillis()
videoMediaSession = MediaSession.Builder(this@PreviewMediaActivity, videoPlayer as Player)
Expand Down Expand Up @@ -491,17 +482,36 @@ class PreviewMediaActivity :
PlayerView.ControllerVisibilityListener { visibility ->
if (visibility == View.VISIBLE) {
windowInsetsController.show(type)
supportActionBar!!.show()
supportActionBar?.show()
} else if (visibility == View.GONE) {
windowInsetsController.hide(type)
supportActionBar!!.hide()
supportActionBar?.hide()
}
}
)
it.player = videoPlayer
it.setFullscreenButtonClickListener { startFullScreenVideo() }
}
}

private fun startFullScreenVideo() {
val client = nextcloudClient ?: return
val player = videoPlayer ?: return
val dialog = PreviewVideoFullscreenDialog(
this,
client,
player,
binding.exoplayerView
)
.apply {
setOnDismissListener {
setupVideoView()
}
}

dialog.show()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.custom_menu_placeholder, menu)

Expand Down Expand Up @@ -592,7 +602,7 @@ class PreviewMediaActivity :
list,
this,
binding.root,
backgroundJobManager
this.backgroundJobManager
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.annotation.OptIn
import androidx.annotation.StringRes
import androidx.core.net.toUri
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.marginBottom
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -40,6 +46,7 @@ import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.MediaSession
import androidx.media3.ui.DefaultTimeBar
import com.nextcloud.client.account.User
import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.di.Injectable
Expand All @@ -55,7 +62,6 @@ import com.nextcloud.ui.fileactions.FileAction
import com.nextcloud.ui.fileactions.FileActionsBottomSheet.Companion.newInstance
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.getTypedActivity
import com.nextcloud.utils.extensions.logFileSize
import com.owncloud.android.R
import com.owncloud.android.databinding.FragmentPreviewMediaBinding
import com.owncloud.android.datamodel.OCFile
Expand Down Expand Up @@ -89,7 +95,7 @@ import javax.inject.Inject
*
* DO NOT CALL IT: an [OCFile] and [User] must be provided for a successful construction
*/
@Suppress("NestedBlockDepth", "ComplexMethod", "LongMethod", "TooManyFunctions")
@Suppress("NestedBlockDepth", "ComplexMethod", "LongMethod", "TooManyFunctions", "ReturnCount")
class PreviewMediaFragment :
FileFragment(),
OnTouchListener,
Expand Down Expand Up @@ -117,6 +123,7 @@ class PreviewMediaFragment :
private var exoPlayer: ExoPlayer? = null
private var mediaSession: MediaSession? = null
private var nextcloudClient: NextcloudClient? = null
private var isFullscreenActive = false

@OptIn(UnstableApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -167,7 +174,6 @@ class PreviewMediaFragment :
}

private fun initArguments(bundle: Bundle) {
file.logFileSize(TAG)
file = bundle.getParcelableArgument(FILE, OCFile::class.java)
user = bundle.getParcelableArgument(USER, User::class.java)

Expand All @@ -176,6 +182,36 @@ class PreviewMediaFragment :
isLivePhoto = bundle.getBoolean(IS_LIVE_PHOTO)
}

override fun onResume() {
super.onResume()
applyWindowInsets()
}

@OptIn(UnstableApi::class)
private fun applyWindowInsets() {
binding.root.post {
val rootInsets = ViewCompat.getRootWindowInsets(binding.root) ?: return@post
val insets = rootInsets.getInsets(
WindowInsetsCompat.Type.systemBars() or
WindowInsetsCompat.Type.displayCutout()
)
val playerView = binding.exoplayerView
val exoControls = playerView
.findViewById<FrameLayout>(androidx.media3.ui.R.id.exo_bottom_bar)
val exoProgress = playerView
.findViewById<DefaultTimeBar>(androidx.media3.ui.R.id.exo_progress)
val progressOriginalMargin = exoProgress?.marginBottom ?: 0
exoControls?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = insets.bottom
}
exoProgress?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = insets.bottom + progressOriginalMargin
}
exoControls?.updatePadding(left = insets.left, right = insets.right)
exoProgress?.updatePadding(left = insets.left, right = insets.right)
}
}

private fun setLoadingView() {
binding.progress.visibility = View.VISIBLE
binding.emptyView.emptyListView.visibility = View.GONE
Expand All @@ -196,7 +232,6 @@ class PreviewMediaFragment :

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
file.logFileSize(TAG)
toggleDrawerLockMode(containerActivity, DrawerLayout.LOCK_MODE_LOCKED_CLOSED)

outState.run {
Expand Down Expand Up @@ -431,7 +466,6 @@ class PreviewMediaFragment :
}
}

@Suppress("ReturnCount")
private fun loadStreamUrl(user: User?, clientFactory: ClientFactory?, fileId: Long): Uri? {
val client: OwnCloudClient? = try {
clientFactory?.create(user)
Expand Down Expand Up @@ -466,6 +500,9 @@ class PreviewMediaFragment :
}

override fun onStop() {
if (!isFullscreenActive) {
releaseVideoPlayer()
}
releaseVideoPlayer()
super.onStop()
}
Expand All @@ -483,13 +520,24 @@ class PreviewMediaFragment :
}

private fun startFullScreenVideo() {
activity?.let { activity ->
nextcloudClient?.let { client ->
exoPlayer?.let { player ->
PreviewVideoFullscreenDialog(activity, client, player, binding.exoplayerView).show()
}
val activity = activity ?: return
val client = nextcloudClient ?: return
val player = exoPlayer ?: return

isFullscreenActive = true
val dialog = PreviewVideoFullscreenDialog(
activity,
client,
player,
binding.exoplayerView
).apply {
setOnDismissListener {
isFullscreenActive = false
setupVideoView()
}
}

dialog.show()
}

override fun onConfigurationChanged(newConfig: Configuration) {
Expand Down Expand Up @@ -576,20 +624,14 @@ class PreviewMediaFragment :
startPlaybackPosition: Long,
autoplay: Boolean,
isLivePhoto: Boolean
): PreviewMediaFragment {
val previewMediaFragment = PreviewMediaFragment()

val bundle = Bundle().apply {
): PreviewMediaFragment = PreviewMediaFragment().apply {
arguments = Bundle().apply {
putParcelable(FILE, fileToDetail)
putParcelable(USER, user)
putLong(PLAYBACK_POSITION, startPlaybackPosition)
putBoolean(AUTOPLAY, autoplay)
putBoolean(IS_LIVE_PHOTO, isLivePhoto)
}

previewMediaFragment.arguments = bundle

return previewMediaFragment
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class PreviewVideoFullscreenDialog(
sourceView.showController()
}
dismiss()
isEnabled = false
}
}

Expand Down
Loading