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 @@ -50,8 +50,11 @@ import com.owncloud.android.utils.theme.ThemeUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.time.Duration.Companion.seconds

class AutoUploadFragment :
Fragment(),
Expand Down Expand Up @@ -82,6 +85,9 @@ class AutoUploadFragment :
private lateinit var dialogs: AutoUploadDialogs
private lateinit var clickHandler: AutoUploadClickHandler

private val maxSwipeRefreshInterval = 4.seconds
private var swipeRefreshTimeoutJob: Job? = null

private val intentHandler = AutoUploadIntentHandler()

private val folderPickers = AutoUploadPickers(this) {
Expand Down Expand Up @@ -130,7 +136,7 @@ class AutoUploadFragment :
setupStoragePermissionWarningBanner(activity, binding)
PermissionUtil.dismissStoragePermissionDialogFragment(activity)
if (PermissionUtil.checkStoragePermission(activity)) {
load(activity)
loadIfEmpty(activity)
}
uploadWarningCard?.bind(binding.autoUploadBatterySaverWarningCard)
}
Expand Down Expand Up @@ -206,7 +212,6 @@ class AutoUploadFragment :
lifecycleScope,
activity,
clock,
gridWidth,
clickHandler,
resources.getBoolean(R.bool.syncedFolder_light),
viewThemeUtils,
Expand All @@ -223,6 +228,11 @@ class AutoUploadFragment :
this.layoutManager = layoutManager
adapter = this@AutoUploadFragment.adapter
}

binding.swipeRefreshLayout.setOnRefreshListener {
load(activity)
stopSwipeRefreshAfterTimeout()
}
}

private fun addMenuProvider(activity: NavigatorActivity) {
Expand Down Expand Up @@ -258,15 +268,20 @@ class AutoUploadFragment :
// region Loading
private fun getItemsDisplayedPerFolder(): Int = resources.getInteger(R.integer.media_grid_width) * 2

@SuppressLint("NotifyDataSetChanged")
private fun load(activity: NavigatorActivity) {
private fun loadIfEmpty(activity: NavigatorActivity) {
if (adapter.itemCount > 0) {
return
}

emptyContent?.showLoadingContent()

load(activity)
}

@SuppressLint("NotifyDataSetChanged")
private fun load(activity: NavigatorActivity) {
val perFolderMediaItemLimit = getItemsDisplayedPerFolder()
val newItemAccountName = activity.account.name
emptyContent?.showLoadingContent()

viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
val currentAccountName = userAccountManager.user.accountName
Expand All @@ -276,10 +291,20 @@ class AutoUploadFragment :
adapter.setItems(items)
emptyContent?.showList()
openMediaFolderSettingsFromIntent()
binding?.swipeRefreshLayout?.isRefreshing = false
}
}
}

private fun stopSwipeRefreshAfterTimeout() {
swipeRefreshTimeoutJob?.cancel()
swipeRefreshTimeoutJob = viewLifecycleOwner.lifecycleScope.launch {
delay(maxSwipeRefreshInterval)

binding?.swipeRefreshLayout?.isRefreshing = false
}
}

