Skip to content

Commit

Permalink
Disable fab instead of hiding it when there's no selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Akilesh-T committed Jun 1, 2020
1 parent b089c07 commit 3f02022
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.akilesh.qacc.ui.createmultiple

import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.O
import android.os.Bundle
Expand Down Expand Up @@ -105,11 +106,9 @@ class CreateAllFragment: Fragment() {
).withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()
binding.createMultipleBottomAppBar.menu.getItem(0).isVisible = selectionTracker.hasSelection()
if (selectionTracker.hasSelection().not()) binding.createMultipleFab.hide() else binding.createMultipleFab.show()

createAllAdapter.tracker = selectionTracker

setupBottomAppBarIcons(selectionTracker.hasSelection())
binding.createMultipleBottomAppBar.setOnMenuItemClickListener {
val temp = arrayListOf<Long>()
createAllAdapter.colours.forEachIndexed { index, _ ->
Expand All @@ -136,11 +135,7 @@ class CreateAllFragment: Fragment() {
object : SelectionTracker.SelectionObserver<Long>() {
override fun onSelectionChanged() {
super.onSelectionChanged()
binding.createMultipleBottomAppBar.menu.apply {
getItem(0).isVisible = selectionTracker.hasSelection()
getItem(1).isVisible = selectionTracker.hasSelection()
}
if (selectionTracker.hasSelection().not()) binding.createMultipleFab.hide() else binding.createMultipleFab.show()
setupBottomAppBarIcons(selectionTracker.hasSelection())
val selection = selectionTracker.selection
selected = selection.mapNotNull { createAllAdapter.colours[it.toInt()] }.toSet()
}
Expand Down Expand Up @@ -196,3 +191,15 @@ class CreateAllFragment: Fragment() {
}
}
}

private fun setupBottomAppBarIcons(flag: Boolean) {
binding.createMultipleBottomAppBar.menu.apply {
getItem(0).isVisible = flag
getItem(1).isVisible = flag
}
binding.createMultipleFab.apply {
binding.createMultipleFab.isEnabled = flag
imageTintList = if (binding.createMultipleFab.isEnabled) null
else ColorStateList.valueOf(Color.GRAY)
}
}

0 comments on commit 3f02022

Please sign in to comment.