Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy offline UI to make it a bit easier to understand #1244

Merged
merged 1 commit into from
Mar 20, 2024
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
4 changes: 2 additions & 2 deletions app/src/main/java/com/infomaniak/drive/data/models/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ open class File(

fun isPendingOffline(context: Context): Boolean {
val get = WorkManager.getInstance(context).getWorkInfosByTag(getWorkerTag()).get()
return get.firstOrNull {
return get.any {
it.state == WorkInfo.State.ENQUEUED
|| it.state == WorkInfo.State.RUNNING
|| it.state == WorkInfo.State.BLOCKED
} != null
}
}

fun getMimeType(): String = name.guessMimeType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,31 @@ class FileInfoActionsView @JvmOverloads constructor(
}

fun refreshBottomSheetUi(file: File, isOfflineProgress: Boolean = false): Unit = with(binding) {
val isPendingOffline = file.isPendingOffline(context)
val isOfflineFile = file.isOfflineFile(context)
enableAvailableOffline(!isPendingOffline || file.currentProgress == 100)
if (isOfflineProgress) fileView.progressLayout.setupFileProgress(file) else fileView.setFileItem(file)
if (availableOfflineSwitch.isEnabled && availableOffline.isVisible) {
availableOfflineSwitch.isChecked = isOfflineFile
}
addFavorites.isEnabled = true
addFavoritesIcon.isEnabled = file.isFavorite
addFavoritesText.setText(if (file.isFavorite) R.string.buttonRemoveFavorites else R.string.buttonAddFavorites)
sharePublicLinkText.setText(if (file.sharelink == null) R.string.buttonCreatePublicLink else R.string.buttonSharePublicLink)

setOfflineItemUi(file, isOfflineProgress)
}

private fun setOfflineItemUi(file: File, isOfflineProgress: Boolean): Unit = with(binding) {
// Update file item progress
if (isOfflineProgress) fileView.progressLayout.setupFileProgress(file) else fileView.setFileItem(file)

val isPendingOffline = file.isPendingOffline(context)
val isItemInteractable = !isPendingOffline || file.currentProgress == 100
tevincent marked this conversation as resolved.
Show resolved Hide resolved
enableAvailableOffline(isItemInteractable)

val isOfflineFile = file.isOfflineFile(context)
if (isItemInteractable) availableOfflineSwitch.isChecked = isOfflineFile

when {
// We can have a currentProgress in [0,99] yet the file is not pending?
KevinBoulongne marked this conversation as resolved.
Show resolved Hide resolved
isPendingOffline && file.currentProgress in 0..99 -> {
availableOfflineComplete.isGone = true
availableOfflineIcon.isGone = true

availableOfflineProgress.apply {
isGone = true // We need to hide the view before updating its `isIndeterminate`
if (isOfflineProgress) {
Expand All @@ -414,9 +423,10 @@ class FileInfoActionsView @JvmOverloads constructor(
}
}
!isOfflineProgress -> {
availableOfflineProgress.isGone = true
availableOfflineComplete.isVisible = isOfflineFile
availableOfflineIcon.isGone = isOfflineFile

availableOfflineProgress.isGone = true
}
}
}
Expand Down
Loading