Skip to content
Open
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 @@ -23,8 +23,10 @@ import android.content.Intent
import android.content.IntentFilter
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -544,12 +546,7 @@ class FileDisplayActivity :
return
}

val currentStorageManager: FileDataStorageManager = storageManager ?: run {
Log_OC.w(TAG, "storage manager is null, cannot init file")
return
}

val initialFile = resolveInitialFile(currentStorageManager) ?: run {
val initialFile = resolveInitialFile() ?: run {
Log_OC.e(TAG, "Could not retrieve root folder – cannot continue")
return
}
Expand Down Expand Up @@ -582,7 +579,7 @@ class FileDisplayActivity :
checkForNewDevVersionNecessary(applicationContext)
}

private fun resolveInitialFile(storageManager: FileDataStorageManager): OCFile? =
private fun resolveInitialFile(): OCFile? =
file?.let { findStoredFile(it, storageManager) } ?: storageManager.getFileByPath(OCFile.ROOT_PATH)

private fun findStoredFile(file: OCFile, storageManager: FileDataStorageManager): OCFile? {
Expand Down Expand Up @@ -887,7 +884,7 @@ class FileDisplayActivity :
return
}

val fileStorageManager = storageManager ?: FileDataStorageManager(user, contentResolver)
val fileStorageManager = storageManager
val weakContext = WeakReference<Context>(this)
val task = FetchRemoteFileTask(user, fileId, fileStorageManager, lifecycleScope, capability, weakContext)
task.run(showFile = { (fetchedFile, message) ->
Expand All @@ -899,7 +896,7 @@ class FileDisplayActivity :
private fun openFileByPath(user: User, filePath: String) {
setUser(user)

val fileStorageManager = storageManager ?: FileDataStorageManager(user, contentResolver)
val fileStorageManager = storageManager
lifecycleScope.launch {
val client = clientRepository.getOwncloudClient() ?: run {
onFileRequestError(null)
Expand Down Expand Up @@ -1203,10 +1200,8 @@ class FileDisplayActivity :
searchMenuItem.isVisible = false
searchText.setOnClickListener {
showSearchView()
searchView?.postDelayed({
searchView?.isIconified = false
searchView?.requestFocusFromTouch()
}, SEARCH_VIEW_FOCUS_DELAY)
searchView?.isIconified = false
searchView?.postDelayed({ searchView?.requestFocusFromTouch() }, SEARCH_VIEW_FOCUS_DELAY)
}

drawerMenuItemsToShowHide = listOf(searchMenuItem)
Expand Down Expand Up @@ -1266,6 +1261,10 @@ class FileDisplayActivity :
private fun setupSearchView(view: SearchView) {
viewThemeUtils.androidx.themeToolbarSearchView(view)

// when search expanded makes transparent of the background
view.findViewById<View>(androidx.appcompat.R.id.search_plate)?.backgroundTintList =
ColorStateList.valueOf(Color.TRANSPARENT)

if (searchQuery.isNotEmpty()) {
view.post { restoreSearchQuery() }
}
Expand Down Expand Up @@ -1570,7 +1569,7 @@ class FileDisplayActivity :
val syncFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH)
val syncResultId = intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)
val syncResult = DataHolderUtil.getInstance().retrieve(syncResultId)
val isSameAccount = isCurrentAccount(accountName) && storageManager != null
val isSameAccount = isCurrentAccount(accountName)
val fileList = listOfFilesFragment

if (isSameAccount) {
Expand Down Expand Up @@ -1960,7 +1959,6 @@ class FileDisplayActivity :

private fun requestDownloadOfWaitingPreview() {
val previousFile = waitingToPreview ?: return
if (storageManager == null) return

val refreshedFile = storageManager.getFileById(previousFile.fileId)
waitingToPreview = refreshedFile
Expand Down Expand Up @@ -2175,8 +2173,8 @@ class FileDisplayActivity :

connectivityService.isNetworkAndServerAvailable { isAvailable ->
when {
isAvailable -> fileOperationsHelper?.removeFiles(filesToRemove, onlyLocalCopy, true)
onlyLocalCopy -> fileOperationsHelper?.removeFiles(filesToRemove, true, true)
isAvailable -> fileOperationsHelper.removeFiles(filesToRemove, onlyLocalCopy, true)
onlyLocalCopy -> fileOperationsHelper.removeFiles(filesToRemove, true, true)
else -> filesToRemove.forEach { fileDataStorageManager.addRemoveFileOfflineOperation(it) }
}
onFilesRemoved()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.ui.activity.drawer.DrawerActivity
import com.owncloud.android.ui.fragment.OCFileListFragment
import com.owncloud.android.ui.fragment.SearchType
import com.owncloud.android.ui.navigation.animator.SearchBarTransition
import com.owncloud.android.ui.navigation.model.ActionBarStyle
import com.owncloud.android.utils.theme.ThemeUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
Expand Down Expand Up @@ -69,6 +70,7 @@ abstract class ToolbarActivity :
private var infoBoxMessage: TextView? = null

private var actionBarStyle = ActionBarStyle.Plain
private val searchBarTransition by lazy { SearchBarTransition(toolbar, homeSearchToolbar) }

private val isToolbarBound: Boolean
get() = ::homeSearchToolbar.isInitialized
Expand Down Expand Up @@ -100,6 +102,10 @@ abstract class ToolbarActivity :

private fun isActionBarDisplayed(style: ActionBarStyle): Boolean {
if (!isToolbarBound) return false

// needed to prevent plain toolbar returning from unified share
if (style == ActionBarStyle.Plain && searchBarTransition.isExpanded) return true

val (displayed, hidden) = when (style) {
ActionBarStyle.Plain -> defaultToolbar to homeSearchToolbar
ActionBarStyle.Search -> homeSearchToolbar to defaultToolbar
Expand Down Expand Up @@ -218,7 +224,7 @@ abstract class ToolbarActivity :

fun showSearchView() {
if (actionBarStyle != ActionBarStyle.Search) return
switchActionBar(ActionBarStyle.Plain)
searchBarTransition.expand()
}

fun hideSearchView(chosenFile: OCFile?) {
Expand All @@ -229,7 +235,8 @@ abstract class ToolbarActivity :
private fun switchActionBar(style: ActionBarStyle) {
val appBar = appBar ?: return

viewThemeUtils.material.themeToolbar(toolbar)
searchBarTransition.syncWith(style)
if (!searchBarTransition.isExpanded) viewThemeUtils.material.themeToolbar(toolbar)

when (style) {
ActionBarStyle.Search -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class OCFileListAdapter(

private val allFiles = mutableListOf<OCFile>()
private val recommendedFiles = mutableListOf<OCFile>()
private var recommendedFilesAdapter: RecommendedFilesAdapter? = null
private val recommendedFilesAdapter = RecommendedFilesAdapter(this, recommendedFiles)

private val popupDateFormat = SimpleDateFormat(DateFormatPattern.FullMonthWithYear.pattern, Locale.getDefault())
private val footerId = UUID.randomUUID().leastSignificantBits
Expand Down Expand Up @@ -568,6 +568,7 @@ class OCFileListAdapter(
fun updateRecommendedFiles(value: List<OCFile>) {
recommendedFiles.clear()
recommendedFiles.addAll(value)
recommendedFilesAdapter.notifyDataSetChanged()
differ.syncHeaderState()
notifyDataSetChanged()
}
Expand Down Expand Up @@ -604,11 +605,7 @@ class OCFileListAdapter(
}

private fun bindHeader(holder: OCFileListHeaderViewHolder) {
val visibleRecommendedFilesAdapter = if (shouldShowRecommendedFiles()) {
RecommendedFilesAdapter(this, recommendedFiles).also { recommendedFilesAdapter = it }
} else {
null
}
val visibleRecommendedFilesAdapter = recommendedFilesAdapter.takeIf { shouldShowRecommendedFiles() }
headerBinder.bind(holder, currentDirectory, visibleRecommendedFilesAdapter)
}

Expand Down Expand Up @@ -658,7 +655,7 @@ class OCFileListAdapter(
recommendedFiles.isNotEmpty() && currentDirectory?.isRootDirectory == true

private fun visibleRecommendedFilesAdapterFor(file: OCFile): RecommendedFilesAdapter? =
recommendedFilesAdapter?.takeIf { shouldShowRecommendedFiles() && file.isRecommendedFile }
recommendedFilesAdapter.takeIf { shouldShowRecommendedFiles() && file.isRecommendedFile }

private fun notifyItemChangedIfPresent(file: OCFile, payload: Any? = null) {
val position = getItemPosition(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class OCFileListDiffer(

if (shouldShowHeader == isHeaderDisplayed) {
if (shouldShowHeader) {
adapter.notifyItemChanged(0)
adapter.notifyItemChanged(0, REBIND_PAYLOAD)
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ internal class OCFileListHeaderBinder(
}

binding.recommendedFilesRecyclerView.run {
layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
adapter = recommendedFilesAdapter
if (layoutManager == null) {
layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
}
if (adapter !== recommendedFilesAdapter) {
adapter = recommendedFilesAdapter
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.owncloud.android.ui.navigation.animator

import android.animation.ValueAnimator
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.view.animation.AnimationUtils
import androidx.core.animation.doOnEnd
import androidx.core.view.isVisible
import androidx.core.view.marginEnd
import androidx.core.view.marginStart
import androidx.core.view.updateLayoutParams
import com.owncloud.android.R
import kotlin.math.roundToInt

class SearchBarSideButtonsAnimator(homeToolbar: ViewGroup, private val durationMillis: Long) {

private val searchCard: View = homeToolbar.findViewById(R.id.home_search_container)
private val leadingButton: View = homeToolbar.findViewById(R.id.menu_button)
private val trailingButton: View = homeToolbar.findViewById(R.id.switch_account_button)

private val leadingWidth = leadingButton.layoutParams.width
private val leadingIdleMarginStart = leadingButton.marginStart
private val leadingIdleMarginEnd = leadingButton.marginEnd
private val trailingWidth = trailingButton.layoutParams.width
private val trailingIdleMarginEnd = trailingButton.marginEnd
private val cardIdleMarginStart = searchCard.marginStart
private val cardIdleMarginEnd = searchCard.marginEnd
private val expandedMargin = homeToolbar.resources.getDimensionPixelSize(R.dimen.standard_margin)

private val interpolator =
AnimationUtils.loadInterpolator(homeToolbar.context, android.R.interpolator.fast_out_slow_in)

private var animator: ValueAnimator? = null

private var hiddenFraction = SHOWN

fun hide() = animateTo(HIDDEN)

fun show() = animateTo(SHOWN)

// Animates hiddenFraction from its current value to target over durationMillis.
// SHOWN (0f) = idle home bar, HIDDEN (1f) = hamburger and avatar completely gone (search open).
// Example for hide(), avatar width 48 -> 0 (real timings follow the fast_out_slow_in easing):
//
// | time | hiddenFraction | avatar width | avatar alpha |
// |--------|----------------|--------------|--------------|
// | 0 ms | 0.0 (0%) | 48 | 1.0 |
// | 100 ms | 0.25 (25%) | 36 | 0.75 |
// | 200 ms | 0.5 (50%) | 24 | 0.5 |
// | 300 ms | 0.75 (75%) | 12 | 0.25 |
// | 400 ms | 1.0 (100%) | 0 | 0.0 |
//
// show() runs the same table backwards (1f -> 0f), so everything returns to its idle size.
private fun animateTo(target: Float) {
animator?.cancel()
applyHiddenFraction(hiddenFraction)
setButtonsVisible(true)

animator = ValueAnimator.ofFloat(hiddenFraction, target).apply {
duration = durationMillis
interpolator = this@SearchBarSideButtonsAnimator.interpolator
addUpdateListener {
// Called on every screen frame so that we can apply transition for each frame
hiddenFraction = it.animatedValue as Float
applyHiddenFraction(hiddenFraction)
}
doOnEnd { if (hiddenFraction == HIDDEN) settleHidden() }
start()
}
}

private fun applyHiddenFraction(fraction: Float) {
val leadingCurrentWidth = interpolate(leadingWidth, 0, fraction)
leadingButton.updateLayoutParams<MarginLayoutParams> {
width = leadingCurrentWidth
marginStart = interpolate(leadingIdleMarginStart, expandedMargin, fraction)
marginEnd = interpolate(leadingIdleMarginEnd, 0, fraction)
}
leadingButton.scrollX = -(leadingWidth - leadingCurrentWidth) / 2

val trailingCurrentWidth = interpolate(trailingWidth, 0, fraction)
trailingButton.updateLayoutParams<MarginLayoutParams> {
width = trailingCurrentWidth
marginEnd = interpolate(trailingIdleMarginEnd, expandedMargin, fraction)
}
trailingButton.scrollX = (trailingWidth - trailingCurrentWidth) / 2

searchCard.updateLayoutParams<MarginLayoutParams> {
marginStart = cardIdleMarginStart
marginEnd = interpolate(cardIdleMarginEnd, 0, fraction)
}

val alpha = VISIBLE_ALPHA - fraction
leadingButton.alpha = alpha
trailingButton.alpha = alpha
}

private fun settleHidden() {
applyHiddenFraction(SHOWN)
setButtonsVisible(false)

searchCard.updateLayoutParams<MarginLayoutParams> {
marginStart = expandedMargin
marginEnd = expandedMargin
}
}

private fun setButtonsVisible(visible: Boolean) {
leadingButton.isVisible = visible
trailingButton.isVisible = visible
}

// Value partway between start and end: fraction 0f gives start, 1f gives end, 0.25f is a quarter of the way,
// e.g. interpolate(48, 0, 0.25f) = 48 + (0 - 48) * 0.25 = 36
private fun interpolate(start: Int, end: Int, fraction: Float): Int =
(start + (end - start) * fraction).roundToInt()

private companion object {
const val SHOWN = 0f
const val HIDDEN = 1f
const val VISIBLE_ALPHA = 1f
}
}
Loading
Loading