Skip to content

Commit

Permalink
fix snackbar dismiss with FAB
Browse files Browse the repository at this point in the history
  • Loading branch information
RobozinhoD committed Feb 6, 2024
1 parent 2412d48 commit c470721
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import anki.collection.OpChanges
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.progressindicator.CircularProgressIndicator
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anim.ActivityTransitionAnimation.Direction.*
import com.ichi2.anki.CollectionHelper.CollectionIntegrityStorageCheck
Expand Down Expand Up @@ -198,7 +199,6 @@ open class DeckPicker :
lateinit var recyclerView: RecyclerView
private lateinit var recyclerViewLayoutManager: LinearLayoutManager
private lateinit var deckListAdapter: DeckAdapter
private val snackbarShowHideCallback = Snackbar.Callback()
lateinit var exportingDelegate: ActivityExportingDelegate
private lateinit var noDecksPlaceholder: LinearLayout
lateinit var pullToSyncWrapper: SwipeRefreshLayout
Expand All @@ -213,8 +213,19 @@ open class DeckPicker :
// flag asking user to do a full sync which is used in upgrade path
private var recommendFullSync = false

private var activeSnackBar: Snackbar? = null
private val activeSnackbarCallback = object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
override fun onShown(transientBottomBar: Snackbar?) {
activeSnackBar = transientBottomBar
}

override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
activeSnackBar = null
}
}
override val baseSnackbarBuilder: SnackbarBuilder = {
anchorView = findViewById<FloatingActionButton>(R.id.fab_main)
addCallback(activeSnackbarCallback)
}

// flag keeping track of when the app has been paused
Expand Down Expand Up @@ -481,6 +492,7 @@ open class DeckPicker :
}
// Setup the FloatingActionButtons, should work everywhere with min API >= 15
floatingActionMenu = DeckPickerFloatingActionMenu(this, view, this)
floatingActionMenu.onShowCallback = { activeSnackBar?.dismiss() }

reviewSummaryTextView = findViewById(R.id.today_stats_text_view)

Expand Down Expand Up @@ -1841,7 +1853,6 @@ open class DeckPicker :
@NeedsTest("14608: Ensure that the deck options refer to the selected deck")
private suspend fun handleDeckSelection(did: DeckId, selectionType: DeckSelectionType) {
fun showEmptyDeckSnackbar() = showSnackbar(R.string.empty_deck) {
addCallback(snackbarShowHideCallback)
setAction(R.string.menu_add) { addNote() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ class DeckPickerFloatingActionMenu(
private val addWhiteIcon: Int = R.drawable.ic_add_white

var isFABOpen = false
var onShowCallback: (() -> Unit)? = null

@Suppress("unused")
val isFragmented: Boolean
get() = studyOptionsFrame != null

private fun showFloatingActionMenu() {
onShowCallback?.invoke()
linearLayout.alpha = 0.5f
studyOptionsFrame?.let { it.alpha = 0.5f }
isFABOpen = true
Expand Down

0 comments on commit c470721

Please sign in to comment.