Skip to content
Closed
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 @@ -10,6 +10,7 @@ import android.content.Intent
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.nextcloud.test.Flaky
import com.owncloud.android.AbstractIT
import com.owncloud.android.R
import org.junit.Assert.assertEquals
Expand All @@ -31,6 +32,7 @@ class LauncherActivityIT : AbstractIT() {
}

@Test
@Flaky(reason = "Opening FileDisplayActivity can keep the main thread busy past the launch timeout")
fun testSplashScreenWithTitlesShouldShowTitles() {
val activity = launchLauncherActivity()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.nmc.android.ui.LauncherActivity
import com.owncloud.android.R
import com.owncloud.android.authentication.AuthenticatorActivity
import com.owncloud.android.ui.activity.DrawerActivity
import com.owncloud.android.ui.preview.PreviewImageActivity
import com.owncloud.android.utils.theme.ViewThemeUtils
import dynamiccolor.MaterialDynamicColors
import javax.inject.Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

package com.nextcloud.utils.extensions

import android.view.View
import android.view.Window
import androidx.appcompat.app.ActionBar
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat

fun ActionBar.toggle(show: Boolean) {
if (show) {
Expand All @@ -21,27 +16,3 @@ fun ActionBar.toggle(show: Boolean) {
hide()
}
}

fun Window.showSystemBar(show: Boolean, view: View) {
WindowCompat.getInsetsController(this, view).run {
val types = WindowInsetsCompat.Type.systemBars()
if (show) {
show(types)
} else {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(types)
}
}
}

fun Window.showNavigationBar(show: Boolean, view: View) {
WindowCompat.getInsetsController(this, view).run {
val types = WindowInsetsCompat.Type.navigationBars()
if (show) {
show(types)
} else {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(types)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
Expand Down Expand Up @@ -102,7 +103,9 @@ class PreviewImageActivity :
private val downloadFinishReceiver = DownloadFinishReceiver()

private val windowInsetsController: WindowInsetsControllerCompat by lazy {
WindowCompat.getInsetsController(window, window.decorView)
WindowCompat.getInsetsController(window, window.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}

private var isDownloadWorkStarted = false
Expand All @@ -123,7 +126,7 @@ class PreviewImageActivity :

if (savedInstanceState != null &&
!savedInstanceState.getBoolean(
KEY_SYSTEM_VISIBLE,
KEY_ACTION_BAR_VISIBLE,
true
) &&
supportActionBar != null
Expand Down Expand Up @@ -158,6 +161,15 @@ class PreviewImageActivity :

lifecycle.addObserver(sendShareDownloader)
sendShareDownloader.restoreState(savedInstanceState)
applyDarkSystemBars()
}

private fun applyDarkSystemBars() {
windowInsetsController.isAppearanceLightStatusBars = false
windowInsetsController.isAppearanceLightNavigationBars = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
}

override fun onNewIntent(intent: Intent?) {
Expand Down Expand Up @@ -380,7 +392,7 @@ class PreviewImageActivity :
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putBoolean(KEY_WAITING_FOR_BINDER, screenState == PreviewImageActivityState.WaitingForBinder)
outState.putBoolean(KEY_SYSTEM_VISIBLE, isSystemUIVisible)
outState.putBoolean(KEY_ACTION_BAR_VISIBLE, isActionBarVisible)
sendShareDownloader.saveState(outState)
}

Expand Down Expand Up @@ -539,12 +551,12 @@ class PreviewImageActivity :
updatePagerDisplayCutOutPadding(isInPictureInPictureMode, displayCutOutSafeInsetTop())

if (isInPictureInPictureMode) {
wasSystemUiVisibleBeforePictureInPicture = isSystemUIVisible
wasActionBarVisibleBeforePictureInPicture = isActionBarVisible
toggleActionBarVisibility(false)
return
}

toggleActionBarVisibility(wasSystemUiVisibleBeforePictureInPicture)
toggleActionBarVisibility(wasActionBarVisibleBeforePictureInPicture)

if (lifecycle.currentState != Lifecycle.State.CREATED) return

Expand Down Expand Up @@ -629,19 +641,19 @@ class PreviewImageActivity :
}
}

val isSystemUIVisible: Boolean
val isActionBarVisible: Boolean
get() = supportActionBar == null || supportActionBar?.isShowing == true

fun toggleFullScreen() {
val rootInsets = ViewCompat.getRootWindowInsets(window.decorView) ?: return

// the content is laid out edge to edge so that showing and hiding the bars does not move it
WindowCompat.setDecorFitsSystemWindows(window, false)

if (rootInsets.isVisible(WindowInsetsCompat.Type.systemBars())) {
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
val showBars = !isActionBarVisible
toggleActionBarVisibility(showBars)
if (showBars) {
windowInsetsController.show(WindowInsetsCompat.Type.navigationBars())
} else {
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
}
}

Expand Down Expand Up @@ -675,7 +687,7 @@ class PreviewImageActivity :
const val EXTRA_VIRTUAL_TYPE: String = "EXTRA_VIRTUAL_TYPE"
const val EXTRA_MEDIA_STATE: String = "EXTRA_MEDIA_STATE"
private const val KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER"
private const val KEY_SYSTEM_VISIBLE = "TRUE"
private const val KEY_ACTION_BAR_VISIBLE = "TRUE"
private const val NO_POSITION = -1

fun previewFileIntent(context: Context?, user: User?, file: OCFile?): Intent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ class PreviewImageFragment :
if (binding.image.drawable is LayerDrawable) {
val layerDrawable = binding.image.drawable as LayerDrawable

val layerOne = if (previewImageActivity?.isSystemUIVisible == true) {
val layerOne = if (previewImageActivity?.isActionBarVisible == true) {
ResourcesCompat.getDrawable(resources, R.color.bg_default, null)
} else {
ResourcesCompat.getDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import com.nextcloud.ui.fileactions.FileActionsBottomSheet
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.getSerializableArgument
import com.nextcloud.utils.extensions.setVisibilityWithAnimation
import com.nextcloud.utils.extensions.showNavigationBar
import com.nextcloud.utils.extensions.showSystemBar
import com.owncloud.android.R
import com.owncloud.android.databinding.PreviewPlaybackFragmentBinding
import com.owncloud.android.datamodel.OCFile
Expand Down Expand Up @@ -123,7 +121,9 @@ class PreviewPlaybackFragment :
private var renderedVideoSize: VideoSize? = null

private var pictureInPictureCallback: OnBackPressedCallback? = null
private var isFullScreen = false

private val previewActivity: PreviewImageActivity?
get() = activity as? PreviewImageActivity

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -183,7 +183,7 @@ class PreviewPlaybackFragment :
}

private fun onOverflowClick(isManualClick: Boolean = false) {
val storageManager = previewActivity()?.storageManager ?: return
val storageManager = previewActivity?.storageManager ?: return
val updatedFile = storageManager.getFileById(file.fileId)

// check for albums file for album file both local and remoteId will be same configured at operation level
Expand All @@ -203,7 +203,7 @@ class PreviewPlaybackFragment :
}

private fun fetchFileMetaDataIfAbsent(ocFile: OCFile) {
val previewActivity = previewActivity() ?: return
val previewActivity = previewActivity ?: return
val context = context ?: return

previewActivity.showLoadingDialog(getString(R.string.wait_a_moment))
Expand Down Expand Up @@ -233,7 +233,7 @@ class PreviewPlaybackFragment :

@Suppress("CyclomaticComplexMethod")
private fun onFileActionChosen(itemId: Int) {
val previewActivity = previewActivity() ?: return
val previewActivity = previewActivity ?: return
val fileOperationsHelper = previewActivity.fileOperationsHelper

when (itemId) {
Expand Down Expand Up @@ -291,7 +291,7 @@ class PreviewPlaybackFragment :
viewLifecycleOwner,
enabled = false
) {
if (previewActivity()?.enterPictureInPicture() == true) {
if (previewActivity?.enterPictureInPicture() == true) {
return@addCallback
}

Expand Down Expand Up @@ -392,7 +392,7 @@ class PreviewPlaybackFragment :
}

private fun showPageOfCurrentItem(state: PlaybackState?) {
val previewActivity = previewActivity() ?: return
val previewActivity = previewActivity ?: return
val localId = state?.currentItemState?.file?.id?.toLongOrNull()
if (localId != null && previewActivity.showFilePage(localId)) return

Expand All @@ -401,19 +401,12 @@ class PreviewPlaybackFragment :
}
}

private fun previewActivity(): PreviewImageActivity? = activity as? PreviewImageActivity

private fun isInPictureInPictureMode(): Boolean = activity?.isInPictureInPictureMode == true

private fun toggleFullScreen() {
val previewActivity = previewActivity() ?: return
isFullScreen = !isFullScreen
previewActivity.toggleActionBarVisibility(!isFullScreen)
binding.playerControlView.setVisibilityWithAnimation(!isFullScreen)
previewActivity.window.run {
showSystemBar(!isFullScreen, binding.root)
showNavigationBar(!isFullScreen, binding.root)
}
val previewActivity = previewActivity ?: return
binding.playerControlView.setVisibilityWithAnimation(!previewActivity.isActionBarVisible)
previewActivity.toggleFullScreen()
}

private fun updatePlayerControlsVisibility() {
Expand All @@ -422,8 +415,7 @@ class PreviewPlaybackFragment :
return
}

// playback updates arrive every second, so they must not undo full screen or cut the fade short
if (!isFullScreen) {
if (previewActivity?.isActionBarVisible == true) {
binding.playerControlView.isVisible = true
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,6 @@
<item name="android:textColor">@color/player_default_text_color</item>
</style>

<style name="ShapeAppearance.App.Player.Media" parent="ShapeAppearance.Material3.Corner.None" />

<style name="ShapeAppearance.App.Player.AlbumCover" parent="ShapeAppearance.Material3.Corner.Large" />

<style name="PlayerSliderStyle" parent="Widget.Material3.Slider">
Expand Down