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

Folders screen: show hint only if folders are loaded #404

Merged
merged 1 commit into from
Nov 7, 2023
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 @@ -14,6 +14,17 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import by.kirich1409.viewbindingdelegate.viewBinding
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.DELETE_FOLDER_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.FAVORITE_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.FORGET_FAVORITE_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.FORGET_ROOT_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.ROOT_KEY
import dev.arkbuilders.arkfilepicker.folders.RootAndFav
import dev.arkbuilders.arkfilepicker.presentation.folderstree.DeviceNode
import dev.arkbuilders.arkfilepicker.presentation.folderstree.FavoriteNode
import dev.arkbuilders.arkfilepicker.presentation.folderstree.FolderNode
import dev.arkbuilders.arkfilepicker.presentation.folderstree.FolderTreeView
import dev.arkbuilders.arkfilepicker.presentation.folderstree.RootNode
import dev.arkbuilders.navigator.R
import dev.arkbuilders.navigator.data.utils.LogTags.FOLDERS_SCREEN
import dev.arkbuilders.navigator.databinding.FragmentFoldersBinding
Expand All @@ -31,17 +42,6 @@ import dev.arkbuilders.navigator.presentation.utils.toast
import dev.arkbuilders.navigator.presentation.utils.toastFailedPaths
import dev.arkbuilders.navigator.presentation.view.StackedToasts
import org.orbitmvi.orbit.viewmodel.observe
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.DELETE_FOLDER_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.FAVORITE_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.FORGET_FAVORITE_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.FORGET_ROOT_KEY
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo.Companion.ROOT_KEY
import dev.arkbuilders.arkfilepicker.folders.RootAndFav
import dev.arkbuilders.arkfilepicker.presentation.folderstree.DeviceNode
import dev.arkbuilders.arkfilepicker.presentation.folderstree.FavoriteNode
import dev.arkbuilders.arkfilepicker.presentation.folderstree.FolderNode
import dev.arkbuilders.arkfilepicker.presentation.folderstree.FolderTreeView
import dev.arkbuilders.arkfilepicker.presentation.folderstree.RootNode
import java.nio.file.Path
import javax.inject.Inject
import kotlin.io.path.Path
Expand Down Expand Up @@ -123,7 +123,7 @@ class FoldersFragment : Fragment(R.layout.fragment_folders) {
}

private fun render(state: FoldersState) = with(state) {
binding.noFolderHint.isVisible = folders.isEmpty()
binding.noFolderHint.isVisible = initialized && folders.isEmpty()
foldersTree?.set(devices, folders)
setProgressVisibility(
progressWithText.enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ import java.nio.file.Path
class ProgressWithText(val enabled: Boolean, val text: String = "")

data class FoldersState private constructor(
val initialized: Boolean,
val devices: List<Path>,
val folders: Map<Path, List<Path>>,
val progressWithText: ProgressWithText
) {
companion object {
fun initial() =
FoldersState(emptyList(), emptyMap(), ProgressWithText(false))
FoldersState(
initialized = false,
devices = emptyList(),
folders = emptyMap(),
progressWithText = ProgressWithText(false)
)
}
}

Expand Down Expand Up @@ -86,6 +92,7 @@ class FoldersViewModel(

reduce {
state.copy(
initialized = true,
devices = devices,
folders = folders.succeeded,
progressWithText = ProgressWithText(false)
Expand Down