private fun openMediaFolderSettingsFromIntent() {
val section = intentHandler.findMediaFolderSection(adapter) ?: return
adapter.getItem(section)?.let(clickHandler::onSyncFolderSettingsClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package com.owncloud.android.ui.fragment.autoUpload.adapter
import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Space
import androidx.annotation.VisibleForTesting
import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleCoroutineScope
Expand All @@ -35,15 +37,13 @@ class AutoUploadFolderAdapter(
private val lifecycleScope: LifecycleCoroutineScope,
private val context: Context,
private val clock: Clock,
gridWidth: Int,
private val clickListener: AutoUploadFolderClickListener,
private val light: Boolean,
private val viewThemeUtils: ViewThemeUtils,
private val powerManagementService: PowerManagementService,
private val connectivityService: ConnectivityService
) : SectionedRecyclerViewAdapter<SectionedViewHolder>() {

private val gridTotal = gridWidth * GRID_ROWS
private val mediaThumbnailGenerationJob = MediaThumbnailGenerationJob(context, viewThemeUtils)

private var items: List<SyncedFolderDisplayItem> = emptyList()
Expand Down Expand Up @@ -131,8 +131,11 @@ class AutoUploadFolderAdapter(
}

override fun getFooterViewType(section: Int): Int {
val showFooter = isFooterSection(section) && hiddenFolderCount > 0
val type = if (showFooter) AutoUploadFolderAdapterType.FOOTER else AutoUploadFolderAdapterType.EMPTY
val type = when {
isFooterSection(section) && hiddenFolderCount > 0 -> AutoUploadFolderAdapterType.FOOTER
isEmptyFolder(section) -> AutoUploadFolderAdapterType.EMPTY_FOLDER
else -> AutoUploadFolderAdapterType.EMPTY
}

return type.viewType
}
Expand All @@ -148,8 +151,15 @@ class AutoUploadFolderAdapter(
AutoUploadFolderAdapterType.FOOTER ->
FooterViewHolder(SyncedFoldersFooterBinding.inflate(inflater, parent, false))

AutoUploadFolderAdapterType.EMPTY ->
EmptyViewHolder(SyncedFoldersEmptyBinding.inflate(inflater, parent, false))
AutoUploadFolderAdapterType.EMPTY -> EmptyViewHolder(Space(parent.context))

AutoUploadFolderAdapterType.EMPTY_FOLDER -> EmptyFolderViewHolder(
SyncedFoldersEmptyBinding.inflate(
inflater,
parent,
false
)
)
}
}

Expand Down Expand Up @@ -186,6 +196,12 @@ class AutoUploadFolderAdapter(
holder.binding.footerText.setOnClickListener { toggleHiddenItemsVisibility() }
}

private fun isEmptyFolder(section: Int): Boolean {
val item = visibleItems.getOrNull(section) ?: return false

return item.filePaths.isNullOrEmpty()
}

override fun onBindViewHolder(
holder: SectionedViewHolder,
section: Int,
Expand All @@ -207,8 +223,9 @@ class AutoUploadFolderAdapter(
thumbnail.tag = file.hashCode()
lifecycleScope.launch { mediaThumbnailGenerationJob.load(file, thumbnail) }

val remainingFileCount = item.numberOfFiles - gridTotal
val showRemainingFileCount = remainingFileCount > 0 && position >= gridTotal - 1
val displayedFileCount = item.filePaths?.size ?: 0
val remainingFileCount = item.numberOfFiles - displayedFileCount
val showRemainingFileCount = remainingFileCount > 0 && position == displayedFileCount - 1
counter.text = String.format(Locale.US, "%d", remainingFileCount)
counterLayout.isVisible = showRemainingFileCount
thumbnailDarkener.isVisible = showRemainingFileCount
Expand All @@ -218,9 +235,7 @@ class AutoUploadFolderAdapter(

private class FooterViewHolder(val binding: SyncedFoldersFooterBinding) : SectionedViewHolder(binding.root)

private class EmptyViewHolder(binding: SyncedFoldersEmptyBinding) : SectionedViewHolder(binding.root)
private class EmptyViewHolder(view: View) : SectionedViewHolder(view)

companion object {
private const val GRID_ROWS = 2
}
private class EmptyFolderViewHolder(binding: SyncedFoldersEmptyBinding) : SectionedViewHolder(binding.root)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum class AutoUploadFolderAdapterType {
ITEM,
HEADER,
FOOTER,
EMPTY;
EMPTY,
EMPTY_FOLDER;

val viewType: Int
get() = ordinal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,33 @@ class AutoUploadDisplayItemFactory(
SyncedFolder.NOT_SCANNED_YET
)

fun createAutoUploadFolder(syncedFolder: SyncedFolderParcelable): SyncedFolderDisplayItem = SyncedFolderDisplayItem(
syncedFolder.id,
syncedFolder.localPath,
syncedFolder.remotePath,
syncedFolder.isWifiOnly,
syncedFolder.isChargingOnly,
syncedFolder.isExisting,
syncedFolder.isSubfolderByDate,
syncedFolder.account,
syncedFolder.uploadAction,
syncedFolder.nameCollisionPolicy.serialize(),
syncedFolder.isEnabled,
syncedFolder.enabledTimestampMs,
File(syncedFolder.localPath).name,
syncedFolder.type,
syncedFolder.isHidden,
syncedFolder.subFolderRule,
syncedFolder.isExcludeHidden,
syncedFolder.lastScanTimestampMs
)
fun createAutoUploadFolder(syncedFolder: SyncedFolderParcelable): SyncedFolderDisplayItem {
val localFolder = File(syncedFolder.localPath)
val files = SyncedFolderUtils.getFileList(localFolder)

return SyncedFolderDisplayItem(
syncedFolder.id,
syncedFolder.localPath,
syncedFolder.remotePath,
syncedFolder.isWifiOnly,
syncedFolder.isChargingOnly,
syncedFolder.isExisting,
syncedFolder.isSubfolderByDate,
syncedFolder.account,
syncedFolder.uploadAction,
syncedFolder.nameCollisionPolicy.serialize(),
syncedFolder.isEnabled,
syncedFolder.enabledTimestampMs,
getDisplayFilePaths(files),
localFolder.name,
files.size.toLong(),
syncedFolder.type,
syncedFolder.isHidden,
syncedFolder.subFolderRule,
syncedFolder.isExcludeHidden,
syncedFolder.lastScanTimestampMs
)
}

fun updateAutoUploadFolderItem(item: SyncedFolderDisplayItem, syncedFolder: SyncedFolderParcelable) {
item.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ class AutoUploadClickHandler(
}

fun onSaveAutoUploadFolderPreference(syncedFolder: SyncedFolderParcelable) {
val item = if (isNewCustomFolder(syncedFolder)) {
if (isNewCustomFolder(syncedFolder)) {
addFolder(syncedFolder)
} else {
updateFolder(syncedFolder)
return
}

onSyncStateApplied(item)
updateFolder(syncedFolder)
}

fun onDeleteAutoUploadFolderPreference(syncedFolder: SyncedFolderParcelable) {
Expand All @@ -113,24 +112,33 @@ class AutoUploadClickHandler(
adapter.getSectionById(syncedFolder.id)
}

private fun addFolder(syncedFolder: SyncedFolderParcelable): SyncedFolderDisplayItem {
val item = itemFactory.createAutoUploadFolder(syncedFolder)
persistence.saveOrUpdateAutoUploadFolder(item)
getAdapter().addItem(item)
private fun addFolder(syncedFolder: SyncedFolderParcelable) {
fragment.lifecycleScope.launch(Dispatchers.IO) {
val item = itemFactory.createAutoUploadFolder(syncedFolder)
persistence.saveOrUpdateAutoUploadFolder(item)

withContext(Dispatchers.Main) {
getAdapter().addItem(item)

return item
onSyncStateApplied(item)
}
}
}

private fun updateFolder(syncedFolder: SyncedFolderParcelable): SyncedFolderDisplayItem {
private fun updateFolder(syncedFolder: SyncedFolderParcelable) {
val adapter = getAdapter()
val section = findSection(adapter, syncedFolder)
val item = adapter.getItem(section) ?: return addFolder(syncedFolder)
val item = adapter.getItem(section)
if (item == null) {
addFolder(syncedFolder)
return
}

itemFactory.updateAutoUploadFolderItem(item, syncedFolder)
persistence.saveOrUpdateAutoUploadFolder(item)
adapter.notifyItemChanged(adapter.getSectionHeaderIndex(section))

return item
onSyncStateApplied(item)
}

private fun onSyncStateApplied(item: SyncedFolderDisplayItem) {
Expand Down
27 changes: 17 additions & 10 deletions app/src/main/res/layout/fragment_auto_upload.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,24 @@
android:layout_height="0dp"
android:layout_weight="1">

<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/synced_folders_recycler_view_layout_margin"
android:layout_marginLeft="@dimen/synced_folders_recycler_view_layout_margin"
android:layout_marginRight="@dimen/synced_folders_recycler_view_layout_margin"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:visibility="visible" />
android:layout_height="wrap_content">

<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/synced_folders_recycler_view_layout_margin"
android:layout_marginLeft="@dimen/synced_folders_recycler_view_layout_margin"
android:layout_marginRight="@dimen/synced_folders_recycler_view_layout_margin"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:visibility="visible" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<LinearLayout
android:id="@+id/loading_content"
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/res/layout/grid_sync_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
~ SPDX-License-Identifier: GPL-2.0-only AND (AGPL-3.0-or-later OR GPL-2.0-only)
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/grid_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -27,15 +28,19 @@
android:layout_height="match_parent"
android:background="#99000000"
android:contentDescription="@null"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"
android:visibility="gone"
tools:visibility="visible" />

<LinearLayout
android:id="@+id/counterLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_horizontal"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">

<TextView
android:id="@+id/next"
Expand All @@ -50,8 +55,7 @@
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/checkbox_off_background"
android:text="@string/placeholder_fileSize"
tools:text="@string/placeholder_remaining_file_count"
android:textColor="#ffffff"
android:textSize="@dimen/grid_sync_item_layout_counter_text_size"
android:textStyle="bold" />
Expand Down
Loading
Loading