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

hide-fab-button #272

Merged
merged 1 commit into from
Jul 17, 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 @@ -67,6 +67,7 @@ data class BrowseArgs(
class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {

private lateinit var args: BrowseArgs
private var fab: FloatingActionButton? = null

@OptIn(InternalMavericksApi::class)
override val viewModel: BrowseViewModel by fragmentViewModelWithArgs { args }
Expand Down Expand Up @@ -103,21 +104,26 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
override fun invalidate() = withState(viewModel) { state ->
super.invalidate()

withState(viewModel) { state ->
if (state.path == getString(R.string.nav_path_recents)) {
updateBanner(state.totalTransfersSize, state.uploadTransferList.size)
if (state.uploadTransferList.isEmpty()) {
viewModel.resetTransferData()
}
if (state.path == getString(R.string.nav_path_recents)) {
updateBanner(state.totalTransfersSize, state.uploadTransferList.size)
if (state.uploadTransferList.isEmpty()) {
viewModel.resetTransferData()
}
}

state.title?.let {
(requireActivity() as AppCompatActivity).supportActionBar?.title = it
}

if (viewModel.canAddItems(state)) {
(view as ViewGroup).addView(makeFab(requireContext()))
if (viewModel.canAddItems(state) && fab == null) {
fab = makeFab(requireContext())
(view as ViewGroup).addView(fab)
}

fab?.visibility = if (state.selectedEntries.isNotEmpty()) {
View.GONE
} else {
View.VISIBLE
}
}

Expand Down Expand Up @@ -177,6 +183,7 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
findNavController().navigateToContextualSearch(args.id ?: "", args.title ?: "", false)
true
}

else -> super.onOptionsItemSelected(item)
}
}
Expand Down Expand Up @@ -249,6 +256,11 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
}
}

override fun onDestroyView() {
super.onDestroyView()
fab = null
}

fun clearMultiSelection() {
disableLongPress()
viewModel.resetMultiSelection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,31 @@ class OfflineFragment : ListFragment<OfflineViewModel, OfflineViewState>() {
fab = null
}

override fun invalidate() {
override fun invalidate() = withState(viewModel) { state ->
super.invalidate()

withState(viewModel) { state ->
// Add fab only to root folder
if (state.parentId == null && fab == null) {
fab = makeFab(requireContext()).apply {
visibility = View.INVISIBLE // required for animation
}
(view as ViewGroup).addView(fab)
// Add fab only to root folder
if (state.parentId == null && fab == null) {
fab = makeFab(requireContext()).apply {
visibility = View.INVISIBLE // required for animation
}
(view as ViewGroup).addView(fab)
}

fab?.apply {
if (state.entries.count() > 0) {
show()
} else {
hide()
}

isEnabled = state.syncNowEnabled
fab?.apply {
if (state.entries.isNotEmpty()) {
show()
} else {
hide()
}

isEnabled = state.syncNowEnabled
}

fab?.visibility = if (state.selectedEntries.isNotEmpty()) {
View.GONE
} else {
View.VISIBLE
}
}

Expand Down